链接

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
5xoooxoxoxosoxoooxoxoxooox

output
NO

input
3wswswswsw

output
YES

input
3xpxpxpxpe

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 = 999999999 ;
char ch[310][310] ;int main()
{int n ;while(~scanf("%d",&n)){for(int i = 0 ; i < n ; i++)scanf("%s",ch[i]) ;bool flag = false ;if(n == 1){printf("NO\n") ;continue ;}if(ch[0][0] == ch[0][1]){printf("NO\n") ;continue ;}for(int i = 0 ; i < n ; i++){for(int j = 0 ; j < n ; j++){if(j == i || j+i == n-1){if(ch[i][j] != ch[0][0]){flag = true ;break ;}}else{if(ch[i][j] != ch[0][1]){flag = true ;break ;}}}if(flag)break ;}if(flag)printf("NO\n") ;else printf("YES\n") ;}return 0 ;
}

View Code

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

这个题太坑爹了。。。。。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 = 999999999 ;
const double eps = 1e-8 ;
double ch[100010] ;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 = 1 ; i <= n  ; i++){ch[i] = d*i ;if(ch[i] > 4*a)//也可以把底下这两句变成      ch[i] = fmod(d*i,4*a) ;也对
            {x = (long long)(ch[i]/(4*a)) ;//就是这里用了int结果精度废了ch[i] = ch[i]-x*1.0*4*a ;}}for(int i = 1 ; i <= n ; i++){if(ch[i] >= 0 && ch[i] <= a)printf("%.9lf %.9lf\n",ch[i],sum) ;else if(ch[i] > a && ch[i] <= 2*a)printf("%.9lf %.9lf\n",a,ch[i]-a) ;else if(ch[i] > 2*a && ch[i] <= 3*a)printf("%.9lf %.9lf\n",3*a-ch[i],a) ;else if(ch[i] > 3*a && ch[i] <= 4*a)printf("%.9lf %.9lf\n",sum,4*a-ch[i]) ;}}return 0 ;
}

View Code

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

思路 :这个题比赛的时候没有时间看,后来是问的啸爷,建一棵最小的树,需要注意几个地方就可以了,就是距离为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 __int64using namespace std;int dis[100100];_LL ans[100100];struct N
{int v,next;
}edge[100100];int head[100100];//head[i]代表的是所有与选定的点距离为i的点int Top;int de[100100];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 != -1;p = edge[p].next){printf("%d %d\n",edge[head[len-1]].v,edge[p].v);//如果距离为len的点应该与距离为len-1的点相连,这样他自己的距离才是(len-1)+1de[edge[head[len-1]].v]++;if(de[edge[head[len-1]].v] == m)//如果距离为len的这个点的父节点的度数已经到达了,就要换另外一个距离为len-1的点head[len-1] = edge[head[len-1]].next;de[edge[p].v] = 1;//因为p点已经与其父节点连接了,所以度数要变为1而不是0.
    }
}int main()
{int n,i;_LL m;scanf("%d %I64d",&n,&m);memset(head,-1,sizeof(head));memset(ans,0,sizeof(ans));memset(de,0,sizeof(de));Top = 0;int Max = -1;for(i = 1;i <= n; ++i){scanf("%d",&dis[i]);Max = max(Max,dis[i]);ans[dis[i]]++;Link(dis[i],i);}if(ans[0] != 1){printf("-1\n");return 0;}for(i = 1;i <= Max; ++i){if(ans[i-1] == 0 || (i != 1 && ans[i] > ans[i-1]*(m-1)) || (i == 1 && ans[i] > m) ){printf("-1\n");return 0;}}printf("%d\n",n-1);for(i = 1;i <= Max; ++i){Output(i,m);}return 0;
}

View Code

