2021/5/21 upc-Contest2819 - 2021个人训练赛第11场

A: God Sequence

题目描述
A sequence of length A+B, E=(E1,E2,…,EA+B), that satisfies all of the conditions below is said to be a god sequence.
E1+E2+⋯+EA+B=0 holds.
There are exactly A positive integers among E1,E2,…,EA+B.
There are exactly B negative integers among E1,E2,…,EA+B.
E1,E2,…,EA+B are all distinct.
−109≤Ei≤109,Ei≠0 holds for every i (1≤i≤A+B).
Construct one god sequence.
We can prove that at least one god sequence exists under Constraints of this problem.
Constraints
1≤A≤1000
1≤B≤1000
All values in input are integers.
输入
Input is given from Standard Input in the following format:
A B
输出
Print the elements of your sequence in one line, with space as separator.
If there are multiple god sequences, any of them will be accepted.
E1 E2 ⋯ EA+B
样例输入 Copy
【样例1】
1 1
【样例2】
1 4
【样例3】
7 5
样例输出 Copy
【样例1】
1001 -1001
【样例2】
-8 -6 -9 120 -97
【样例3】
323 -320 411 206 -259 298 -177 -564 167 392 -628 151
提示
样例1解释
A sequence (1001,−1001) contains A=1 positive integer and B=1 negative integer totaling 1001+(−1001)=0.
It also satisfies the other conditions and thus is a god sequence.
样例2解释
A sequence (−8,−6,−9,120,−97) contains A=1 positive integer and B=4 negative integers totaling (−8)+(−6)+(−9)+120+(−97)=0.
It also satisfies the other conditions and thus is a god sequence.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int main()
{
	int a,b,s=0;
	scanf("%d %d",&a,&b);
	if(a>=b)
	{
		for(int i=1;i<=a;i++)
		{
			printf("%d ",i);
			s+=i;
		}
		for(int i=1;i<=b-1;i++)
		{
			printf("%d ",-i);
			s-=i;
		}
	}
	else{
		for(int i=1;i<=b;i++)
		{
			printf("%d ",-i);
			s-=i;
		}
		for(int i=1;i<=a-1;i++)
		{
			printf("%d ",i);
			s+=i;
		}
	}
	printf("%d",-s);
	return 0;
}

G: 展示玩具

题目描述
一年一度的圣诞节快来临了,玩具公司为此生产了不同类型的圣诞玩具。为了让更多的大小朋友能够买到他们喜欢的玩具,公司决定将这 n 种类型的玩具在江北万达里展示出来。
由于玩具实在太多了,不一定能将所有的玩具一一展示出来。今年的圣诞节大老板泽泽会亲临现扬,他是一个很奇怪的人,他希望每次展示出来的玩具大小尽可能地接近,他不允许展示出来的玩具中有两个玩具的大小差距超过 k。现在给你这个整数 k,请你帮助泽泽计算最多有多少个玩具可以同时被展示出来。
输入
输入两个整数 n 和 k,n 表示玩具的总数,k 表示最大的差值。
下面 n 行,每行输入一个整数 ai,分别表示玩具的尺寸大小。
输出
输出一个整数,表示最多可以展示的玩具总数。
样例输入 Copy
6 3
1
8
4
3
1
2
样例输出 Copy
5
提示
尺寸大小为 1,1,2,3,4 这 5 个玩具可同时展示出来,其中最大的玩具和最小的玩具尺寸之差只有 3,刚好。
1<=n<=5000;
0<=k<=5000;
每个玩具的尺寸都是正整数不超过 5000。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=5e4+2;
int q[N];
int n,k;
int main()
{
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++)
	    scanf("%d",&q[i]);
	sort(q,q+n);
	int maxq=0;
	for(int i=0;i<n;i++)
	{
		int j=i+1,s=1;
		if(q[j]-q[i]<=k&&j<n)
		{
			while(q[j]-q[i]<=k&&j<n)
			{
				j++,s++;
			}
		}
		maxq=max(maxq,s);
	}
	printf("%d",maxq);
	return 0;
 } 

K: 促销骰子

题目描述
小爱的商店正在做促销活动。顾客在付款的时候,有机会掷一次骰子,如果掷出 6,可以获得优惠,并且可以继续掷骰子,直到出现不是 6 的情况,或掷三次为止。获奖规则如下:
如果只有一个 6,优惠 10 元;
如果有两个 6,优惠 100 元;
如果有三个 6,优惠 1000 元。
给定一组投掷的结果,请输出可以获得的优惠金额。
输入
输入由最多三个整数构成,中间由空格分开:
若输入有三个数字,则保证前两个数字为 6;
若输入有两个数字,则保证第一个数字为 6,后一个数字不为 6;
若输入只有一个数字,则保证该数字不为 6。
输出
单个整数:表示获得的优惠金额。
样例输入 Copy
【样例1】
6 3
【样例2】
6 6 6
【样例3】
1
样例输出 Copy
【样例1】
10
【样例2】
1000
【样例3】
0
提示
保证输入的每个数字在 1 到 6 之间。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int a=0,b=0,c=0,s;
	scanf("%d",&a);
	if(a==6)
	{
		s=10;
		scanf("%d",&b);
		if(b==6)
		{
			s=100;
			scanf("%d",&c);
			if(c==6) s=1000;
		} 
	} 
	else s=0;	
	printf("%d",s);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值