CodeForces - 1393

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\n");//zhangfangxing*2
        else if (num6&&num2)printf("YES\n");
        else if (num6&&num4)printf("YES\n");
        else if (num4&&num2>=2)printf("YES\n");
        else printf("NO\n");
    }
    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;
}

你可能感兴趣的:(Codeforces)