Codeforces round #263 (div.2)

Source: Internet
Author: User

462 after reading the meaning of A, it is easy to do. It is the number of 'o' adjacent to the upper and lower sides of a square. If it is an even number, yes. Otherwise, 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 is sorted by the number of letters, and sum is determined by the relationship between the maximum number of each letter and the size of 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 simple reasoning can almost find the formula.

#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;}

Codeforces round #263 (div.2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.