bunz训练赛 A B E

A
You’re given a row with n chairs. We call a seating of people “maximal” if the two following conditions hold:

There are no neighbors adjacent to anyone seated.
It’s impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones (0 means that the corresponding seat is empty, 1 — occupied). The goal is to determine whether this seating is “maximal”.

Note that the first and last seats are not adjacent (if n≠2).

Input
The first line contains a single integer n (1≤n≤1000) — the number of chairs.

The next line contains a string of n characters, each of them is either zero or one, describing the seating.

Output
Output “Yes” (without quotation marks) if the seating is “maximal”. Otherwise print “No”.

You are allowed to print letters in whatever case you’d like (uppercase or lowercase).

题意:判断输入的座位排布符不符合规则,规则一:坐人的位置相邻的座位不能坐人,规则二:在符合第一条规则的情况下不能再坐下人。
思路:单纯考虑相邻的座位会出错,像是4 1001这样的数据就会出错,所以考虑前后补0三个数三个数看,如果出现三个0就代表还有多余的位置,出现相邻两个1就不符合规则一。

#include<iostream>
#include<string>

using namespace std;

int main() {
	int n;
	string t;
	while(cin >> n >> t) {
		int ans = 1;
		t.insert(0,1,'0');
		t += '0';
		for(int i = 0; i < n ; i ++) {
			if(t[i] == '0' && t[i+1] == '0' && t[i+2] == '0')
				ans = 0;
			if(t[i] == '1' && t[i+1] == '1')
				ans = 0;
		}
		if(ans)
			cout << "Yes\n";
		else
			cout << "No\n";
	}
	return 0;
}

B
In the Bus of Characters there are n rows of seat, each having 2 seats. The width of both seats in the i-th row is wi centimeters. All integers wi are distinct.

Initially the bus is empty. On each of 2n stops one passenger enters the bus. There are two types of passengers:

an introvert always chooses a row where both seats are empty. Among these rows he chooses the one with the smallest seats width and takes one of the seats in it;
an extrovert always chooses a row where exactly one seat is occupied (by an introvert). Among these rows he chooses the one with the largest seats width and takes the vacant place in it.
You are given the seats width in each row and the order the passengers enter the bus. Determine which row each passenger will take.

Input
The first line contains a single integer n (1≤n≤200000) — the number of rows in the bus.

The second line contains the sequence of integers w1,w2,…,wn (1≤wi≤109), where wi is the width of each of the seats in the i-th row. It is guaranteed that all wi are distinct.

The third line contains a string of length 2n, consisting of digits ‘0’ and ‘1’ — the description of the order the passengers enter the bus. If the j-th character is ‘0’, then the passenger that enters the bus on the j-th stop is an introvert. If the j-th character is ‘1’, the the passenger that enters the bus on the j-th stop is an extrovert. It is guaranteed that the number of extroverts equals the number of introverts (i. e. both numbers equal n), and for each extrovert there always is a suitable row.

Output
Print 2n integers — the rows the passengers will take. The order of passengers should be the same as in input.
题意:车上有n排,每排两个座位。有两种人,一种内向,选择所在排没人的座位,优先选择宽度小的座位;一种外向,选所在排有人的座位,优先选宽度大的座位,按顺序给出座位宽度和乘客上车的顺序,要求按上车顺序输出乘客座位。
思路:用结构体记录座位宽度和序号,并从小到大排序。按上车顺序,内向的人分配到目前最小的座位,同时将座位序号压入栈中,外向的人就从栈顶取得座位编号。

#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<algorithm>

using namespace std;
queue<int> q;
stack<int> st;
struct seat{
	int nums;
	int w;
	
}m[2000100];
bool cmp(seat a,seat b){
	return a.w < b.w;
}
int main() {
	int n;
	string s;
	while(cin >> n) {
		for(int i = 1; i <= n; i ++) {
			cin >> m[i].w;
			m[i].nums = i;
		}
		sort(m + 1, m + n + 1,cmp);
		cin >> s;
		for(int i = 0,j = 1; i < 2 * n; i ++) {
			if(s[i] == '0') {						
				q.push(m[j].nums);
				st.push(m[j++].nums);
			} else {
				q.push(st.top());
				st.pop();
			}
		}
		while(!q.empty()){
			cout <<  q.front()  << ' ';
			q.pop();
		}
		cout << '\n';
	}
	return 0;
}

E
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.

It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-class android which is produced by a little-known company. His design is not perfect, his characteristics also could be better. So he is bullied by other androids.

One of the popular pranks on Vasya is to force him to compare xy with yx. Other androids can do it in milliseconds while Vasya’s memory is too small to store such big numbers.

Please help Vasya! Write a fast program to compare xy with yx for Vasya, maybe then other androids will respect him.

Input
On the only line of input there are two integers x and y (1≤x,y≤109).

Output
If xy<yx, then print ‘<’ (without quotes). If xy>yx, then print ‘>’ (without quotes). If xy=yx, then print ‘=’ (without quotes).
题意:比较x的y次方和y的x次方的大小
思路:直接算次方肯定不行,数据太大了。我发现除了2 3,3 2,2 4,4 2,和带有1 的数据,其他的底数大反而小。

#include<stdio.h>
int main(){
	int n,m;
	while(~scanf("%d%d",&n,&m)){
		if(n == m || (n == 2 && m == 4) || (n == 4 && m == 2))
			printf("=\n");
		else if(n == 3 && m == 2)
			printf(">\n");
		else if((n > m || (n == 2 && m == 3) || n == 1) && m != 1)
			printf("<\n");
		else
			printf(">\n");
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值