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

本周依然是div3的第一
在这里插入图片描述
然后开始题解吧

A - Stock Arbitraging

Welcome to Codeforces Stock Exchange! We’re pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope you’ll still be able to make profit from the market!

In the morning, there are n opportunities to buy shares. The i-th of them allows to buy as many shares as you want, each at the price of si bourles.

In the evening, there are m opportunities to sell shares. The i-th of them allows to sell as many shares as you want, each at the price of bi bourles. You can’t sell more shares than you have.

It’s morning now and you possess r bourles and no shares.

What is the maximum number of bourles you can hold after the evening?

Input
The first line of the input contains three integers n,m,r (1≤n≤30, 1≤m≤30, 1≤r≤1000) — the number of ways to buy the shares on the market, the number of ways to sell the shares on the market, and the number of bourles you hold now.

The next line contains n integers s1,s2,…,sn (1≤si≤1000); si indicates the opportunity to buy shares at the price of si bourles.

The following line contains m integers b1,b2,…,bm (1≤bi≤1000); bi indicates the opportunity to sell shares at the price of bi bourles.

Output
Output a single integer — the maximum number of bourles you can hold after the evening.

Examples
在这里插入图片描述
Note
In the first example test, you have 11 bourles in the morning. It’s optimal to buy 5 shares of a stock at the price of 2 bourles in the morning, and then to sell all of them at the price of 5 bourles in the evening. It’s easy to verify that you’ll have 26 bourles after the evening.

In the second example test, it’s optimal not to take any action.

程序如下:

#include<stdio.h>
int main()
{
	int a,c,n,m,r,min,max;
	while(~scanf("%d %d %d",&n,&m,&r))
	{
		scanf("%d",&a);
		min=a;
		for (int i=2;i<=n;i++)
		{
			scanf("%d",&a);
			if (min>a) min=a;
		}
		scanf("%d",&a);
		max=a;
		for (int i=2;i<=m;i++)
		{
			scanf("%d",&a);
			if (max<a) max=a;
		}
		if (min>max) printf("%d\n",r);
		else
		{
			c=r/min;
			r=r%min+c*max;
			printf("%d\n",r);
		}
	}
	return 0;
}

这道题呢思路很简单,就是用自己的钱尽可能多的买早上最便宜的,然后再以晚上最贵的卖出,当然还要判断早上最便宜的是否比晚上最贵的还要贵,那样不买不卖反而是最优解。

B - Tiling Challenge
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
在这里插入图片描述
Note
The following sketches show the example boards and their tilings if such tilings exist:
在这里插入图片描述
我的程序如下:

#include<stdio.h>
int main()
{
	int n,flag;
	char st[52][52];
	while(~scanf("%d",&n))
	{
		getchar();
		for (int i=0;i<n;i++) gets(st[i]);
		for (int i=0;i<n;i++)
		{
			flag=0;
			for (int j=0;j<n;j++)
			{
				if (st[i][j]=='.')
				{
					if (st[i+1][j]=='.' && st[i+1][j-1]=='.' && st[i+1][j+1]=='.' && st[i+2][j]=='.')
					{
						st[i][j]=='#';
						st[i+1][j-1]='#';
						st[i+1][j]='#';
						st[i+1][j+1]='#';
						st[i+2][j]='#';
					}
					else 
					{
						printf("NO\n");
						flag=1;
						break;
					}
				}
			}
			if (flag) break;
		}
		if (!flag) printf("YES\n");
	}
	return 0;
}

然后这道题只要判断遇到第一个空格找他的下、下左、下右、下下是否都为空,是的话就把他填满,继续遍历,如果遇到有一个不为空的情况下,就直接break,输出NO。

C - Prefix Sum Primes
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
在这里插入图片描述
Note
The first solution produces the prefix sums 1,2,3,5,7 (four primes constructed), while the prefix sums in the second solution are 1,2,3,5,6,7,8,10,11 (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.

程序如下

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

这题重在解决造2和3 解决了就能过 差点AC了可惜

D - City Day
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<aj should hold for all d−x≤j<d and d<j≤d+y. Citizens only watch the weather during summer, so we only consider such j that 1≤j≤n.

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
在这里插入图片描述
Note
In the first example days 3 and 8 are not-so-rainy. The 3-rd day is earlier.

In the second example day 3 is not not-so-rainy, because 3+y=6 and a3>a6. Thus, day 8 is the answer. Note that 8+y=11, but we don’t consider day 11, because it is not summer.

程序如下:

#include<stdio.h>
int main()
{
	int n,x,y,flag,a[100002];
	while(~scanf("%d %d %d",&n,&x,&y))
	{
		for (int i=1;i<=n;i++) scanf("%d",&a[i]);
		for (int i=1;i<=n;i++)
		{
			flag=0;
			for (int j=i-x;j<=i+y;j++)
			{
				if (j<1 || j>n) continue;
				if (a[i]>a[j]) flag=1;
			}
			if (!flag)
			{
				printf("%d\n",i);
				break;
			}
		}
	}
	return 0;
}

这题是比较区域最小值,没什么难的

E - Water Lily
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<L≤106).

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.

Examples
在这里插入图片描述
程序如下:

#include<stdio.h>
int main()
{
	double H,L;
	while(~scanf("%lf %lf",&H,&L))
	{
		printf("%.13lf\n",(L*L-H*H)/(2*H));
	}
	return 0;
}

这道题列个方程就行了,签到题。

总的来说,今天的题目很大几率可以AC的,但是就是差点。继续努力。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值