QLU-凉心的比赛(一)

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

  • 输入

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.

  • 输出

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

  • 样例输入

4
1001
1
1

  • 样例输出

100
1

  • 提示

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组成的字符串,两个相邻的1可以合并为1个1,0和1可以交换位置输出操作后的最短字符。

  • 解题思路

由于两个1可以合并成一个1,且0和1可以互换位置也就是不管怎样所有1都可以换到相邻并进行合并,也就是说无论字符串中有多少个1最后都只剩一个1,只需要记录0的数量并判断字符串中是否有1即可。

  • 代码
#include<iostream>
#include<cstdio>
#include<string>

using namespace std;

int main() {
	int ans = 0;
	bool flag = false;
	string s;
	int n;
	cin >> n;
	cin >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == '1') {
			flag = true;
		}
		else {
			ans++;
		}
	}
	if (flag) {
		cout << 1;
	}
	for (int i = 0; i < ans; i++) {
		cout << 0;
	}
}

C题-地下城还有劳拉

  • 题目描述

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?

  • 输入

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

  • 输出

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

  • 样例输入

4 3 0
4 3 11
4 3 7

  • 样例输出

1 1
1 2
3 2

  • 提示

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组成的字符串,两个相邻的1可以合并为1个1,0和1可以交换位置输出操作后的最短字符。

  • 提示
    在这里插入图片描述

  • 解题思路

本题只需分类讨论即可:
1.k <= n - 1 直接输出k + 1和1即可.
2.每次走m - 1的步数行数就会减一,所以得行数的规律x = n - (k / (m - 1))。
3.对于列数需要分奇数和偶数的情况讨论,偶数是加,奇数是减。偶数为y = 2 + (k % (m - 1)),奇数为y = m - (k % (m - 1))。

  • 代码
#include<iostream>
#include<cstdio>

using namespace std;

long long n,m;
long long k;
long long x,y;

int main() {
	cin >> n >> m >> k;
	if(k <= n - 1) {
		cout << k + 1 << ' ' << 1 << endl;
	}
	else {
		k -= n;
		x = n - (k / (m - 1));
		if(x % 2 == 0) {
			y = 2 + (k % (m - 1));
		}
		else {
			y = m - (k % (m - 1));
		}
		cout << x << ' ' << y << endl;
	}
	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.

  • 输入

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

  • 输出

Print a single integer representing the answer to the problem.

  • 样例输入

2
10

  • 样例输出

1
3

  • 提示

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>
#include<cstdio>

using namespace std;

int main() {
	int n;
	int ans = 0;
	cin >> n;
	for (int i = 1; i < n; i++) {
		if ((n - i) % i == 0) {
			ans++;
		}
	}
	cout << ans << endl;
}

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.

  • 输入

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.

  • 输出

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.

  • 样例输入

1
U
6
RURUUR
7
URRRUUU

  • 样例输出

0
1
2

  • 题意

两个王国之间有一堵墙y = x将两个王国分开,法法从(0,0)出发,每次穿过围墙进入不同国家需要交一次过路费,U为y + 1,R为x + 1。

  • 解题思路

需要交过路费前法法必定是走到了围墙上,所以只需要考虑所有y = x的情况的前后状态,由于围墙的分隔作用两个王国的坐标都具有自己的特点,假定围墙上方为1号王国他的坐标一定是y > x,二号王国的坐标一定是x > y,所以据此可以判断在围墙时的前后状态是否处于不同的王国,如果是就记录交了一次过路费,如果不是就不交。

  • 代码
#include<iostream>
#include<cstdio>

using namespace std;

int main() {
	int x = 0, y = 0;
	int a, b, c, d;
	int n;
	int ans = 0;
	string s;
	cin >> n;
	cin >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'U') {
			y++;
		}
		else {
			x++;
		}
		if (x == y) {
			a = x;
			b = y;
			c = x;
			d = y;
			if (s[i] == 'U') {
				b--;
			}
			else {
				a--;
			}
			if (i != n - 1 && s[i + 1] == 'U') {
				d++;
			}
			else if (i != n - 1 && s[i + 1] == 'R') {
				c++;
			}
			if (a < b && c > d) {
				ans++;
			}
			else if (a > b && c < d) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值