C/C++教程

Codeforces Round #736 (Div. 2)

本文主要是介绍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;
}
这篇关于Codeforces Round #736 (Div. 2)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!