Codeforces Round #234 (Div. 2)

来源:互联网 发布:sar指标源码2 编辑:程序博客网 时间:2024/06/05 05:38

做了好多场cf了,感觉这上面的题挺不错的,有很多技巧,挺行也很新,以后继续

A - Inna and Choose Options


#include<iostream>#include<cstdio>#include<string>using namespace std;int n;string a;string s[]={"1x12","2x6","3x4","4x3","6x2","12x1"};bool solve(int num){    int len=a.size();    bool flag=true;    for(int i=0;i<12/num;i++)    {        flag=true;        for(int j=0;j<num;j++)        if(a[i]!='X'||a[i]!=a[(i+j*12/num)%12])        {            flag=false;            break;        }        if(flag)return true;    }    return false;}int main(){    //freopen("in.txt","r",stdin);    cin>>n;    while(n--)    {        cin>>a;        int ans[10];        int m=0;        if(solve(1))ans[m++]=0;        if(solve(2))ans[m++]=1;        if(solve(3))ans[m++]=2;        if(solve(4))ans[m++]=3;        if(solve(6))ans[m++]=4;        if(solve(12))ans[m++]=5;        int first=true;        cout<<m;        for(int i=0;i<m;i++)        {            cout<<" ";            cout<<s[ans[i]];        }        cout<<endl;    }    return 0;}

B - Inna and New Matrix of Candies

自己思维还是太弱,只要求出s和g差的不同的个数就好了。

#include<iostream>#include<cstdio>#include<string>#include<cstring>using namespace std;const int maxn=1005;const int INF=100000000;int n,m;char s[maxn][maxn];int pos[maxn];int main(){    //freopen("in.txt","r",stdin);    cin>>n>>m;    bool flag=true;    int min1=INF;    memset(pos,0,sizeof(pos));    for(int i=0;i<n;i++)    {        cin>>s[i];        if(!flag)continue;        flag=false;        int xs=-1,xg=-1;        for(int j=0;j<m;j++)        {            if(s[i][j]=='S'&&xg!=-1){flag=true;pos[j-xg]++;break;}            if(xg==-1&&s[i][j]=='G'){xg=j;}        }    }    if(!flag)cout<<-1<<endl;    else    {        int ans=0;        for(int i=0;i<=1000;i++)            if(pos[i]>0)ans++;        cout<<ans<<endl;    }    return 0;}

C - Inna and Huge Candy Matrix


Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from1 ton from top to bottom and the columns — from1 tom, from left to right. We'll represent the cell on the intersection of thei-th row andj-th column as(i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix hasp candies: thek-th candy is at cell(xk, yk).

The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrixx times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrixy times. And then he rotated the matrixz times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like.

Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made!

Input

The first line of the input contains fix integers n,m,x,y,z,p(1 ≤ n, m ≤ 109; 0 ≤ x, y, z ≤ 109; 1 ≤ p ≤ 105).

Each of the following p lines contains two integersxk,yk(1 ≤ xk ≤ n; 1 ≤ yk ≤ m) — the initial coordinates of thek-th candy. Two candies can lie on the same cell.

Output

For each of the p candies, print on a single line its space-separated new coordinates.

Sample test(s)
Input
3 3 3 1 1 91 11 21 32 12 22 33 13 23 3
Output
1 31 21 12 32 22 13 33 23 1


数学题,找出变化后的公式。

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int n,m,x,y,z,p;int x1,y1;void process_clock(int &ansx,int &ansy,int x,int x1,int y1){    if(x==1)ansx=y1,ansy=n-x1+1;    else if(x==2)ansx=n-x1+1,ansy=m-y1+1;    else if(x==3){ansx=m-y1+1,ansy=x1;}}void process_rotate(int &ansx,int &ansy){    if(y%2)        ansy=m-ansy+1;}int main(){    //freopen("in.txt","r",stdin);    cin>>n>>m>>x>>y>>z>>p;    x=x%4;    int ansx,ansy;    while(p--)    {        cin>>x1>>y1;        ansx=x1,ansy=y1;        process_clock(ansx,ansy,x,x1,y1);        if(x%2)swap(n,m);        process_rotate(ansx,ansy);        x1=ansx,y1=ansy;        process_clock(ansx,ansy,4-z%4,x1,y1);        cout<<ansx<<" "<<ansy<<endl;        if(x%2)swap(n,m);    }    return 0;}

D - Dima and Bacteria

题意:有k种细菌,第i种有ci个,按顺序编号,一共有n个细菌。告诉细菌之间传递能量所需的价值。问是否存在对于任何种类i,该种所有细菌相互传递能量的价值都为0(可以传递)。存在就输出Yes,并输出任意两种细菌传递能量的最小值,否则只用输出No.

思路:并查集+floyd最短路

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=600;const int maxm=100010;const int INF=1000000000;int n,m,k;int inwhich[maxm],pra[maxm],rank[maxm];int grid[maxn][maxn];void init(){    for(int i=0;i<=n;i++)    {        pra[i]=i;        rank[i]=0;    }    for(int i=1;i<=k;i++)        for(int j=1;j<=k;j++)        grid[i][j]=INF;}int find(int x){    if(x==pra[x])return x;    return pra[x]=find(pra[x]);}void unite(int x,int y){    if(rank[x]<rank[y])        pra[x]=y;    else    {        pra[y]=x;        if(rank[x]==rank[y])rank[x]++;    }}int main(){    //freopen("in.txt","r",stdin);    scanf("%d%d%d",&n,&m,&k);    int sum=0,u,v,x,c;    init();    for(int i=1;i<=k;i++)    {        scanf("%d",&c);        grid[i][i]=0;        for(int j=sum+1;j<=sum+c;j++)inwhich[j]=i;        sum+=c;    }    while(m--)    {        scanf("%d%d%d",&u,&v,&x);        if(inwhich[u]!=inwhich[v]&&grid[inwhich[u]][inwhich[v]]>x)            grid[inwhich[u]][inwhich[v]]=grid[inwhich[v]][inwhich[u]]=x;        if(x==0)        {            int a=find(u);            int b=find(v);            if(a!=b)unite(a,b);        }    }    for(int i=2;i<=n;i++)    {        if(inwhich[i]==inwhich[i-1])        {            int x=find(i);            int y=find(i-1);            if(x!=y){cout<<"No"<<endl;return 0;}        }    }    for(int p=1;p<=k;p++)    {        for(int i=1;i<=k;i++)        {            for(int j=1;j<=k;j++)                grid[i][j]=min(grid[i][j],grid[i][p]+grid[p][j]);        }    }    cout<<"Yes"<<endl;    for(int i=1;i<=k;i++)    {        for(int j=1;j<=k;j++)            if(grid[i][j]>=INF)cout<<-1<<" ";            else cout<<grid[i][j]<<" ";        cout<<endl;    }    return 0;}



0 0