A - ABC333

思路:模拟

B - Shiritori

思路:模拟

C - Skip

思路:把x插入到数组中,排序后,求所有相邻a[i+1]-a[i]的公共gcd

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e6+6;
const ll MOD=1e9+7;
const int Seed=1e7+7;
template <class T>
bool sf(T &ret){ //Faster Input
    char c; int sgn; T bit=0.1;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    if(c==' '||c=='\n'){ ret*=sgn; return 1; }
    while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
    ret*=sgn;
    return 1;
}
ll a[N];
int main(){
    int n,x;
    sf(n);sf(x);
    for(int i=1;i<=n;i++)   sf(a[i]);
    n++;a[n]=x;
    sort(a+1,a+1+n);
    ll ans=0;
    for(int i=2;i<=n;i++){
        ans=__gcd(ans,a[i]-a[i-1]);
    }
    cout << ans << endl;
//    int index;
//    for(int i=1;i<=n;i++){
//        if(a[i]==x){
//            index=i;break;
//        }
//    }


    return 0;
}

D - Make Them Even

题意:一个n*m的矩阵,每次从一个未选择过并且大于0的a[i][j]转移1个或者不转移到相邻的四个方向。要求构造出最佳方案,使得最后a[i][j]是偶数个数最多

思路:从上往下贪心搞,最后对i=n横着搞一次

#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N=2e6+6;
const ll MOD=1e9+7;
const int Seed=1e7+7;
template <class T>
bool sf(T &ret){ //Faster Input
    char c; int sgn; T bit=0.1;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    if(c==' '||c=='\n'){ ret*=sgn; return 1; }
    while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
    ret*=sgn;
    return 1;
}
typedef pair<pair<int,int>,pair<int,int> >ppp;
vector<ppp> ans;
int a[600][600];
int main(){
    int n,m;
    sf(n);sf(m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)   sf(a[i][j]);
    for(int j=1;j<=m;j++){
        for(int i=1;i<=n-1;i++){
            if(a[i][j]==0)  continue;
            if(a[i][j]%2==0)    continue;
            ans.push_back(make_pair(make_pair(i,j),make_pair(i+1,j)));
            a[i][j]--;
            a[i+1][j]++;

        }
    }
    for(int i=n;i<=n;i++){
        for(int j=1;j<=m-1;j++){
            if(a[i][j]==0)  continue;
            if(a[i][j]%2==0)    continue;
            ans.push_back(make_pair(make_pair(i,j),make_pair(i,j+1)));
            a[i][j+1]++;
            a[i][j]--;
        }
    }
    cout <<ans.size() << endl;
    for(auto t : ans){
       pair<int,int> x,y;
       x=t.first,y=t.second;
       cout <<x.F<<" "<<x.S<<" "<<y.F<<" "<<y.S<<endl;
    }

    return 0;
}