Codeforces Round #303 (Div. 2)
2015-08-29 18:28
337 查看
A. Toy Cars
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the і-th row and j-th column that describes the result of the collision of the і-th and the j-th car:
- 1: if this pair of cars never collided. - 1 occurs only on the main diagonal of the matrix.
0: if no car turned over during the collision.
1: if only the i-th car turned over during the collision.
2: if only the j-th car turned over during the collision.
3: if both cars turned over during the collision.
Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Input
The first line contains integer n (1 ≤ n ≤ 100) — the number of cars.
Each of the next n lines contains n space-separated integers that determine matrix A.
It is guaranteed that on the main diagonal there are - 1, and - 1 doesn’t appear anywhere else in the matrix.
It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
Output
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
Sample test(s)
input
3
-1 0 0
0 -1 1
0 2 -1
output
2
1 3
input
4
-1 3 3 3
3 -1 3 3
3 3 -1 3
3 3 3 -1
output
0
这题就是在矩阵中,第i行的第j列表示第i辆车与第j辆车碰撞,数值代表碰撞结果,最后输出幸存的车的编号,模拟。
#include <stdio.h> #include <string.h> int main() { int st[110]; memset(st, 0, sizeof(st)); int n, a; while(~scanf("%d",&n)) { for(int i = 1; i <= n; i ++) { for(int j = 1; j <= n; j ++) { scanf("%d",&a); if(!st[i]) { if(a == 1) { st[i] = 1; } else if(a == 2) { if(!st[j]) { st[j] = 1; } } else if(a == 3) { if(!st[j]) { st[j] = 1; } st[i] = 1; } } } } int ans = 0; for(int i = 1; i <= n; i ++) { if(!st[i]) ans ++; } printf("%d\n",ans); for(int i = 1; i <= n; i ++) { if(!st[i]) printf("%d ",i); } printf("\n"); } }
B. Equidistant String
Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance:We will define the distance between two strings s and t of the same length consisting of digits zero and one as the number of positions i, such that si isn’t equal to ti.
As besides everything else Susie loves symmetry, she wants to find for two strings s and t of length n such string p of length n, that the distance from p to s was equal to the distance from p to t.
It’s time for Susie to go to bed, help her find such string p or state that it is impossible.
Input
The first line contains string s of length n.
The second line contains string t of length n.
The length of string n is within range from 1 to 105. It is guaranteed that both strings contain only digits zero and one.
Output
Print a string of length n, consisting of digits zero and one, that meets the problem statement. If no such string exist, print on a single line “impossible” (without the quotes).
If there are multiple possible answers, print any of them.
Sample test(s)
input
0001
1011
output
0011
input
000
111
output
impossible
Note
In the first sample different answers are possible, namely — 0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101.
获得一个和给出字符串一样长度的,与str1,str2的相同长度一致,答案有很多种,输出一种就好,模拟。
#include<stdio.h> #include<string.h> char str1[100010]; char str2[100010]; bool s[100010]; int main() { while(~scanf("%s",str1)) { memset(s,false,sizeof(s)); scanf("%s",str2); int len = strlen(str1); int cnt = 0; for(int i = 0; i < len; i ++) { if(str1[i] != str2[i]) { cnt ++; } else { s[i] = true; } } if(cnt%2 == 1) { printf("impossible\n"); continue; } int amt = 0; for(int i = 0; i < len; i ++) { if(s[i]) printf("%c",str1[i]); else if(!s[i] && amt < cnt/2) { amt ++; printf("%c",str1[i]); } else { printf("%c",str2[i]); } } printf("\n"); } }
C. Woodcutters
Little Susie listens to fairy tales before bed every day. Today’s fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.There are n trees located along the road at points with coordinates x1, x2, …, xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn’t contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of trees.
Next n lines contain pairs of integers xi, hi (1 ≤ xi, hi ≤ 109) — the coordinate and the height of the і-th tree.
The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate.
Output
Print a single number — the maximum number of trees that you can cut down by the given rules.
Sample test(s)
input
5
1 2
2 1
5 10
10 9
19 1
output
3
input
5
1 2
2 1
5 10
10 9
20 1
output
4
Note
In the first sample you can fell the trees like that:
fell the 1-st tree to the left — now it occupies segment [ - 1;1]
fell the 2-nd tree to the right — now it occupies segment [2;3]
leave the 3-rd tree — it occupies point 5
leave the 4-th tree — it occupies point 10
fell the 5-th tree to the right — now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].
DP,尽快搞出来。
D. Queue
Little girl Susie went shopping with her mom and she wondered how to improve service quality.There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed.
Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue.
Input
The first line contains integer n (1 ≤ n ≤ 105).
The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces.
Output
Print a single number — the maximum number of not disappointed people in the queue.
Sample test(s)
input
5
15 2 1 5 3
output
4
Note
Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5.
求最小等待的人数,其实拍完序之后,从小到大遍历,如果时间超过了,其实放在最后面也是没关系的,所以这题也变得非常的简单,sort。
#include <stdio.h> #include <algorithm> using namespace std; int tt[100010]; int main() { int n; while(~scanf("%d",&n)) { for(int i = 0; i < n; i ++) { scanf("%d",&tt[i]); } sort(tt, tt + n); long int sum = 0; int cnt = 0; for(int i = 0; i < n; i ++) { if(tt[i] >= sum) { cnt ++; sum += tt[i]; } } printf("%d\n",cnt); } }
相关文章推荐
- 第3讲:导入表的定位和读取操作
- HDU 1075 What Are You Talking About(map+字符串)
- Python 函数之参数、局部变量
- 求二叉树叶子节点的个数
- 如何确定一个数组中的最大值
- 关于安装JDK不当--找不到或无法加载主类 com.sun.tools.javac.Main问题
- 有关findviewbyid 一个错误用法
- 第2讲:搜索PEB结构获取kernel32.dll的基址暴力搜索内存空间获得 Api 的线性地址
- 项目总结---- imageLoder 的2个Bug解决方法、1.9.4如何选择性删除disk缓存和其它一些错误。
- oracle dblink创建
- 暑假-二分图-E - Girls and Boys
- 为好基友做了个豆瓣相册下载助手,在这里记录分享一下
- MYSQL的添加字段和修改字段
- 控制并发调用接口数
- MongoDB学习十--MongoDB的Replication Introduction
- 树莓派2代(RaspberryPi2)配合温度传感器DS18B20获取温度
- 友元函数
- 在linux下烧写exynos4412 SD卡启动的Supperboot(2)
- 关于iphone6适配
- POJ2528解题报告,区间离散化,线段树