链接

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 < 300; n 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
5
xooox
oxoxo
soxoo
oxoxo
xooox
output
NO
input
3
wsw
sws
wsw
output
YES
input
3
xpx
pxp
xpe
output
NO
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#include <map> using namespace std ; const int INF = ;
char ch[][] ; int main()
{
int n ;
while(~scanf("%d",&n))
{
for(int i = ; i < n ; i++)
scanf("%s",ch[i]) ;
bool flag = false ;
if(n == )
{
printf("NO\n") ;
continue ;
}
if(ch[][] == ch[][])
{
printf("NO\n") ;
continue ;
}
for(int i = ; i < n ; i++)
{
for(int j = ; j < n ; j++)
{
if(j == i || j+i == n-)
{
if(ch[i][j] != ch[][])
{
flag = true ;
break ;
}
}
else
{
if(ch[i][j] != ch[][])
{
flag = true ;
break ;
}
}
}
if(flag)
break ;
}
if(flag)
printf("NO\n") ;
else printf("YES\n") ;
}
return ;
}

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 5
2
output
1.0000000000 2.0000000000
2.0000000000 0.0000000000
input
4.147 2.8819
6
output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000

这个题太坑爹了。。。。。WA了好几遍,原来就是因为该用long long我用了int。。。。。。这个题好想,把这个正方形扯成直线再去做,因为浮点数不能用普通的取余,所以要用别的办法,转化成别的类型取余,或者是直接减也行,还可以用fmod,膜拜啊,我今天才知道这个函数、

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#include <map> using namespace std ; const int INF = ;
const double eps = 1e- ;
double ch[] ; int main()
{
double a,d ;
int n ;
while(~scanf("%lf %lf",&a,&d))
{
scanf("%d",&n) ;
double sum = 0.0 ;
long long x;
for(int i = ; i <= n ; i++)
{
ch[i] = d*i ;
if(ch[i] > *a)//也可以把底下这两句变成 ch[i] = fmod(d*i,4*a) ;也对
{
x = (long long)(ch[i]/(*a)) ;//就是这里用了int结果精度废了
ch[i] = ch[i]-x*1.0**a ;
}
}
for(int i = ; i <= n ; i++)
{
if(ch[i] >= && ch[i] <= a)
printf("%.9lf %.9lf\n",ch[i],sum) ;
else if(ch[i] > a && ch[i] <= *a)
printf("%.9lf %.9lf\n",a,ch[i]-a) ;
else if(ch[i] > *a && ch[i] <= *a)
printf("%.9lf %.9lf\n",*a-ch[i],a) ;
else if(ch[i] > *a && ch[i] <= *a)
printf("%.9lf %.9lf\n",sum,*a-ch[i]) ;
}
}
return ;
}

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 2
0 1 1
output
3
1 2
1 3
3 2
input
4 2
2 0 1 3
output
3
1 3
1 4
2 3
input
3 1
0 0 0
output

-1

思路 :这个题比赛的时候没有时间看,后来是问的啸爷,建一棵最小的树,需要注意几个地方就可以了,就是距离为0的点只能有一个,因为只可以有一个根节点,如果距离为 i( i 不等于1) 的点最多可以有距离为i-1的点乘上k-1个,因为距离为i-1的点还需要有一条边分给父节点,当然,当i为1时,他的点最多可以有m个,因为他的父节点本身就是根节点,不需要再分给父节点的父节点。然后就是存边了

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#define _LL __int64 using namespace std; int dis[]; _LL ans[]; struct N
{
int v,next;
}edge[]; int head[];//head[i]代表的是所有与选定的点距离为i的点 int Top; int de[]; void Link(int u,int v)
{
edge[Top].v = v;//v存的是该点的下标
edge[Top].next = head[u];
head[u] = Top++;
} void Output(int len,int m)
{ int p ; for(p = head[len];p != -;p = edge[p].next)
{
printf("%d %d\n",edge[head[len-]].v,edge[p].v);//如果距离为len的点应该与距离为len-1的点相连,这样他自己的距离才是(len-1)+1
de[edge[head[len-]].v]++;
if(de[edge[head[len-]].v] == m)//如果距离为len的这个点的父节点的度数已经到达了,就要换另外一个距离为len-1的点
head[len-] = edge[head[len-]].next;
de[edge[p].v] = ;//因为p点已经与其父节点连接了,所以度数要变为1而不是0.
}
} int main()
{
int n,i; _LL m; scanf("%d %I64d",&n,&m); memset(head,-,sizeof(head));
memset(ans,,sizeof(ans));
memset(de,,sizeof(de)); Top = ; int Max = -; for(i = ;i <= n; ++i)
{
scanf("%d",&dis[i]);
Max = max(Max,dis[i]);
ans[dis[i]]++;
Link(dis[i],i);
} if(ans[] != )
{
printf("-1\n");
return ;
} for(i = ;i <= Max; ++i)
{
if(ans[i-] == || (i != && ans[i] > ans[i-]*(m-)) || (i == && ans[i] > m) )
{
printf("-1\n");
return ;
}
} printf("%d\n",n-); for(i = ;i <= Max; ++i)
{
Output(i,m);
} return ;
}
#include <stdio.h>
#include <iostream>
#include <vector> using namespace std ; vector<int>dis[] ;
vector<pair<int,int> >map ;
int main()
{
int n, k ;
while(~scanf("%d %d",&n,&k))
{
for(int i = ; i <= n ; i++)
dis[i].clear() ;
int x ,maxx = ;
for(int i = ; i <= n ; i++)
{
scanf("%d",&x) ;
dis[x].push_back(i) ;//将这个距离和下标存储下来
maxx = max(maxx,x) ;//求最长距离
}
if(dis[].size() != )//距离为0的点只能有一个就是它本身,只有一个才能做为根节点,否则多个根节点就不符合
{
printf("-1\n");
return ;
}
for(int i = ; i <= maxx ; i++)
{
int edge = (i != ) ,cnt = ;
//当距离为1的时候,不用考虑父节点与其父节点的那条边,因为本身就是根节点,没有父节点,edge为0
//cnt表示的是距选定点距离为i-1的点中的第cnt个
for(int j = ; j < dis[i].size() ; j++)//所有与题目中某点距离为i的点
{
if(edge == k)//如果这个点的度数已经到达给出的最大度数k
{
edge = (i != ) ;
cnt++ ;//就换到下一个点
}
if(cnt == dis[i-].size())//如果所有距离为i的点都用完了
{
printf("-1\n") ;
return ;
}
map.push_back(make_pair(dis[i-][cnt],dis[i][j])) ;//距离为i的点中的第j个与距离为i-1的点中第cnt个相连
edge++ ;
}
}
printf("%d\n",n-) ;//如果构造的是一棵最小的树,所以n个点最少有n-1条边
for(int i = ; i < map.size() ; i++)
printf("%d %d\n",map[i].first,map[i].second) ;
}
return ;
}

