cf545ABCD

A. Toy Cars
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<vector>
using namespace std;
const int maxn=110;
int Map[maxn][maxn];
bool vis[maxn];
int ans[maxn];
int main()
{
	int n,i,j,k;
	while(scanf("%d",&n)!=EOF){
		memset(vis,false,sizeof(vis));
		int cnt=0;
		for(i=1;i<=n;++i){
			bool good=true;
			for(j=1;j<=n;++j){
				scanf("%d",&Map[i][j]);
				if(Map[i][j]==1||Map[i][j]==3){
					good=false;
				}
			}
			if(good){
				ans[cnt++]=i;
			}
		}
		printf("%d\n",cnt);
		for(i=0;i<cnt;++i){
			if(i){
				printf(" %d",ans[i]);
			}
			else {
				printf("%d",ans[i]);
			}
		}
		printf("\n");
	}
	return 0;
} 

B. Equidistant String
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
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.


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<vector>
using namespace std;
const int maxn=100010;
char s[maxn];
char t[maxn];
char ans[maxn];
int main()
{
	int n,m,i,j,k;
	while(scanf("%s%s",s,t)!=EOF){
		int l=strlen(s);
		int num=0;
		for(i=0;i<l;++i){
			if(s[i]!=t[i])num++;
		}
		if(num&1){
			printf("impossible\n");
		}
		else {
			int num1=0;
			for(i=0;i<l;++i){
				if(s[i]==t[i]){
					ans[i]=s[i];
				}
				else if(num1<num/2){
					num1++;
					ans[i]=s[i];
				}
				else {
					ans[i]=t[i];
				}
			}
			ans[l]=0;
			printf("%s\n",ans);
		}
	}
	return 0;
}

C. Woodcutters
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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
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].


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<vector>
#include<cstring>
using namespace std;
const int maxn=100010;
struct Node{
	long long pos,h;
}A[maxn];
bool cmp(Node a,Node b){
	return a.pos<b.pos;
}
int main()
{
	int n,i,j,k;
	scanf("%d",&n);
	for(i=1;i<=n;++i){
		scanf("%lld%lld",&A[i].pos,&A[i].h);
	}
	if(n<3){
		printf("%d\n",n);
		return 0;
	}
	sort(A+1,A+n+1,cmp);
	long long left=A[1].pos,ans=2;
	for(i=2;i<n;++i){
		if(A[i].pos-A[i].h>left){
			left=A[i].pos;ans++;
		}
		else {
			if(A[i].pos+A[i].h<A[i+1].pos){
				ans++;left=A[i].pos+A[i].h;
			}
			else left=A[i].pos;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

D. Queue
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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
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.


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<vector>
using namespace std;
const int maxn=100010;
long long num[maxn];
int main()
{
	int n,i,j,k;
	scanf("%d",&n);
	for(i=1;i<=n;++i){
		scanf("%lld",&num[i]);
	}
	sort(num+1,num+n+1);
	long long time=num[1],ans=1;
	for(i=2;i<=n;++i){
		if(time<=num[i]){
			time+=num[i];
			ans++;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值