Codeforces Round #573

http://codeforces.com/contest/1191

A

给一个数,可以加0,1或2然后取模,再映射到字母,字母有排名,求最大排名。

总共只有4种情况,讨论即可

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define ll long long
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define fd(i,l,r) for(int i = r;i >= l;i--)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int maxn = 400050;
const ll inf = 987654321234500LL;
const ll mod = 1e9+7;
ll n;
ll read() {
    ll x=0,f=1;
    char ch=getchar();
    while(!(ch>='0'&&ch<='9')) {
        if(ch=='-')f=-1;
        ch=getchar();
    };
    while(ch>='0'&&ch<='9') {
        x=x*10+(ch-'0');
        ch=getchar();
    };
    return x*f;
}
int tran[4]={1,4,3,2};
int main() {
    n=read();
    int mx,dd;
    n %= 4;
    if(n==0){
        dd=1;
        mx = 0;
    }
    if(n==1){
        dd = 0;
        mx = 0;
    }
    if(n==2){
        dd = 1;
        mx = 1;
    }
    if(n==3){
        dd = 2;
        mx = 0;
    }
    cout<<dd<<" "<<(char)('A'+mx);
    return 0;
}
View Code

B

一副牌,看看有没有三张一样的牌或者三张连号的牌

遍历

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define ll long long
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define fd(i,l,r) for(int i = r;i >= l;i--)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int maxn = 400050;
const ll inf = 987654321234500LL;
const ll mod = 1e9+7;
ll n;
ll read() {
    ll x=0,f=1;
    char ch=getchar();
    while(!(ch>='0'&&ch<='9')) {
        if(ch=='-')f=-1;
        ch=getchar();
    };
    while(ch>='0'&&ch<='9') {
        x=x*10+(ch-'0');
        ch=getchar();
    };
    return x*f;
}
char a[5][10];
int p[100][100];
int main() {
    scanf("%s %s %s",a[1],a[2],a[3]);
    fo(i,1,3){
        int hs = 0;
        if(a[i][1]=='m')hs=1;
        if(a[i][1]=='p')hs=2;
        if(a[i][1]=='s')hs=3;
        p[hs][a[i][0]-'0']++;
    }
    int ans = 3;
    fo(i,1,3){
        fo(j,0,9){
            ans = min(ans,3-p[i][j]);
        }
        fo(j,1,7){
            ans = min(ans,3-((p[i][j]>=1)+(p[i][j+1]>=1)+(p[i][j+2]>=1)));
        }
    }
    cout<<ans;
    return 0;
}
View Code

C

一个纸带,分成若干段,把一些位置标记,每轮把第一个有标记的段的所有标记位置拿走,后面的位置向前顺延,问多少次取完

这个标记段是不断后移的,算一下下次在哪个段就行了

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define ll long long
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define fd(i,l,r) for(int i = r;i >= l;i--)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int maxn = 100050;
const ll inf = 987654321234500LL;
const ll mod = 1e9+7;
ll read() {
    ll x=0,f=1;
    char ch=getchar();
    while(!(ch>='0'&&ch<='9')) {
        if(ch=='-')f=-1;
        ch=getchar();
    };
    while(ch>='0'&&ch<='9') {
        x=x*10+(ch-'0');
        ch=getchar();
    };
    return x*f;
}
ll n,m,k;
ll p[maxn];
ll lp,rp;
int main() {
    n=read();
    m=read();
    k=read();
    fo(i,1,m){
        p[i]=read();
    }
    lp = 1;
    rp = k;
    ll hasp=0,nowhp;
    ll ans = 0;
    ll pos = 1;
    while(pos <= m){
        nowhp=0;
        while(pos <= m && p[pos]-hasp<=rp){
            nowhp++;
            pos++;
        }
        if(nowhp)ans++;
        hasp += nowhp;
        if(rp < p[pos]-hasp){
            ll tmp = (p[pos]-hasp-rp);
            tmp = (tmp-1)/k + 1;
            tmp *= k;
            lp += tmp;
            rp += tmp;
        }
    }
    cout<<ans;
    return 0;
}
View Code

D

有n堆石子,两人轮流从一堆里取一块,什么时候取不了了,或者有两堆高度一样的(包括0),那这个人就输了。问谁赢。

假设先手面临的不是必败态,最后的必败态是0、1、2、3...n这种情况,看谁先到达。

先手必败有哪些?都是0的,和包含相同的,如果包含一个相同的对,其他再没有相同的对,并且这一对不是0,且没有恰好比它们高度小1的堆,那就不是必败,否则是必败。

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define ll long long
#define fo(i,l,r) for(int i = l;i <= r;i++)
#define fd(i,l,r) for(int i = r;i >= l;i--)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int maxn = 100050;
const ll inf = 987654321234500LL;
const ll mod = 1e9+7;
ll read() {
    ll x=0,f=1;
    char ch=getchar();
    while(!(ch>='0'&&ch<='9')) {
        if(ch=='-')f=-1;
        ch=getchar();
    };
    while(ch>='0'&&ch<='9') {
        x=x*10+(ch-'0');
        ch=getchar();
    };
    return x*f;
}
int n;
ll a[maxn];
int main() {
    n=read();
    fo(i,1,n){
        a[i]=read();
    }
    sort(a+1,a+1+n);
    ll cnt = 0;
    fo(i,1,n-1){
        if(a[i]==a[i+1]){
            cnt++;
            if(a[i]==0)cnt++;
            if(i > 1 && a[i]==a[i-1]+1)cnt++;
        }
    }
    if(cnt > 1){
        cout<<"cslnb";
        return 0;
    }
    cnt = 0;
    fo(i,1,n){
        cnt += (ll)a[i]-(ll)(i-1);
    }
    if(cnt&1)cout<<"sjfnb";
    else cout<<"cslnb";
    return 0;
}
View Code

 

posted @ 2019-07-15 23:46  ACforever  阅读(156)  评论(0编辑  收藏  举报