CodeForces - 1393

29576 단어 Codeforces
CodeForces - 1393
A - Rainbow Dash, Fluttershy and Chess Coloring
     

int t,n;
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        W(n/2+1);
    }
}

B - Applejack and Storages
         ,      ,      

int n,x,num[maxn],q;
char s[4];
int main()
{
    int num2=0,num4=0,num6=0,num8=0;
    scanf("%d",&n);
    rep(i,1,n)
    {
        scanf("%d",&x);
        num[x]++;
        if (num[x]==8)num8++,num6--;
        else if (num[x]==6)num6++,num4--;
        else if (num[x]==4)num4++,num2--;
        else if (num[x]==2)num2++;
    }
    scanf("%d",&q);
    while(q--)
    {
        scanf("%s",s);
        scanf("%d",&x);
        if (s[0]=='+')
        {
            num[x]++;
            if (num[x]==8)num8++,num6--;
            else if (num[x]==6)num6++,num4--;
            else if (num[x]==4)num4++,num2--;
            else if (num[x]==2)num2++;
        }
        else if (s[0]=='-')
        {
            if (num[x]==8)num8--,num6++;
            else if (num[x]==6)num6--,num4++;
            else if (num[x]==4)num4--,num2++;
            else if (num[x]==2)num2--;
            num[x]--;
        }
        if (num8||num6>=2||num4>=2)printf("YES
"
);//zhangfangxing*2 else if (num6&&num2)printf("YES
"
); else if (num6&&num4)printf("YES
"
); else if (num4&&num2>=2)printf("YES
"
); else printf("NO
"
); } return 0; }

C - Pinkie Pie Eats Patty-cakes
  
                 ,  maxx-1   
          ,     ,  123123123

int t,num[maxn],n,x;
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        int maxx=0,cnt=0;
        mem(num,0);
        scanf("%d",&n);
        rep(i,1,n)
        {
            scanf("%d",&x);
            num[x]++;
            maxx=max(maxx,num[x]);
        }
        rep(i,1,n)if (num[i]==maxx)cnt++;
        n-=(cnt-1);
        W((n-maxx)/(maxx-1));
    }
}

D - Rarity and New Dress
dp[i][j]   mapp[i][j]         
   dp    dp[i-2][j],dp[i-1][j-1] dp[i-1][j+1]   
    dp[i-1][j],dp[i-1][j-1] dp[i-1][j+1]   
        +1,         +2
       [i,j]    [i-2][j]      


int dp[maxn][maxn],ans=0,n,m;
int main()
{
    scanf("%d%d",&n,&m);
    rep(i,0,n-1)scanf("%s",mapp[i]);
    rep(i,0,n-1)
    {
        rep(j,0,m-1)
        {
            dp[i][j]=1;
            if (i<2||j==0||j==m-1)dp[i][j]=1;
            else if (mapp[i][j]==mapp[i-1][j]&&mapp[i][j]==mapp[i-1][j-1]&&mapp[i][j]==mapp[i-2][j]&&mapp[i][j]==mapp[i-1][j+1])
                dp[i][j]+=min(min(dp[i-1][j-1],dp[i-2][j]),dp[i-1][j+1]);
            ans+=dp[i][j];
        }
    }
    W(ans);
    return 0;
}

좋은 웹페이지 즐겨찾기