[2020-3-13]BNUZ套题比赛div3解题报告

[2020-3-13]BNUZ套题比赛div3题解

很开心,本次再次蝉联了训练赛的第一名。排名如下在这里插入图片描述
A - Row
You’re given a row with $ n n 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 0 0$ means that the corresponding seat is empty, $ 1 1 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 n \ne 2 n=2$).

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

The next line contains a string of $ n n 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).

Examples
在这里插入图片描述
Note
In sample case one the given seating is maximal.

In sample case two the person at chair three has a neighbour to the right.

In sample case three it is possible to seat yet another person into chair three.

以下是我的程序:

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n; 
	string a;
	cin>>n>>a;
	a='0'+a+'0';
	if (a.find("000")==-1 && a.find("11")==-1) printf("Yes\n"); else printf("No\n");
	return 0;
}

这道题的想法是1与0的最密分布,只有一种最优解。一开始我的做法是先统计1的数量,如果是奇数个就得有n/2+1个,如果是偶数个就得有n/2个,然后再判断相邻的是否相同,看上去好像是没什么问题,但是就是会WA。所以我又换了另一种思路,这种思路比较巧妙,前后各加一个0,然后寻找字符串中‘000’或者‘11’的位置,如果都没有,则为最优解。‘000’是因为这还有空间,‘11’是因为不符合规则,然后前后加0又巧妙地解决了010或者100的情况。

B - Bus of Characters
这道题用STL就能随便过,但是学艺不精,最主要还是因为在家里不同在学校,没有那种自觉去复习学算法的气氛,再者就是学习时间分配的问题,导致上周学的算法没怎么去巩固,不会用,这道题直接用循环模拟必超时超空间。

C - Cut 'em all!
这题是DFS,以后再说,插个眼。

D - Infinity Gauntlet
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:

the Power Gem of purple color,
the Time Gem of green color,
the Space Gem of blue color,
the Soul Gem of orange color,
the Reality Gem of red color,
the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.

Input
In the first line of input there is one integer n (0≤n≤6) — the number of Gems in Infinity Gauntlet.

In next n lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.

Output
In the first line output one integer m (0≤m≤6) — the number of absent Gems.

Then in m lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.

Examples
在这里插入图片描述
Note
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.

In the second sample Thanos doesn’t have any Gems, so he needs all six.

以下是我的程序:

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,green,yellow,orange,purple,red,blue;
	string a;
	green=0;
	yellow=0;
	orange=0;
	purple=0;
	red=0;
	blue=0;
	cin>>n;
	printf("%d\n",6-n);
	for (int i=0;i<n;i++) 
	{
		cin>>a;
		switch (a[0])
		{
			case 'r':
				red=1;
				break;
			case 'g':
				green=1;
				break;
			case 'p':
				purple=1;
				break;
			case 'b':
				blue=1;
				break;
			case 'o':
				orange=1;
				break;
			case 'y':
				yellow=1;
				break;
		}
	}
	if (green==0) printf("Time\n");
	if (yellow==0) printf("Mind\n");
	if (orange==0) printf("Soul\n");
	if (purple==0) printf("Power\n");
	if (red==0) printf("Reality\n");
	if (blue==0) printf("Space\n");
	return 0;
}

这题是签到题,太简单了,没什么好说的。

E - High School: Become Human
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).

Examples在这里插入图片描述
Note
In the first example 58=5⋅5⋅5⋅5⋅5⋅5⋅5⋅5=390625, and 85=8⋅8⋅8⋅8⋅8=32768. So you should print ‘>’.

In the second example 103=1000<310=59049.

In the third example 66=46656=66.

以下是我的程序:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int x,y;
    scanf("%lld%lld",&x,&y);
    if(x==y)
        printf("=\n");
    else
    {
        if((double)y*log(x)>(double)x*log(y))
            printf(">\n");
        else if((double)y*log(x)<(double)x*log(y))
            printf("<\n");
        else
            printf("=\n");
    }
    return 0;
}

这道题也没什么难度,就单纯用数学方法比较n的m次方和m的n次方谁大,取对数反过来比较就好了。

F - Three displays
这题是动态规划,要更以后再说了,插个眼。

总之,这次在新生中还是第一名。但是,作为有基础的我,这个领先是很正常的,但是随着日后的训练,如果我不认真学的话,不仅会被他们追上来,还会慢慢不学无术,吃完老本就没东西再吃了。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值