Codeforces Round #277 (Div. 2) 解题报告

只会做3道。。TUT。。

A题:Calculating Function

水。每两项为1.对奇偶性分类讨论。

代码如下:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

using namespace std;
#define LL __int64
const int INF=0x3f3f3f3f;

int main()
{
    LL n, x;
    scanf("%I64d",&n);
    x=n/2;
    if(n&1)
        printf("%I64d\n",x-n);
        else
            printf("%I64d\n",x);
    return 0;
}

B题:OR in Matrix

水。

把必须为0的填上,然后判断1的是否符合条件。若符合,让剩下的全为1输出,不符合就输出no。

代码如下:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

using namespace std;
#define LL __int64
const int INF=0x3f3f3f3f;
int a[110][110], b[110][110];
int main()
{
    int i, j, k, n, m, flag, flag1, flag2;
    scanf("%d%d",&n,&m);
    for(i=0; i<n; i++)
    {
        for(j=0; j<m; j++)
        {
            scanf("%d",&b[i][j]);
        }
    }
    flag=0;
    memset(a,0,sizeof(a));
    for(i=0; i<n; i++)
    {
        for(j=0; j<m; j++)
        {
            if(!b[i][j])
            {
                for(k=0; k<n; k++)
                {
                    a[k][j]=1;
                }
                for(k=0; k<m; k++)
                {
                    a[i][k]=1;
                }
            }
        }
    }
    for(i=0; i<n; i++)
    {
        for(j=0; j<m; j++)
        {
            if(b[i][j])
            {
                flag1=flag2=0;
                for(k=0;k<n;k++)
                {
                    if(!a[k][j])
                    {
                        flag1=1;
                        break;
                    }
                }
                for(k=0;k<m;k++)
                {
                    if(!a[i][k])
                    {
                        flag2=1;
                        break;
                    }
                }
                if(!flag1&&!flag2)
                    flag=1;
            }
        }
    }
    if(flag)
        puts("NO");
    else
    {
        puts("YES");
        for(i=0; i<n; i++)
        {
            for(j=0; j<m; j++)
            {
                printf("%d ",1-a[i][j]);
            }
            puts("");
        }
    }
    return 0;
}

C题:Palindrome Transformation

先找出改变字母需要的步数,只在P所在的那半侧改变。

然后求出较小的移动的步数。累加即可。

代码如下:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

using namespace std;
#define LL __int64
const int INF=0x3f3f3f3f;
char s[110000];
int judge(char c1, char c2)
{
    int x;
    if(c1>c2) swap(c1,c2);
    return min(c2-c1,c1+26-c2);
}
int main()
{
    int l, r, len, i, p, sum=0, flag=0;
    scanf("%d%d",&len,&p);
    p--;
    l=len-1;
    r=0;
    scanf("%s",s);
    for(i=0; i<len/2; i++)
    {
        if(s[i]!=s[len-i-1])
        {
            sum+=judge(s[i],s[len-i-1]);
            if(p<len/2)
            {
                l=min(l,i);
                r=max(r,i);
            }
            else
            {
                l=min(l,len-i-1);
                r=max(r,len-i-1);
            }
            flag=1;
        }
    }
    if(!flag)
        puts("0");
    else
    {
        if(p-l>r-p)
        {
            sum+=r-l+abs(r-p);
        }
        else
        {
            sum+=r-l+abs(p-l);
        }
        printf("%d\n",sum);
    }
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值