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:
Help Valera, write the program that completes the described task for him.
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
5 xooox oxoxo soxoo oxoxo xooox
NO
3 wsw sws wsw
YES
3 xpx pxp xpe
NO
//31 ms 100 KB
#include
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;
}
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.
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.
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.
2 5 2
1.0000000000 2.0000000000 2.0000000000 0.0000000000
4.147 2.8819 6
2.8819000000 0.0000000000 4.1470000000 1.6168000000 3.7953000000 4.1470000000 0.9134000000 4.1470000000 0.0000000000 2.1785000000 0.7034000000 0.0000000000
//60 ms 100 KB
#include
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&&s=l3&&s<=l4)printf("0.0000000000 %.10f\n",(a-(s-l3)));
}
}
return 0;
}
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.
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.
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 ≤ n; ai ≠ 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.
3 2 0 1 1
3 1 2 1 3 3 2
4 2 2 0 1 3
3 1 3 1 4 2 3
3 1 0 0 0
-1
//77 ms 1900 KB
#include
#include
#include
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=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