Codeforces Round #736 (Div. 2)

A. Gregor and Cryptography

构造...

#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std;
using ll = long long ;
void solve()
{
    ll p;
    cin>>p;
    for(ll i=2;i*i<=p;i++){
        if(p%i==0){
            cout<<i<<" "<<p<<"\n";
            return ;
        }
    }
    cout<<2<<" "<<p-1<<"\n";
}
int main()
{
    ios::sync_with_stdio(false);
    int t=1;
    cin>>t;
    while(t--)
        solve();
    return 0;
}

B. Gregor and the Pawn Game

贪心...

#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std;
using ll = long long ;
bool vis[200010];
void solve()
{
    int n;
    cin>>n;
    for(int i=0;i<=n;i++) vis[i]=0;
    string a,b;
    cin>>a>>b;
    int ans=0;
    for(int i=0;i<n;i++){
        if(b[i]=='0')continue;
        if(i-1>=0&&!vis[i-1]&&a[i-1]=='1'){
            vis[i-1]=true,ans++;
        }else if(a[i]=='0'&&!vis[i]){
            vis[i]=true,ans++;
        }else if(i+1<n&&!vis[i+1]&&a[i+1]=='1'){
            vis[i+1]=true,ans++;
        }
    }
    cout<<ans<<"\n";
    return ;
}
int main()
{
    ios::sync_with_stdio(false);
    int t=1;
    cin>>t;
    while(t--)
        solve();
    return 0;
}

C. Web of Lies

思路: 只记录入度即可

#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std;
using ll = long long ;
int jing[200010];
int in[200010];
void solve()
{
    int n,m;
    cin>>n>>m;
    for(int i=0,u,v;i<m;i++){
        cin>>u>>v;
        if(u>v)jing[v]++;
        else if(u<v)jing[u]++;
    }
    long long int ans=0;
    for(int i=1;i<=n;i++) if(jing[i]==0)ans++;
    int q;
    cin>>q;
    while(q--){
        int u,v;
        int op;
        cin>>op;
        if(op==1){
            cin>>u>>v;
            if(u>v){
                jing[v]++;
                if(jing[v]==1)ans--;
            }else{
                jing[u]++;
                if(jing[u]==1)ans--;
            }
        }else if(op==2){
            cin>>u>>v;
            if(u>v){
                jing[v]--;
                if(jing[v]==0)ans++;
            }else{
                jing[u]--;
                if(jing[u]==0)ans++;
            }
        }
        else{
            cout<<ans<<"\n";

        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    int t=1;
   // cin>>t;
    while(t--)
        solve();
    return 0;
}
上一篇:IDEA中java不能创建类class


下一篇:求N的倍数M都是各位0和1