#include <stdio.h>
#include <iostream>
#include <vector>using namespace std ;vector<int>dis[100010] ;
vector<pair<int,int> >map ;
int main()
{int n, k ;while(~scanf("%d %d",&n,&k)){for(int i = 0 ; i <= n ; i++)dis[i].clear() ;int x ,maxx = 0;for(int i = 1 ; i <= n ; i++){scanf("%d",&x) ;dis[x].push_back(i) ;//将这个距离和下标存储下来maxx = max(maxx,x) ;//求最长距离
        }if(dis[0].size() != 1)//距离为0的点只能有一个就是它本身,只有一个才能做为根节点,否则多个根节点就不符合
        {printf("-1\n");return 0 ;}for(int i = 1 ; i <= maxx ; i++){int edge = (i != 1) ,cnt = 0;//当距离为1的时候,不用考虑父节点与其父节点的那条边,因为本身就是根节点,没有父节点,edge为0//cnt表示的是距选定点距离为i-1的点中的第cnt个for(int j = 0 ; j < dis[i].size() ; j++)//所有与题目中某点距离为i的点
            {if(edge == k)//如果这个点的度数已经到达给出的最大度数k
                {edge = (i != 1) ;cnt++ ;//就换到下一个点
                }if(cnt == dis[i-1].size())//如果所有距离为i的点都用完了
                {printf("-1\n") ;return 0 ;}map.push_back(make_pair(dis[i-1][cnt],dis[i][j])) ;//距离为i的点中的第j个与距离为i-1的点中第cnt个相连edge++ ;}}printf("%d\n",n-1) ;//如果构造的是一棵最小的树,所以n个点最少有n-1条边for(int i = 0 ; i < map.size() ; i++)printf("%d %d\n",map[i].first,map[i].second) ;}return 0 ;
}

View Code

转载于:https://www.cnblogs.com/luyingfeng/p/3616750.html

Codeforces Round #237 (Div. 2)相关推荐

  1. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  2. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  3. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  4. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  5. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  6. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

  7. Codeforces Round #700 (Div. 2) D2 Painting the Array II(最通俗易懂的贪心策略讲解)看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 整场比赛的A ~ E 6题全,全部题目超高质量题解链接: Codeforces Round #700 ...

  8. Codeforces Round #699 (Div. 2) F - AB Tree(贪心、树上DP)超级清晰,良心题解,看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) F - AB Tree Problem ...

  9. Codeforces Round #699 (Div. 2) (A ~ F)6题全,超高质量良心题解【每日亿题】2021/2/6

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) (A.B.C)[每日亿题]2021/2/ ...

最新文章

  1. B - The Suspects POJ - 1611
  2. ORA-03113: end-of-file on communication channel Process ID: 252 Session ID: 1 Serial number: 3
  3. C/C++ 中长度为0的数组
  4. conda切换环境_Python多环境管理,你需要知道的几种方法
  5. 了解OPhone平台---OPhone平台架构和主要开发组件
  6. linux(windows)之svn重定向地址
  7. Top Secret Task(dp+滚动数组)
  8. NAR丨方海发布免疫疾病遗传靶点数据库“优先指数”,助力计算转化医学研究...
  9. linux so获取自己路径,linux下so获得自己文件位置的路径
  10. Spring注解配置框架
  11. Linux服务器校准时间
  12. 随机生成游戏建筑物的算法
  13. 依山傍水,云淡风轻-----只是传说
  14. java生成短网址_最新url.cn短网址缩短生成接口(API)获取方法
  15. 远远被大家低估了的实用智能家居设备——窗帘电机
  16. 凹凸中的相与国 ——读《大清相国》
  17. IDEA setting设置
  18. scala学习--面向对象(OOP)
  19. VC代码的编写和调试
  20. 树的高度单位换算 c语言编辑,小数与单位换算的公式(小数长度单位换算口诀)...

热门文章

  1. 数据库的四大事务特性
  2. ZOJ 3981 2017CCPC秦皇岛 A:Balloon Robot
  3. 2017 Multi-University Training Contest - Team 4:1002. Classic Quotation(KMP+DP)
  4. [PyTorch] reverse the normalization
  5. 各大厂大数据精品分享汇总(进阶版)
  6. matlab2c使用c++实现matlab函数系列教程-ceil函数
  7. 生成式对抗网络GAN生成手写数字
  8. CentOS7 上以 RPM 包方式安装 Oracle 18c 单实例
  9. 卸载MySQL以及重装卡到Start Services的解决办法(亲测有效,刚重装成功)
  10. Kafka:ZK+Kafka+Spark Streaming集群环境搭建(十二)VMW安装四台CentOS,并实现本机与它们能交互,虚拟机内部实现可以上网。...