ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

2021/5/22 upc-Contest2820 - 2021个人训练赛第11场(补题场)

2021-05-22 13:58:13  阅读:185  来源: 互联网

标签:11 int 样例 sum tr 2021 圣诞树 include 补题


以下补题来自各位大佬的帮助

B: ARC Wrecker

题目描述
There are N buildings along AtCoder road. Initially, the i-th building from the left has Ai stories.
Takahashi, the president of ARC Wrecker, Inc., can do the following operation any number of times, possibly zero:
Choose a positive integer X that he likes and shoot a cannonball at that height, which decreases by 1 the number of stories in each building with X or more stories.
Find the number of possible final sceneries of buildings, modulo (109+7).
We consider two sceneries A and B different when the following holds:
let Pi be the number of stories of the i-th building from the left in scenery A;
let Qi be the number of stories of the i-th building from the left in scenery B;
we consider sceneries A and B different when Pi≠Qi for one or more indices i.
Constraints
1≤N≤100000
1≤Ai≤109
All values in input are integers.
输入
Input is given from Standard Input in the following format:
N
A1 A2 ⋯ AN
输出
Print the answer.
样例输入 Copy
【样例1】
2
1 2
【样例2】
6
5 3 4 1 5 2
【样例3】
7
314 159 265 358 979 323 846
样例输出 Copy
【样例1】
4
【样例2】
32
【样例3】
492018656
提示
样例1解释
There are four possible combinations of heights of the buildings, as follows:
(Building 1, Building 2) = (0,0)
(Building 1, Building 2) = (0,1)
(Building 1, Building 2) = (1,1)
(Building 1, Building 2) = (1,2)
样例3解释
There are 20192492160000 possible final sceneries. The correct output is that number modulo 109+7, which is 492018656.

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define mod 1000000007
int q[100002];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	    scanf("%d",&q[i]);
	sort(q+1,q+n+1);
	long long s=1;
	for(int i=n;i>=1;i--)
	{
		s=s*(q[i]-q[i-1]+1)%mod;
	}
	printf("%lld",s);
	return 0;
}

H: ok 字符串

题目描述
商场中展示了这么多玩具,乐乐爱不释手。现在游戏环节开始,只要你能解决一个问题,就能够挑选一件精美的玩具。此时,乐乐需要你们这帮“牛娃”的帮助,请你帮助乐乐解决这个问题。
现在给你一个长度为 n 的字符串,该字符串只包含字符’o’和’k’。你最多可以修改 t 个字符(将字符’o’改为字符’k’或将字符’k’改为字符’o’),使得某一段连续相同的字符个数是最多的。
例如: ‘ooooo’或’kkkkk’像这样的连续相同字符都可以。
请你经过不多于t次地合理修改,帮助乐乐求出字符串某一段连续相同的字符最多个数。
输入
第一行输入整数 n 和 t,分别表示字符串的总长度和最多可以修改的字符数。
第二行输入一行字符串,仅包含字符‘o‘或‘k‘。
输出
输出一个整数,表示经过不多于 t 次地合理修改,字符串某一段连续相同的字符最多个数。
样例输入 Copy
【样例1】
4 2
okko
【样例2】
8 3
ookookoo
样例输出 Copy
【样例1】
4
【样例2】
8
提示
样例一:通过 2 次修改后,可以获得字符串‘oooo‘或‘kkkk‘,所以连续的字符个数是 4。
样例二:虽然 t 是 3,但只需通过 2 次修改后,可以获得字符串‘oooooooo‘,连续的字符个数是 8。
对于 80%的数据,保证 1<=n<=10000,0<=t<=n。
对于另外 20%的数据,保证 n<=1000000, 0<=t<=10000,并保证字符‘o‘的总个数<=10000
或字符‘k‘的总个数<=10000。

大佬真的厉害!!!!

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=1e6+2;
char ok[N];
int n,t;
int main()
{
	scanf("%d %d",&n,&t);
	scanf("%s",ok);
	int o=0,k=0,j=0,sum=0;
	for(int i=0;i<n;i++)
	{
		if(ok[i]=='o') o++;
		else k++;
		while(o>t&&k>t)
		{
			if(ok[j++]=='o') o--;
			else k--;
		}
		sum=max(sum,o+k);
	}
	printf("%d",sum);
	return 0;
}

I: 圣诞树

