凉心的比赛(一)

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



题意:
将含01的字符串转码成类似于(1)00000
思路:
所有的’1’都会成为一个首位的‘1’,'0’的个数不变
代码:

#include<iostream>
using namespace std;

int main(void)
{
   char s_01[10001];
   int n,sign=0,k=0;
   cin>>n;
   for(int i=0;i<n;i++)
   {
      cin>>s_01[i];
      if(s_01[i]=='1') sign++;
      else k++;
   }
   if(sign) cout<<"1";
   while(k--)
      cout<<"0";
      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.


题意:
求输入数因数的个数
思路:
其实是有数学公式求的,但是没有穷举简单
代码:

#include<iostream>
using namespace std;

int main(void)
{
   int n,count=0;
   cin>>n;
   for(int i=1;i<n;i++)
      if(n%i==0) count++;
   cout<<count;
}

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


题意:
求点的轨迹穿过y=x正方向射线的次数
思路:
记录点与原点的斜率和1的差的符号(用u来表示,1为+,0为-)当异号时,就是穿过了
代码:

#include<iostream>
using namespace std;

char toward[100005];

int main(void)
{
   double x=0,y=0,count=0,n,u,v;
   cin>>n;
   cin>>toward;
   for(int i=0;i<n;i++)
   {
      v=u;
      if(toward[i]=='U') y++;
      else x++;
      if(y<x) u=1;
      else if(y>x) u=0;
      if(u!=v&&i!=0) count++;
   }
   cout<<count;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值