Codeforces Round 1027 (Div. 3)

注:这次只贴代码了,  前面文章还有好几个坑没填呢(哈哈哈)

A. Square Year

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t; cin>>t;
    while(t--){
        string s; cin>>s;
        int a=stoi(s);
        double b=sqrt(a);
        if(b-int(b)>0){
            cout<<-1<<endl;
        }else{cout<<0<<" "<<b<<endl;}
    }
    return 0;
}

B. Not Quite a Palindromic String

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t; cin>>t;
    while(t--){
        int n,k; 
        cin>>n>>k;
        string s; cin>>s;
        vector<int> fq(2,0);
        for(char x: s){
            fq[x-'0']++;
        }
        int a=fq[0]-(n/2-k),b=fq[1]-(n/2-k);
        if(a>=0&&a%2==0&&b>=0&&b%2==0){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

 C. Need More Arrays

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t; cin>>t;
    while(t--){
        int n; cin>>n;
        vector<int> a(n);
        for(int i=0;i<n;i++) cin>>a[i];
        int cnt=1,pre=a[0];
        for(int i=1;i<n;i++){
            if(a[i]>pre+1){
                cnt++;
                pre=a[i];
            }
        }
        cout<<cnt<<endl;
        // cout<<"========"<<endl;
    }
    return 0;
}

D. Come a Little Closer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int t;
    cin >> t;
    while (t--){
        int n;
        cin >> n;
        vector<vector<int>> a(n, vector<int>(2, 0));
        for (int i = 0; i < n; i++) {
            cin >> a[i][0] >> a[i][1];
        }
        if (n == 1) {
            cout << 1 << endl;
            continue;
        }
        multiset<int> xs, ys;
        for (auto &t : a) {
            xs.insert(t[0]);
            ys.insert(t[1]);
        }
        ll res = LONG_LONG_MAX;
        ll width = *xs.rbegin() - *xs.begin() + 1;
        ll height = *ys.rbegin() - *ys.begin() + 1;
        res = min(res, width * height);
        for (auto &t : a) {
            xs.erase(xs.find(t[0]));
            ys.erase(ys.find(t[1]));
            width = *xs.rbegin() - *xs.begin() + 1;
            height = *ys.rbegin() - *ys.begin() + 1;
            ll area = width * height;
            if (area == n - 1) {
                area += min(width, height);
            }
            res = min(res, area);
            xs.insert(t[0]);
            ys.insert(t[1]);
        }
        cout << res << endl;
    }
    return 0;
}

E. Kirei Attacks the Estate

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
    int t;
    cin >> t;
    while (t--) {
        int n; cin>>n;
        vector<ll> a(n);
        for(int i=0;i<n;i++) cin>>a[i];
        vector<vector<int>> g(n);
        for(int i=0;i<n-1;i++){
            int x,y; cin>>x>>y; x--; y--;
            g[x].push_back(y);
            g[y].push_back(x);
        }
        vector<vector<ll>> f(n,vector<ll>(2,0));
        auto dfs=[&](this auto&& self,int x,int fa)-> void{
            f[x][0]=a[x];
            f[x][1]=a[x];
            if(fa!=-1){
                f[x][0] = min(f[x][0], a[x]-f[fa][1]);
                f[x][1] = max(f[x][1], a[x]-f[fa][0]);
            }
            for(int y: g[x]){
                if(y!=fa) dfs(y,x);
            }
        };
        dfs(0,-1);
        for(int i=0;i<n;i++){
            cout<<f[i][1]<<" ";
        }
        cout<<endl;
    }
    return 0;
}

 F. Small Operations

感谢大家的点赞和关注,你们的支持是我创作的动力!

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值