Codeforces Round #685 (Div. 2)

Codeforces Round #685 (Div. 2)

A. Subtract or Divide

3的时候是俩步
奇数先一步到偶数,偶数直接到2;

#include <bits/stdc++.h>

#define int long long
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const int N = 2e7 + 5;

void solve() {
    int n;
    cin>>n;
    if(n<=3) cout<<n-1<<"\n";
    else cout<<(n%2?3:2)<<"\n";
}

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

B. Non-Substring Subsequence

只看l,r俩位置的字符在l前或者r后有没有重复即可

#include <bits/stdc++.h>

#define int long long
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const int N = 2e7 + 5;

void solve() {
    int n,q;
    string s;
    cin>>n>>q>>s;
    while (q--){
        int l,r;
        cin>>l>>r;
        int flag=0;
        for (int i = 0; i < l-1; ++i)
            if(s[i]==s[l-1]) flag=1;
        for(int i=r;i<n;i++)
            if(s[i]==s[r-1]) flag=1;
        cout<<(flag?"YES":"NO")<<"\n";
    }
}

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

C. String Equality

判断:
1.b串中每个字母的个数减完a串个数后是否是k的倍数(因为剩余的就是a变过来的,必须满足整除k)
2.如果a串某字母个数不够变,便不满足;

#include <bits/stdc++.h>

#define int long long
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const int N = 2e7 + 5;

int aa[27],bb[27];

void solve() {
    memset(aa,0,sizeof(aa));
    memset(bb,0,sizeof(bb));
    int n,k;
    string a,b;
    cin>>n>>k>>a>>b;
    int f=0,bian=0;
    for(int i=0;i<n;i++) aa[a[i]-'a']++,bb[b[i]-'a']++;
    for(int i=0;i<26;i++){
        if((bb[i]-aa[i])%k!=0){f=1;break;}
        bian+=(aa[i]-bb[i])/k;
        if(bian<0){f=1;break;}
    }
    cout<<(f?"No":"Yes")<<"\n";
}

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

D. Circle Game

直接计算最多能走的步数;

#include <bits/stdc++.h>

#define int long long
using namespace std;

void solve() {
    double d,k;
    cin>>d>>k;
    int x=d/(sqrt(2)*k);
    x=x*k;
    if((x+k)*(x+k)+x*x<=d*d)
        cout<<"Ashish"<<endl;
    else
        cout<<"Utkarsh"<<endl;
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--)
        solve();
    return 0;
}

E. Bitwise Queries
判断是否存在与a1 xor结果相同的,相同即 ai=aj;
1.存在。因为aj=ai => a1^ aj^ ai=a1^ ai^ai=a1; 得到a1,同样的方法得到整个数组。
2.若不存在aj==ai,即数组是个排列必有a1ai=1,a1aj=2;即ai和a1只有最后一位不一样,aj和a1只有最后第二位不一样;所以a1&ai+(a1&aj)%2=a1; 得到a1,同样的方法得到整个数组。

#include <bits/stdc++.h>

#define int long long
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const int N = (1<<16)+1;

int ans[N],sum[N];

int query(int key,int x,int y){
    int tmp;
    if(key==1) cout<<"AND "<<x<<" "<<y<<"\n";
    if(key==2) cout<<"OR "<<x<<" "<<y<<"\n";
    if(key==3) cout<<"XOR "<<x<<" "<<y<<"\n";
    cout.flush();
    cin>>tmp;
    return tmp;
}

void solve() {
    int n,id=0;
    cin>>n;
    sum[0]=1;
    for(int i=2;i<=n;i++){
        int a=query(3,1,i);
        ans[i]=a;
        if(!sum[a]) sum[a]=i;
        else id=i;
    }
    if(id){
        int res = query(1, sum[ans[id]], id);
        ans[1]=ans[id]^res;
        for(int i=2;i<=n;i++) ans[i]^=ans[1];
    } else{
        int k1=sum[1],k2=sum[2];
        int a1=query(1,k1,1);
        int a2=query(1,k2,1);
        int res=a1+a2%2;
        for(int i=1;i<=n;i++) ans[i]^=res;
    }
    cout<<"! ";
    for(int i=1;i<=n;i++) cout<<ans[i]<<" ";
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值