【刷题】AtCoder Regular Contest 002

A.うるう年

题意:判断闰年

做法:。。

#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
#define REP(a,b,c) for(register int a=(b),a##end=(c);a<=a##end;++a)
#define DEP(a,b,c) for(register int a=(b),a##end=(c);a>=a##end;--a)
template<typename T> inline void read(T &x)
{
    T data=0,w=1;
    char ch=0;
    while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
    if(ch=='-')w=-1,ch=getchar();
    while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
    x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
    if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
int main()
{
    int n;read(n);
    if(n%4!=0)puts("NO");
    else
    {
        if(n%100==0&&n%400!=0)puts("NO");
        else puts("YES");
    }
    return 0;
}

B.リモコン

题意:找到在给定日期之后的一个日期,使得年/月/日是整数(/是除法的意思)

做法:枚举

#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
#define REP(a,b,c) for(register int a=(b),a##end=(c);a<=a##end;++a)
#define DEP(a,b,c) for(register int a=(b),a##end=(c);a>=a##end;--a)
int a,b,c,mh[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
template<typename T> inline void read(T &x)
{
    T data=0,w=1;
    char ch=0;
    while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
    if(ch=='-')w=-1,ch=getchar();
    while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
    x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
    if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline bool check(int x)
{
    if(x%4!=0)return false;
    else
    {
        if(x%100==0&&x%400!=0)return false;
        return true;
    }
}
inline void print(int y,int m,int d)
{
    printf("%d/",y);
    if(m<10)putchar('0');
    printf("%d/",m);
    if(d<10)putchar('0');
    printf("%d\n",d);
}
int main()
{
    read(a);read(b);read(c);
    REP(i,a,3000)REP(j,i==a?b:1,12)
    {
        int lt=mh[j];
        if(j==2&&check(i))lt=29;
        REP(k,i==a&&j==b?c:1,lt)if(i%(j*k)==0)
        {
            print(i,j,k);
            return 0;
        }
    }
    return 0;
}

C.パズルのお手伝い

题意:给一个只包含A, B, X, Y的字符串,每次操作可以减去一个字符或者一个你自己规定的两个由两个字符组成的组合,问将字符串清空的最小操作数

做法:枚举所有组合,取最小值就好了

#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
#define REP(a,b,c) for(register int a=(b),a##end=(c);a<=a##end;++a)
#define DEP(a,b,c) for(register int a=(b),a##end=(c);a>=a##end;--a)
const int MAXN=1000+10,inf=0x3f3f3f3f;
int n,ans=inf;
char s[MAXN];
template<typename T> inline void read(T &x)
{
    T data=0,w=1;
    char ch=0;
    while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
    if(ch=='-')w=-1,ch=getchar();
    while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
    x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
    if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
int main()
{
    read(n);scanf("%s",s+1);
    REP(i,1,n)
        if(s[i]=='A')s[i]=1;
        else if(s[i]=='B')s[i]=2;
        else if(s[i]=='X')s[i]=3;
        else s[i]=4;
    REP(i,1,4)REP(j,1,4)REP(k,1,4)REP(p,1,4)
    {
        int res=n;
        REP(l,1,n)if((s[l-1]==i&&s[l]==j)||(s[l-1]==k&&s[l]==p))res--,++l;
        chkmin(ans,res);
    }
    write(ans,'\n');
    return 0;
}

D.レースゲーム

题意:一个 \(n*m\) 的棋盘,其中第 \(1\) 列和第 \(m\) 列是双方的阵营。棋盘上现在有一些双方的棋子,剩下的位置是空地。棋子只能往对方的方向走(即一个向左,一个向右),可以吃掉对方的棋子。最先将自己棋子移动到对方阵营里的人获胜。给定一个棋盘局面,问谁必胜

做法:首先特判有没有没有阻碍直接可以到对面阵营的。然后由于双方足够聪明,所以每种局面都可以转化成一种无论谁再走一步就会吃子的局面。而谁从原来的局面变成新局面的步数更多谁就必胜,因为步数少的那一个人必定会先走出被吃子的那一步,然后引发连锁反应,使自己所有子都被吃

#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
#define REP(a,b,c) for(register int a=(b),a##end=(c);a<=a##end;++a)
#define DEP(a,b,c) for(register int a=(b),a##end=(c);a>=a##end;--a)
const int MAXN=2000+10,inf=0x3f3f3f3f;
int n,m;
ll vL,vR;
char G[MAXN][MAXN];
std::vector< std::pair<int,int> > ext;
template<typename T> inline void read(T &x)
{
    T data=0,w=1;
    char ch=0;
    while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
    if(ch=='-')w=-1,ch=getchar();
    while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
    x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
    if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline void init()
{
    int mL=inf,mR=inf;
    REP(i,1,n)
    {
        REP(j,1,m)
        {
            if(G[i][j]=='x')chkmin(mR,j-1);
            if(G[i][j]!='.')break;
        }
        DEP(j,m,1)
        {
            if(G[i][j]=='o')chkmin(mL,m-j);
            if(G[i][j]!='.')break;
        }
    }
    if(mL!=inf||mR!=inf)puts(mL<=mR?"o":"x"),exit(0);
}
int main()
{
    read(n);read(m);
    REP(i,1,n)scanf("%s",G[i]+1);
    init();
    REP(i,1,n)
    {
        int j=1;
        while(j<=m)
        {
            while(j<=m&&G[i][j]=='.')++j;
            int L=j,Lr,Lp,Ls=0;
            while(j<=m&&G[i][j]!='x')++j;
            while(j<=m&&G[i][j]!='o')++j;j--;
            int R=j,Rl,Rp,Rs=0;
            if(L>R)break;
            DEP(k,R,L)if(G[i][k]=='o'){Lr=k;break;}
            REP(k,L,R)if(G[i][k]=='x'){Rl=k;break;}
            Lp=Lr,Rp=Rl;
            while(Rp-Lp-1>2)Lp++,Rp--;
            int mk=(Rp-Lp-1==2);
            DEP(k,Lr,L)if(G[i][k]=='o')vL+=Lp-k,Lp--,Ls++;
            REP(k,Rl,R)if(G[i][k]=='x')vR+=k-Rp,Rp++,Rs++;
            if(mk)ext.push_back(std::make_pair(Ls+Rs,Ls));
            ++j;
        }
    }
    std::sort(ext.begin(),ext.end());
    DEP(i,ext.size()-1,0)
        if((ext.size()-i-1)%2)vR+=ext[i].first-ext[i].second;
        else vL+=ext[i].second;
    puts(vL>vR?"o":"x");
    return 0;
}

转载于:https://www.cnblogs.com/hongyj/p/9803873.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值