Educational Codeforces Round 43 (Rated for Div. 2)

A. Minimum Binary Number
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".

You are given a correct string s.

You can perform two different operations on this string:

  1. swap any pair of adjacent characters (for example, "101 "110");
  2. replace "11" with "1" (for example, "110 "10").

Let val(s) be such a number that s is its binary representation.

Correct string a is less than some other correct string b iff val(a) < val(b).

Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).

Input

The first line contains integer number n (1 ≤ n ≤ 100) — the length of string s.

The second line contains the string s consisting of characters "0" and "1". It is guaranteed that the string s is correct.

Output

Print one string — the minimum correct string that you can obtain from the given one.

Examples
input
Copy
4
1001
output
Copy
100
input
Copy
1
1
output
Copy
1
Note

In the first example you can obtain the answer by the following sequence of operations: "1001 "1010 "1100 "100".

In the second example you can't obtain smaller answer no matter what operations you use.

题意:如果字符串由字符“0”和“1”组成,并且没有多余的前导零,则可以将其称为正确字符串。以下是一些示例:“0”、“10”、“1001”。给你一个正确的字符串您可以对此字符串执行两种不同的操作:交换任何一对相邻字符(例如,“101”“110”);将" 11 "改为" 1 " (例如," 110 " " 10 " )。让值是这样一个数字,即s是它的二进制表示。正确的字符串a小于其他正确的字符串b。您的任务是使用上述操作从给定字符串中找到最小的正确字符串。您可以以任何顺序多次使用这些操作(甚至完全不使用任何操作)。

思路:水题,暴力,直到字符串中的‘1’的个数只用一个时结束,那时一定时最小的字符串

代码:

#include<bits/stdc++.h>
using namespace std;
int n;
char s[1000];
int flag[1000];
int main(){
	scanf("%d",&n); 
	scanf("%s",s);
	int sum=0;
	for(int i=0;i<n;i++){
		if(s[i]=='1'){
			sum++;
		}
	}
	memset(flag,0,sizeof(flag)); 
	for(int i=n-1;i>=0;i--){
		if(sum>1){
			if(s[i]=='1'&&s[i-1]=='0'){
				swap(s[i],s[i-1]);
			}
			if(s[i]=='1'&&s[i-1]=='1'){
				flag[i]=1;
				sum--;	
			}
		}
	}
	for(int i=0;i<n;i++){
		if(!flag[i]){
			printf("%c",s[i]);
		}
	}
	printf("\n");
} 


B. Lara Croft and the New Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.

Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x, y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.

Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (n, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. n and m given are such that she always end up in cell (1, 2).

Lara has already moved to a neighbouring cell k times. Can you determine her current position?

Input

The only line contains three integers nm and k (2 ≤ n, m ≤ 109n is always even0 ≤ k < n·m). Note that k doesn't fit into 32-bit integer type!

Output

Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.

题意:你可能听说过今年劳拉·克罗夫特系列的下一场比赛。你也可能看过它的预告片。虽然你肯定错过了关于它的阴谋的主要想法,所以让我揭开秘密的面纱。
劳拉将探索另一个危险的地牢。游戏设计师决定使用好的旧2D环境。地牢可以表示为n行m列的矩形矩阵。单元格( x,y )是第y列第x行中的单元格。劳拉可以在四个方向上在相邻的细胞间移动。
此外,她甚至选择了自己的道路,以避免所有的陷阱。她在矩阵左上角的牢房( 1、…1 )中进入地牢。然后,她一路走下去,来到牢房( n,1 )——左下角。然后她开始以蛇的方式移动——一路向右,一个单元格向上,然后向左移动到第二列的单元格,一个单元格向上。她一直搬家,直到没有人探访的牢房用完。n和m是这样给定的,使得她总是最终在单元( 1,…2 )中。
劳拉已经搬到邻近的牢房k次了。你能确定她的当前位置吗?

水题

代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,m;
	long long k;
	scanf("%lld%lld%lld",&n,&m,&k);
	long long  x=1,y=1;
	if(k<n){
		printf("%lld 1\n",x+k);
	}
	else{
		x=n;
		long long t=k-n+1;
		long long tt=t/(m-1);
		t=t%(m-1);
		if(t!=0){
			x-=tt;
			if(x%2==0){
				y=1;
				y+=t;
			}
			else{
				y=m+1;
				y-=t;
			}
		}
		else{
			x-=tt;
			x++;
			if(x%2==0){
				y=m;
			}
			else
				y=2;
		}
		printf("%lld %lld\n",x,y);
	}
} 


C. Nested Segments
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and jsuch that segment ai lies within segment aj.

Segment [l1, r1] lies within segment [l2, r2] iff l1 ≥ l2 and r1 ≤ r2.

Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.

Input

The first line contains one integer n (1 ≤ n ≤ 3·105) — the number of segments.

Each of the next n lines contains two integers li and ri (1 ≤ li ≤ ri ≤ 109) — the i-th segment.

Output

Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1.

Examples
input
Copy
5
1 10
2 9
3 9
2 3
2 9
output
Copy
2 1
input
Copy
3
1 5
2 6
6 20
output
Copy
-1 -1

题意:查找一个i,j,满足i的区间,包含j的区间;

思路:水题,区间[a,b],按a从小到的排序,b从大到小排序;

代码:

#include<bits/stdc++.h>
using namespace std;
struct p{
	int xiabiao;
	int a;
	int b;
}s[1000005];
int cmp(p x,p y);
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d %d",&s[i].a,&s[i].b);
		s[i].xiabiao=i;
	}
	sort(s,s+n,cmp);
	for(int i=0;i<n-1;i++){
		if(s[i].a<=s[i+1].a&&s[i].b>=s[i+1].b){
			printf("%d %d\n",s[i+1].xiabiao+1,s[i].xiabiao+1);
			return 0;
		}
	}
	printf("-1 -1\n");
	return 0;
} 
int cmp(p x,p y){
	if(x.a!=y.a)
		return x.a<y.a;
	else 
		return x.b>y.b;
} 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值