Codeforces Round #668 (Div. 2)

Codeforces Round #668 (Div. 2)

A. Permutation Forgery

#include <bits/stdc++.h>
#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
const int N=205;
using namespace std;



void solve(){
    int p[105];
    int n;
    cin>>n;
    for (int i = 1; i <=n; ++i)  cin>>p[i];
    for (int j = n; j >=1 ; --j) cout<<p[j]<<" ";
    cout<<endl;
}

signed main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) solve();
    return 0;
}

B. Array Cancellation

#include <bits/stdc++.h>
#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
const int N=205;
using namespace std;

int p[maxn];

void solve(){
    int n,flag=0,z=0,f=0;
    cin>>n;
    for (int i = 1; i <=n; ++i) {
        cin>>p[i];
        if (p[i]>0)flag=1;
        if (!flag)f-=p[i];
        if (flag){
            z+=p[i];
            if (z<0)f-=z,z=0;
        }
    }int t=ceil((f+z)*1.0/2);
    cout<<t<<endl;

}

signed main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) solve();
    return 0;
}

C. Balanced Bitstring

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;


void solve(){
    int n,k,flag=1;
    string s;
    cin>>n>>k>>s;char t[k];
    for (int j = 0; j < k; ++j) t[j]=s[j];
    for (int i = 0; i < s.size(); ++i) {
        if (s[i]!='?'){
            if (s[i]!=t[i%k]){
                if (t[i%k]!='?') {flag=0;break;}
                else t[i%k]=s[i];
            }
        }
    }
    int a=0,b=0,c=0;
    for(int i=0;i<k;i++){
        if (t[i]=='1')a++;
        if (t[i]=='0')b++;
        if (t[i]=='?')c++;
    }
    if (abs(a-b)>c)flag=0;
    cout<<(flag?"YES":"NO")<<endl;
}

signed main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) solve();
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
int cnt[300003];
int main(){
    int T;
    cin>>T;
    while(T--){
        int n,k,ret0=0,ret1=0;
        string s;
        cin>>n>>k>>s;
        for(int i=0;i<n;i++)cnt[i]=0;
        for(int i=0;i<n;i++)
            if(s[i]!='?') cnt[i%k]|=(1<<(s[i]-'0'));
        bool ok=1;
        for(int i=0;i<k;i++){
            if(cnt[i]==1)ret0++;
            if(cnt[i]==2)ret1++;
            if(cnt[i]==3)ok=0;
        }
        if(ret0>k/2||ret1>k/2)ok=0;
        cout<<(ok?"YES":"NO")<<endl;
    }
}

D. Tree Tag

#include <bits/stdc++.h>
//#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
//const int N=205;
using namespace std;

vector<int > to[maxn];
int r=0,depth[maxn];
int n,a,b,da,db;

int dfs(int x,int f){
    int len=0;
    for (int y:to[x]) {
        if (y!=f){
            depth[y]=depth[x]+1;
            int ans=1+dfs(y,x);
            r=max(ans+len,r);//和谁取max看错了一直填的ans,列开
            len=max(len,ans);
        }
    }
    return len;
}

void solve(){
    cin>>n>>a>>b>>da>>db;
    for (int i = 1; i <=n; ++i) to[i].clear();
    for (int i = 0; i < n-1; ++i) {
        int u,v;
        cin>>u>>v;
        to[u].push_back(v);
        to[v].push_back(u);
    }
    r=0;//直径
    depth[a]=0;
    dfs(a,-1);
    if (2*da>=min(r,db)||depth[b]<=da)cout<<"Alice"<<endl;
    else cout<<"Bob"<<endl;
}

signed main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) {
        //init();
        solve();
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值