Codeforces Round #237 (Div. 2)的更多相关文章

  1. Codeforces Round #237 (Div. 2) B题模拟题

    链接:http://codeforces.com/contest/404/problem/B B. Marathon time limit per test 1 second memory limit ...

  2. Codeforces Round #237 (Div. 2) A

    链接:http://codeforces.com/contest/404/problem/A A. Valera and X time limit per test 1 second memory l ...

  3. Codeforces Round #237 (Div. 2) B. Marathon(卡long long)

    题目:http://codeforces.com/contest/404/problem/B #include <iostream> #include <cstring> #i ...

  4. Codeforces Round #237 (Div. 2) C. Restore Graph(水构造)

    题目大意 一个含有 n 个顶点的无向图,顶点编号为 1~n.给出一个距离数组:d[i] 表示顶点 i 距离图中某个定点的最短距离.这个图有个限制:每个点的度不能超过 k 现在,请构造一个这样的无向图, ...

  5. [Codeforces Round #237 (Div. 2)] A. Valera and X

    A. Valera and X time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  6. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. postgresql crosstab 行转列函数

    http://blog.csdn.net/hexin373/article/details/19242833

  2. JQuery 性能优化

    一.合适的选择器 JQuery 选择器提供丰富的选择器来定位DOM元素, 基本选择器 #id..class.element.*等:那他们哪个更高效呢? 第一选择: $("#id") ...

  3. Activiti源码分析(框架、核心类。。。)

    http://jiangwenfeng762.iteye.com/blog/1338553 Activiti是业界很流行的java工作流引擎,关于Activiti与JBPM5的关系和如何选择不是本文要 ...

  4. mysql安全

    安装MySql时,尽量选择别的端口(默认是3306),密码设复杂一点!在next的步骤中,注意不要选中"允许远程登录". Web漏洞检测及修复 http://wiki.open.q ...

  5. iOS项目里面如何清理缓存

    在正式讲解以前,请先看一下以下图片,在以下这款APP种设有清理缓存,开始我以为很复杂,在弄明白之后,其实就是几句代码就解决了.      在实际项目开发中,我们很多的文件都会缓存在沙盒里面,比如:照片 ...

  6. JavaScript中事件绑定的方法总结

    最近收集了一些关于JavaScript绑定事件的方法,汇总了一下,不全面,但是,希望便于以后自己查看. JavaScript中绑定事件的方法主要有三种: 1 在DOM元素中直接绑定 2 JavaScr ...

  7. 九度OJ 1531 货币面值(网易游戏2013年校园招聘笔试题) -- 动态规划

    题目地址:http://ac.jobdu.com/problem.php?pid=1531 题目描述: 小虎是游戏中的一个国王,在他管理的国家中发行了很多不同面额的纸币,用这些纸币进行任意的组合可以在 ...

  8. away3d打包到IOS锯齿问题解决办法

    很多ios设备是高清屏,一个像素顶普通设备四个像素.从这点上也许可以入手解决. 先把<requestedDisplayResolution>high</requestedDispla ...

  9. SQL Server 2012 读写分离设置

    SQL Server 2012 读写分离设置 - AlsoIn 时间 2014-07-21 17:38:00  博客园-所有随笔区 原文  http://www.cnblogs.com/also/p/ ...

  10. php获取汉字首字母的函数

    本文介绍用php实现汉字转化为首字母的方法,主要功能是:功能明确,易于修改维护和扩展: 英文的字串:不变返回(包括数字):中文字符串:返回拼音首字符: 中英混合串: 返回拼音首字符和英文. 网上的方法 ...