Home >Web Front-end >HTML Tutorial >Codeforces Round#263(Div.2)_html/css_WEB-ITnose

Codeforces Round#263(Div.2)_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:58:57932browse

462 A    题意读懂后就好做了,就是与一个方块上下左右相邻的‘o’的个数,如果是偶数,yes,否则,no。

#include<map>#include<cmath>#include<queue>#include<vector>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#define pi acos(-1.0)#define inf 0xfffffff#define maxn 5000using namespace std;char str[maxn][maxn];int a[maxn],b[maxn];int main(){    int n;    scanf("%d",&n);    for(int i=0;i<n;i++)        scanf("%s",str[i]);   for(int i=0;i<n;i++)       for(int j=0;j<n;j++)         {             int flag=0;             if(i>0)             {                 if(str[i-1][j]=='o') flag++;             }             if(i<n-1)             {                 if(str[i+1][j]=='o') flag++;             }             if(j>0)             {                 if(str[i][j-1]=='o') flag++;             }             if(j<n-1)             {                 if(str[i][j+1]=='o') flag++;             }             if(flag%2==1)             {                 cout<<"NO"<<endl;                 return 0;             }        }    printf("YES\n");    return 0;}

462B  按照字母出现的次数排序,sum就取决于每一个字母的最大个数与k的大小关系。

#include<map>#include<cmath>#include<queue>#include<vector>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#define pi acos(-1.0)#define inf 0xfffffff#define maxn 500000using namespace std;char str[maxn];__int64 a[30];__int64 n,k;bool cmp(__int64 u,__int64 v){    return u>v;}int main(){    scanf("%I64d%I64d",&n,&k);    memset(a,0,sizeof(a));    scanf("%s",str);    for(int i=0;str[i]!='\0';i++)    {        int m=(int)(str[i]-'A');        a[m]++;    }    sort(a,a+27,cmp);    __int64 t=0;    __int64 sum=0;    while(k>0)    {        if(k>=a[t])        {            sum+=a[t]*a[t];            k-=a[t];            t++;        }        else        {            sum+=k*k;            k=0;        }    }    printf("%I64d\n",sum);    return 0;}

463 C  简单的推理就可以差不多找到公式了。

    

#include<map>#include<cmath>#include<queue>#include<vector>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#define pi acos(-1.0)#define inf 0xfffffff#define maxn 500000using namespace std;__int64 a[maxn],b[maxn];__int64 sum=0;bool cmp(__int64 a,__int64 b){    return a>b;}int main(){    int n;    scanf("%d",&n);    for(int i=0;i<n;i++) scanf("%I64d",&a[i]);    sort(a,a+n,cmp);      b[0]=a[0];    for(int i=0;i<n-1;i++)  b[i+1]=b[i]+a[i+1];   // for(int i=0;i<n;i++) cout<<b[i]<<endl;/*    for(int i=n-1;i>0;i--)        sum+=b[i];    for(int i=0;i<n;i++) sum+=a[i];    cout<<sum<<endl;    return 0;}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn