凉心的比赛

#凉心的比赛
##A - 最小的二进制数
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:

swap any pair of adjacent characters (for example, “101” “110”);
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
4
1001
Output
100
Input
1
1
Output
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”)。
设val(s)是这样一个数,即s是它的二进制表示。
正确字符串a小于其他正确字符串b iff val(a) < val(b)。
您的任务是使用上述操作从给定字符串中找到可以获得的最小正确字符串。您可以按任何顺序多次使用这些操作(甚至根本不使用任何操作)。
输入
第一行包含整数n(1 ≤ n ≤ 100)-字符串s的长度。
第二行包含由字符“0”和“1”组成的字符串。保证字符串s是正确的。
输出
打印一个字符串-从给定字符串中可以获得的最小正确字符串。
Examples
Input
4
1001
Output
100
Input
1
1
Output
1
注意
在第一个示例中,您可以通过以下操作序列获得答案:“1001”“1010”“1100”“100”。
在第二个例子中,无论使用什么操作,都无法获得较小的答案。

代码
#include<stdio.h>
#include<string.h>
char a[1000];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int m=n;
scanf("%s",a);
for(int i=0;i<n;i++)
{
if(a[i]‘1’)
m–;
}
if(n
1)
printf("%s\n",a);
else
{
char b=‘1’,c=‘0’;
printf("%c",b);
for(int i=0;i<m;i++)
printf("%c",c);
printf("\n");
}
}

return 0;	

}

##E - 法法在分配工作
Fafa owns a company that works on huge projects. There are n employees in Fafa’s company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.

Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.

Given the number of employees n, find in how many ways Fafa could choose the number of team leaders l in such a way that it is possible to divide employees between them evenly.

Input
The input consists of a single line containing a positive integer n (2 ≤ n ≤ 105) — the number of employees in Fafa’s company.

Output
Print a single integer representing the answer to the problem.

Examples
Input
2
Output
1
Input
10
Output
3
Note
In the second sample Fafa has 3 ways:
choose only 1 employee as a team leader with 9 employees under his responsibility.
choose 2 employees as team leaders with 4 employees under the responsibility of each of them.
choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
Fafa拥有一家从事大型项目的公司。Fafa公司有n名员工。每当公司有一个新的项目要开始工作时,Fafa必须把这个项目的任务分配给所有员工。
法法发现每次这样做对他来说都很累。所以,他决定选择公司里最好的l员工作为团队领导。每当有一个新的项目,Fafa只将任务分配给团队负责人,每个团队负责人将负责一些正数量的员工给他们任务。为了使这个过程对团队领导公平,他们中的每个人都应该对相同数量的员工负责。而且,每一个不是组长的员工都必须由一个组长负责,没有一个组长对另一个组长负责。
考虑到员工人数n,找出Fafa可以通过多少方式选择团队领导l,这样就可以将员工平均分配给他们。
输入
输入包含一个正整数n(2 ≤ n ≤ 10^5)-fafafa公司的员工人数的单行。
输出
打印一个表示问题答案的整数。
Examples
Input
2
Output
1
Input
10
Output
3
注意
在第二个样本中,Fafa有三种方式:
只选择1名员工作为团队领导,9名员工由其负责。
选择2名员工作为团队领导,每名员工负责4名员工。
选择5名员工作为团队领导,每个人负责1名员工。

代码:
#include <bits/stdc++.h>
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int sum=0;
for(int i=1;i<=n/2;i++)
{
if((n-i)%i==0)
sum++;
}
printf("%d\n",sum);
}
return 0;
}

##F - 法法要穿过大门
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.

The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), …). The wall and the gates do not belong to any of the kingdoms.

Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are ‘U’ (move one step up, from (x, y) to (x, y + 1)) and ‘R’ (move one step right, from (x, y) to (x + 1, y)).

Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn’t pay at the gate at point (0, 0), i. e. he is initially on the side he needs.

Input
The first line of the input contains single integer n (1 ≤ n ≤ 105) — the number of moves in the walking sequence.

The second line contains a string S of length n consisting of the characters ‘U’ and ‘R’ describing the required moves. Fafa will follow the sequence S in order from left to right.

Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.

Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
在这里插入图片描述
两个相邻的王国决定在它们之间筑起一堵墙,并设置一些城门,使公民能够从一个王国进入另一个王国。每当一个公民通过一个大门,他必须支付一个银币。
世界可以用一个平面的第一象限来表示,墙是沿着同一条线(即方程x = y的线)建造的。墙下的任何一点属于第一王国,墙上的任何一点属于第二王国。在直线上的任何整数点(即点(0, 0),(1, 1),(2, 2),…)都有一个浇口。城墙和城门不属于任何王国。
Fafa在门的位置(0, 0),他想在两个王国里四处走动。他知道他要做的一系列动作。这个序列是一个字符串,每个字符代表一个移动。Fafa可能做的两个动作是“U”(向上移动一步,从(x, y)移动到(x, y + 1)和“R”(向右移动一步,从(x, y)移动到(x + 1, y))。
Fafa想知道他需要支付的银币数量,以便按照序列S在两个王国之间漫游。请注意,如果Fafa访问一个门而没有从一个王国移动到另一个王国,他不支付银币。同时假设他没有在门口付款(0, 0),也就是说,他最初是站在他需要的一边。
输入
输入的第一行包含单个整数n(1 ≤ n ≤ 105)-行走序列中的移动次数。
第二行包含长度为n的字符串S,由描述所需移动的字符“U”和“R”组成。Fafa将遵循从左到右的顺序。
输出
在一行上,打印一个整数,表示Fafa需要在大门处支付的银币数量,以遵循序列S。
Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
注意
下图描述了第三个示例。红色箭头表示Fafa将遵循的移动顺序。绿色大门代表着联邦航空局必须支付银币的大门。

代码:
#include <stdio.h>
const int MAXN=1e+5;
char str[MAXN];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
scanf("%s",str);
int l=0,x=0,y=0,ans=0;
for(char* c=str;*c;c++)
{
if(*c==‘U’)
y++;
else
x++;
if(x>y&&l1) ans++;
if(x<y&&l
-1) ans++;
if(x!=y) x>y?l=-1:l=1;
}
printf("%d\n",ans);
}
return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值