bnuz 训练 B C D E

B - Tiling Challenge CodeForces - 1150B
One day Alice was cleaning up her basement when she noticed something very curious: an infinite set of wooden pieces! Each piece was made of five square tiles, with four tiles adjacent to the fifth center tile:

By the pieces lay a large square wooden board. The board is divided into n2 cells arranged into n rows and n columns. Some of the cells are already occupied by single tiles stuck to it. The remaining cells are free.
Alice started wondering whether she could fill the board completely using the pieces she had found. Of course, each piece has to cover exactly five distinct cells of the board, no two pieces can overlap and every piece should fit in the board entirely, without some parts laying outside the board borders. The board however was too large for Alice to do the tiling by hand. Can you help determine if it’s possible to fully tile the board?

Input
The first line of the input contains a single integer n (3≤n≤50) — the size of the board.

The following n lines describe the board. The i-th line (1≤i≤n) contains a single string of length n. Its j-th character (1≤j≤n) is equal to “.” if the cell in the i-th row and the j-th column is free; it is equal to “#” if it’s occupied.

You can assume that the board contains at least one free cell.

Output
Output YES if the board can be tiled by Alice’s pieces, or NO otherwise. You can print each letter in any case (upper or lower).

Examples
Input
3
#.#

#.#
Output
YES
Input
4
##.#
#…

##.#
Output
NO
Input
5
#.###
…#
#…
###.#

Output
YES
Input
5
#.###
…#
#…
…#
#…##
Output
NO
题意:能不能用五个单位组成的‘+’填满空缺
一开始用dfs然后wa了,后来想到要从头开始迭代判断每个位置上下左右中是否为空,不过忘记边界了。。。

#include

using namespace std;
char g[60][60];
int n;
const int m[4][2]= {
     {
     0,1},{
     0,-1},{
     1,0},{
     -1,0}};
int jg(int i,int j) {
     
	int a,b;
	if(g[i][j] == '#')
		return 0;
	for(int k = 0; k < 4; k ++) {
     
		a = i + m[k][0];
		b = j + m[k][1];
		if(g[a][b] == '#' || a  < 0 || a >= n || b < 0 || b >= n)
			return 0;
	}
	return 1;
}
void fix(int i,int j) {
     
	int a,b;
	if(jg(i,j)) {
     
		g[i][j] = '#';
		for(int k = 0; k < 4; k ++) {
     
			a = i + m[k][0];
			b = j + m[k][1];
			g[a][b] = '#';
		}
	}
}
int main() {
     
	while(~scanf("%d",&n)) {
     
		getchar();
		int i_,j_,flag = 1;
		for(int i = 0; i < n; i ++) {
     
			for(int j = 0; j < n; j ++) {
     
				scanf("%c",&g[i][j]);
			}
			getchar();
		}

		for(int i = 0; i < n; i ++) {
     
			for(int j = 0; j < n; j ++) {
     
				fix(i,j);
			}
		}
		for(int i = 0; i < n; i ++) {
     
			for(int j = 0; j < n; j ++) {
     

				if(g[i][j] == '.')
					flag = 0;
			}
		}
		if(flag )
			printf("YES\n");
		else
			printf("NO\n");

	}
	return 0;
}

C - Prefix Sum Primes CodeForces - 1150C
We’re giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2.

However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get.

Can you win the prize? Hurry up, the bags are waiting!

Input
The first line of the input contains a single integer n (1≤n≤200000) — the number of number tiles in the bag. The following line contains n space-separated integers a1,a2,…,an (ai∈{1,2}) — the values written on the tiles.

Output
Output a permutation b1,b2,…,bn of the input sequence (a1,a2,…,an) maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any.

Examples
Input
5
1 2 1 2 1
Output
1 1 1 2 2
Input
9
1 1 2 1 1 1 2 1 1
Output
1 1 1 2 1 1 1 2 1
题意:用给的由1和2组成的一段数,排列成前缀和为素数最多的数列
思路:除了2其他的素数都是为奇数,所以尽量让前2位数为2 1,剩下的2排在后面,剩下的1排在最后

#include

int main() {
     
	int n,a[3];
	while(~scanf("%d",&n)) {
     
		a[1] = a[2] = 0;
		for(int i = 0; i < n; i ++) {
     
			int t;
			scanf("%d",&t);
			if(t == 1)
				a[1] ++;
			else
				a[2] ++;
		}
		if(a[2]--)
			printf("2 ");
		if(a[1]--)
			printf("1 ");
		while(a[2]-- > 0) {
     
			printf("2 ");
		}
		while(a[1]-- > 0) {
     
			printf("1 ");
		}
		printf("\n");
	}
	return 0;
}

D - City Day CodeForces - 1199A
For years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the n days of summer. On the i-th day, ai millimeters of rain will fall. All values ai are distinct.

The mayor knows that citizens will watch the weather x days before the celebration and y days after. Because of that, he says that a day d is not-so-rainy if ad is smaller than rain amounts at each of x days before day d and and each of y days after day d. In other words, ad

Help mayor find the earliest not-so-rainy day of summer.

Input
The first line contains three integers n, x and y (1≤n≤100000, 0≤x,y≤7) — the number of days in summer, the number of days citizens watch the weather before the celebration and the number of days they do that after.

The second line contains n distinct integers a1, a2, …, an (1≤ai≤109), where ai denotes the rain amount on the i-th day.

Output
Print a single integer — the index of the earliest not-so-rainy day of summer. We can show that the answer always exists.

Examples
Input
10 2 2
10 9 6 7 8 3 2 1 4 5
Output
3
Input
10 2 3
10 9 6 7 8 3 2 1 4 5
Output
8
Input
5 5 5
100000 10000 1000 100 10
Output
5
题意:找出最早的符合前x天和后y天比当天降雨量多的一天
思路:按题意写就好了,注意边界

#include
using namespace std;

int main() {
     
	int n,x,y,arr[99999];
	while(~scanf("%d%d%d",&n,&x,&y)) {
     
		for(int i = 1; i <= n; i ++) {
     
			scanf("%d",&arr[i]);
		}
		
		for(int i = 1; i <= n; i ++) {
     
			int count = 0,flag = 1;
			for(int j = i - 1; j >= 1; j --) {
     
				if(count ++ == x)
					break;
				if(arr[i] > arr[j]) {
     
					flag = 0;
					break;
				}
			}
			count = 0;
			for(int j = i + 1; j <= n; j ++) {
     
				if(count ++ == y)
					break;
				if(arr[i] > arr[j]) {
     
					flag = 0;
					break;
				}
			}
			if(flag){
     
				printf("%d\n",i);
				break;
			}
		}
	}
	return 0;
}

E - Water Lily CodeForces - 1199B
While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake’s surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface.

Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A?

Input
The only line contains two integers H and L (1≤H

Output
Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10−6.

Formally, let your answer be A, and the jury’s answer be B. Your answer is accepted if and only if |A−B|max(1,|B|)≤10−6.
思路:勾股定理就完事了

#include

int main(){
     
	double h,l;
	while(~scanf("%lf%lf",&h,&l)){
     
		printf("%.13lf\n",(l*l-h*h)*1.0/(2*h));
	}
	return 0;
}

你可能感兴趣的:(bnuz 训练 B C D E)