天天看点

Codeforces Round #736 (Div. 2) - 代码A - Gregor and CryptographyB - Gregor and the Pawn GameC - Web of Lies

Codeforces Round #736 Div. 2

  • A - Gregor and Cryptography
  • B - Gregor and the Pawn Game
  • C - Web of Lies

A - Gregor and Cryptography

#include <bits/stdc++.h>
using namespace std;
 
const int N = 5e5+10;
 
int main(){
    int t;
    cin>>t;
    while(t--){
        int n ; cin>>n;
        n--;
        if(n == 4) cout<<"2 4"<<endl;
        else {
        for(int i = 2; i < n/i; i++)
            if(n % i == 0) {
                cout<<i<<' '<<n/i<<endl;
                break;
            }
        }
    }
    return 0;
}
           

B - Gregor and the Pawn Game

#include <bits/stdc++.h>
using namespace std;
 
const int N = 2e5+10;
int num[N]={0};
 
string x, y;
 
int main(){
 
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    int t;
    cin>>t;
    while(t--){
        memset(num, 0 ,sizeof num);
        int n, k = 0;
        cin>> n >> x >> y;
        
        for(int i = 0; i < n; i++){
           
            if(!(y[i] - '0')) continue;
            if(!num[i] && ! (x[i]-'0'))  num[i] = 1, k++;
            else if(i && x[i-1] - '0' && !num[i-1]) 
                    num[i-1] = 1, k++;
            else if(i < n -1 && x[i+1]-'0') num[i+1] = 1, k++;
            // cout<<k<<endl;
        }
        cout<< k <<endl;
 
    }
 
    return 0;
}
           

C - Web of Lies

#include <bits/stdc++.h>
using namespace std;
 
const int N = 2e5+10;
int num[N]={0};
 
set<int, greater<int> >st[N];
 
int main(){
 
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    int n, m, q, x, y;
    cin>>n>>m;
    int k = n;
    while(m--){
        cin>>x>>y;
        if(x < y) swap(x,y); 
        if(st[y].empty()) k--;
        st[y].insert(x);
    }
 
    cin>>q;
    while(q--){
        int a,b,c;
        cin>> c ;
        if(c == 2){
            cin>>a>>b;
            if(a < b) swap(a,b);
         
            if(st[b].size() == 1) k++, st[b].clear();    
            else st[b].erase(a); 
        }
        else if(c == 1){
            cin >> a >> b;
            if (a < b)  swap(a, b);
            if(st[b].empty()) k--;
            st[b].insert(a);
        }
        else  cout<<k<<endl;       
    }
    return 0;
}
           

继续阅读