Codeforces Round #237 (Div. 2)

来源:互联网 发布:淘宝发帖推广怎么弄 编辑:程序博客网 时间:2024/04/29 16:00
点击打开链接
A. Valera and X
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet.

Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:

  • on both diagonals of the square paper all letters are the same;
  • all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.

Help Valera, write the program that completes the described task for him.

Input

The first line contains integer n (3 ≤ n < 300n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.

Output

Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.

Sample test(s)
input
5xoooxoxoxosoxoooxoxoxooox
output
NO
input
3wswswswsw
output
YES
input
3xpxpxpxpe
output
NO
两条对角线的字符是一样的,不在对角线的字符也是一样的但必须不同于对角线的字符。
//31 ms 100 KB#include<stdio.h>char s[307][307];int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        for(int i=1;i<=n;i++)            scanf("%s",s[i]+1);        char c=s[1][1],cc;        int k=n,flag=0;        for(int i=1;i<=n;i++)            if(s[i][i]!=c||s[i][k--]!=c)            {                flag=1;                break;            }        k=1+n;        if(flag){printf("NO\n");continue;}        cc=s[1][2];        if(cc==c){printf("NO\n");continue;}        for(int i=1;i<=n;i++)            for(int j=1;j<=n;j++)                if(i==j||i+j==k)continue;                else                    if(s[i][j]!=cc)                    {                        flag=1;                        break;                    }        if(flag)printf("NO\n");        else printf("YES\n");    }    return 0;}

点击打开链接
B. Marathon
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.

As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equalsnd + 0.5 meters.

Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2·d, ..., n·d meters.

Input

The first line contains two space-separated real numbers a and d (1 ≤ a, d ≤ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.

The second line contains integer n (1 ≤ n ≤ 105) showing that Valera needs an extra drink n times.

Output

Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers i·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.

Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.

Sample test(s)
input
2 52
output
1.0000000000 2.00000000002.0000000000 0.0000000000
input
4.147 2.88196
output
2.8819000000 0.00000000004.1470000000 1.61680000003.7953000000 4.14700000000.9134000000 4.14700000000.0000000000 2.17850000000.7034000000 0.0000000000
将正方形四条边合成一条线段,把这条线段平均分成四份,每次判断走到该得饮料的地点是在那一份上,然后输出坐标。
//60 ms100 KB#include<stdio.h>int main(){    double a,d;    int k;    while(scanf("%lf%lf%d",&a,&d,&k)!=EOF)    {        double x,y,len=a*4.0,s=0;        double l1=a,l2=a*2.0,l3=a*3.0,l4=a*4.0;        while(d>len)d-=len;        for(int i=1;i<=k;i++)        {            s+=d;           while(s>len){s-=len;}           if(s>len)s-=len;            if(s>=0&&s<=l1)                printf("%.10f 0.0000000000\n",s);            else if(s>=l1&&s<l2)                printf("%.10f %.10f\n",a,s-l1);            else if(s>=l2&&s<l3)                printf("%.10f %.10f\n",a-(s-l2),a);            else  if(s>=l3&&s<=l4)printf("0.0000000000 %.10f\n",(a-(s-l3)));        }    }    return 0;}

点击打开链接
C. Restore Graph
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Valera had an undirected connected graph without self-loops and multiple edges consisting of n vertices. The graph had an interesting property: there were at most k edges adjacent to each of its vertices. For convenience, we will assume that the graph vertices were indexed by integers from 1 to n.

One day Valera counted the shortest distances from one of the graph vertices to all other ones and wrote them out in array d. Thus, element d[i] of the array shows the shortest distance from the vertex Valera chose to vertex number i.

Then something irreparable terrible happened. Valera lost the initial graph. However, he still has the array d. Help him restore the lost graph.

Input

The first line contains two space-separated integers n and k (1 ≤ k < n ≤ 105). Number n shows the number of vertices in the original graph. Number k shows that at most k edges were adjacent to each vertex in the original graph.

The second line contains space-separated integers d[1], d[2], ..., d[n] (0 ≤ d[i] < n). Number d[i] shows the shortest distance from the vertex Valera chose to the vertex number i.

Output

If Valera made a mistake in his notes and the required graph doesn't exist, print in the first line number -1. Otherwise, in the first line print integer m (0 ≤ m ≤ 106) — the number of edges in the found graph.

In each of the next m lines print two space-separated integers ai and bi (1 ≤ ai, bi ≤ nai ≠ bi), denoting the edge that connects vertices with numbers ai and bi. The graph shouldn't contain self-loops and multiple edges. If there are multiple possible answers, print any of them.

Sample test(s)
input
3 20 1 1
output
31 21 33 2
input
4 22 0 1 3
output
31 31 42 3
input
3 10 0 0
output
-1
一个图有n个顶点,而且每个顶点所连接的边的条数不超过k,然后给你一个数组d,d[i]表示在图中点i到某个点的最短距离是d[i],如果此图存在,则输出。
有点像构造树,其中d[i]为0的点为根,如果存在d[i]=d[j]+1,那么j点肯定连接i点,然后根据这条性质进行见图,如果在建图的过程中,出现某点的度数大于k或者存在自环,则肯定不存在。
//77 ms1900 KB#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int x[100007],y[100007];int vis[100007];struct T{    int id,degree;}t[100007];int cmp(T a,T b){    return a.degree<b.degree;}int main(){    int n,kk;    while(scanf("%d%d",&n,&kk)!=EOF)    {        int a,cnt=0;        memset(vis,0,sizeof(vis));        for(int i=0;i<n;i++)        {            scanf("%d",&a);            if(a==0)cnt++;            t[i].id=i+1;            t[i].degree=a;        }        if(cnt!=1){printf("-1\n");continue;}        sort(t,t+n,cmp);        int k=0,flag=0,vec=1,xx=1,yy=0;        for(int i=1;i<n;)        {            int j=yy;            while(t[i].degree==vec&&i<n)            {                if(j>=xx)j=yy;                x[k]=t[j].id;y[k++]=t[i].id;                vis[t[i].id]++;vis[t[j].id]++;                if(vis[t[i].id]>kk||vis[t[j].id]>kk||t[i].id==t[j].id)                {                    flag=1;break;                }                i++,j++;            }            vec++;            yy=xx;            xx=i;            if(flag)break;        }        if(flag){printf("-1\n");continue;}        printf("%d\n",k);        for(int i=0;i<k;i++)            printf("%d %d\n",x[i],y[i]);    }    return 0;}

0 0
原创粉丝点击