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

来源:互联网 发布:toro网络意思 编辑:程序博客网 时间:2024/05/06 05:59

只会做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 __int64const 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 __int64const 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 __int64const 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