博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #303 A C D
阅读量:3953 次
发布时间:2019-05-24

本文共 6129 字,大约阅读时间需要 20 分钟。

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.

Examples

input

Copy

3-1 0 00 -1 10 2 -1

output

Copy

21 3

input

Copy

4-1 3 3 33 -1 3 33 3 -1 33 3 3 -1

output

Copy

0

【方法】

两辆车相撞,等于1的话本辆车被撞翻,2的话相撞的那辆车撞翻,3的话都被撞翻,模拟就行,从1到n都存入set当中,按照规则操作,输出。

#include 
using namespace std;const int N=111;int a[N][N];int main(){ int n; cin>>n; set
s; for(int i=1;i<=n;i++) { s.insert(i); for(int j=1;j<=n;j++) { cin>>a[i][j]; } } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { if(a[i][j]==1) s.erase(i); if(a[i][j]==2) s.erase(j); if(a[i][j]==3) s.erase(i),s.erase(j); } if(s.size()==0) puts("0"); else { cout<
<
::iterator it=s.begin();it!=s.end();it++) cout<<*it<<" "; cout<

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.

Examples

input

Copy

51 22 15 1010 919 1

output

Copy

3

input

Copy

51 22 15 1010 920 1

output

Copy

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思想,这棵树砍不砍取决于它倒下能不能碰到两边的树。

#include 
using namespace std;int x[100005],h[100005];int main(){ ios::sync_with_stdio(false); int n; cin>>n; if(n==1) { puts("1"); return 0; } for(int i=1;i<=n;i++) cin>>x[i]>>h[i]; int sum=0; for(int i=2;i
h[i]) sum++; else if(x[i+1]-x[i]>h[i]) { sum++; x[i]+=h[i]; } } cout<
<

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.

Examples

input

Copy

515 2 1 5 3

output

Copy

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.

【题意】

贪心,要求最大的不失望的人数,从小到大排序,第一个人肯定不失望,后面与他前面所有人的时间比较。

#include 
using namespace std;int a[100005];int main(){ ios::sync_with_stdio(false); int n; cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1); int sum=a[1],cnt=1; for(int i=2;i<=n;i++) { if(a[i]>=sum) { sum+=a[i]; cnt++; } } cout<
<

 

转载地址:http://ntyzi.baihongyu.com/

你可能感兴趣的文章
技术道德
查看>>
“需求为王”才是根本
查看>>
高效率的危害
查看>>
寻找边缘性创新
查看>>
让创意瞄准市场
查看>>
高效经理人应具有的八个重要习惯
查看>>
优秀的领导者能读懂人才
查看>>
大智若愚也是领导力
查看>>
android如何编译MTK的模拟器
查看>>
android如何添加AP中要使用的第三方JAR文件
查看>>
利用sudo命令为Ubuntu分配管理权限
查看>>
Ubuntu下几个重要apt-get命令用法与加速UBUNTU
查看>>
Ubuntu中网页各种插件安装命令
查看>>
使用tar命令备份Ubuntu系统
查看>>
ubuntu flash 文字乱码解决方案
查看>>
在ubuntu中运行exe文件
查看>>
ubuntu安装命令
查看>>
和上司沟通必备8个黄金句
查看>>
联系查看两张卡的未接电话记录
查看>>
Python 3 之多线程研究
查看>>