Codeforces Round #691 (Div. 2)A-C题

Div2第一次AC两道题

A题
直接比较一张卡片上的两个数,blue大blue ,red大red ,最后比较(当时就凭感觉应该是这样qwq)

#include<iostream>#include<stdio.h>#include<string>#include<algorithm>using namespace std;char r[1005];char b[1005];int main(){    int t;    cin>>t;    int n;    int blue;    int red;    while(t--){        cin>>n;        red = blue = 0;        for (int i = 1;i<=n;i  ){            cin >> r[i];        }        for (int i = 1; i <= n;i  ){            cin >> b[i];        }        for (int i = 1; i <= n;i  ){            if((int)(r[i]-'0')>(int)(b[i]-'0'))                red  ;            if((int)(r[i]-'0')<(int)(b[i]-'0'))                blue  ;        }        if (red > blue)            cout<<"RED"<<endl;        if(red<blue)            cout << "BLUE" << endl;        if(red==blue)            cout << "EQUAL" << endl;    }    return 0;}

B题:

一开始用dfs搜,明显超时,果断用dfs找规律

#include<iostream>using namespace std;//dfs打表wow//前面是dfs搜的代码/*void dfs(int x,int y){    if(num==n){        if(!vis[x][y]){            vis[x][y] = 1;            sum  ;        }        return;    }    for (int i = 1;i<=2;i  ){        if (flag)        {            num  ;            flag = 0;            dfs(x   1, y);            num--;            num  ;            flag = 0;            dfs(x - 1, y);            num--;            return;        }        else        {            num  ;            flag = 1;            dfs(x, y   1);            num--;            num  ;            flag = 1;            dfs(x, y - 1);            num--;            return;        }    }}int main(){    cin>>n;    flag = 0;    dfs(500,500);    long long k=sum;    cout << sum << endl;    flag = 1;    dfs(500, 500);    cout<<sum-k<<endl;    cout << sum;    return 0;}*/int main(){    int n;    cin >> n;    if(n%2==0){        cout << (n / 2   1) * (n / 2   1);        return 0;    }else{        n  ;        cout << ((n / 2   1) * (n / 2   1) - (n / 2   1))*2;        return 0;    }}

C题:(补题)

比赛时没做出来(其实是不会)

(数论一直搞不懂)

gcd(a,b)=gcd(a-b,b)

#include<iostream>#include<stdio.h>#include<algorithm>using namespace std;long long gcd(long long x,long long y){    if(y==0)        return x;    else        return gcd(y, x % y);}long long a[200006];int main(){    int n;    int m;    long long t;    long long gcd_x=1;    cin >> n >> m;    for(int i=1;i<=n;i  )        cin>>a[i];    sort(a   1, a   n   1);    if(n>=2){        gcd_x = a[2] - a[1];        for (int i = 3; i <= n;i  )            gcd_x=gcd(gcd_x,a[i]-a[i-1]);        for (int i = 1;i<=m;i  ){            cin>>t;            cout << gcd(gcd_x, a[1]   t) << ' ';        }    }else{        for (int i = 1; i <= m;i  ){            cin >> t;            cout << t   a[1] << ' ';        }    }    return 0;}

来源:https://www.icode9.com/content-4-793701.html

(0)

相关推荐