题目描述
为了营造圣诞节欢快的气氛,大老板泽泽想在江北万达的门口摆放两棵圣诞树(不一定要一模一样)。圣诞树的制造商们可提供给他 n 棵圣诞树,每棵圣诞树都会有一个美丽值,需要用相应的货币购买。货币只能用人民币或美金(不能将人民币换成美金或将美金换成人民币)。每棵圣诞树一定要用规定数量的对应货币购买,也就是说有些树只能用人民币买,有些树只能用美金买(要看制造商们喜欢那种货币)。
如果大老板泽泽带了足够的货币去购买两棵圣诞树,你的任务是帮助泽泽找到两棵圣诞树,他们的美丽值之和最大。如果他无法买到两棵,则输出 0。
输入
第一行输入三个整数 n,c 和 d,n 表示制造商们提供的圣诞树总数,c 表示泽泽所带的人民币,d 表示泽泽所带的美金。
下面 n 行,每行描述一棵圣诞树:每行包含两个整数 bi 和 pi,分别表示第 i 棵圣诞树的美丽值和价格,(特别提醒:美丽值和价格之间用一个空格分隔),字母 “C”或“D”表示货币,其中 C 表示必须要用人民币购买,D 表示必须要用美金购买。(特别提醒:价格和货币之间用一个空格分隔)。
输出
输出泽泽可以购买的两棵圣诞树的最大美丽值之和。如果他不能购买两棵,则输出 0。
样例输入 Copy
【样例1】
3 8 7
10 9 C
3 4 C
5 7 D
【样例2】
2 6 1
2 5 C
2 5 D
【样例3】
3 10 10
4 5 C
6 5 C
10 11 D
样例输出 Copy
【样例1】
8
【样例2】
0
【样例3】
10
提示
样例一:泽泽无法购买第一棵圣诞树,因为他没有足够的人民币。他可以购买第二棵美丽值为 3 的圣诞树,需要付 4 人民币。此外,泽泽还可以购买第三棵美丽值为 5 的圣诞树,需要付 7 美金。 因此,两棵圣诞树的美丽值之和是 8。
样例二:有两棵圣诞树,但泽泽无法购买它们。因为他需要 5 美金购买第二棵圣诞树,而泽泽只有 1 美金,所以他不能买第二棵。
2<=n<=5000;
0<=c,d<=100000
1<=bi,pi<=100000

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
struct tree
{
	int b,p;
	char ch;
}tr[5002];
bool cmp(tree x,tree y)
{
	if(x.b==y.b) return x.p<y.p;
	return x.b>y.b;
}
int main()
{
	int n,c,d;
	scanf("%d %d %d",&n,&c,&d);
	for(int i=0;i<n;i++)
	    scanf("%d %d %c",&tr[i].b,&tr[i].p,&tr[i].ch);
	//sort(tr,tr+n,cmp);
	int sum=0;
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(tr[j].ch=='C'&&tr[i].ch=='C')
			{
				if(tr[i].p+tr[j].p<=c){
			    	sum=max(sum,tr[i].b+tr[j].b);
		    	}	
			}
			else if(tr[i].ch=='D'&&tr[j].ch=='D'){
		    	if(tr[i].p+tr[j].p<=d)
		    	{
		    		sum=max(sum,tr[i].b+tr[j].b);
		    	}
			}
			else if(tr[i].ch=='C'&&tr[j].ch=='D')
			{
				if(tr[i].p<=c&&tr[j].p<=d)
				{
					sum=max(sum,tr[i].b+tr[j].b);
				}
			}
			else if(tr[i].ch=='D'&&tr[j].ch=='C')
			{
				if(tr[i].p<=d&&tr[j].p<=c)
				{
					sum=max(sum,tr[i].b+tr[j].b);
				}
			}
		}
	}
	/*for(int i=0;i<n-1;i++)
	{
		f=0;s=0;
		int C=c,D=d;
		for(int j=i;j<n;j++)
		{
			if(tr[j].ch=='C'&&f<2)
			{
				if(tr[j].p<=C){
			    	s+=tr[j].b,C-=tr[j].p,f++;
		    	}	
			}
			else if(tr[j].ch=='D'&&f<2){
		    	if(tr[j].p<=D)
		    	{
		    		s+=tr[j].b,D-=tr[j].p,f++;
		    	}
			}
		}
		if(f==2){
			sum=s;break;
		}
	}*/
	printf("%d",sum);
	return 0;
}

标签:11,int,样例,sum,tr,2021,圣诞树,include,补题
来源: https://blog.csdn.net/TTTuuuuuuuuuu/article/details/117158521

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有