Contest2821 - 2021个人训练赛第12场

问题 A: Tax Included Price

题目描述

The consumption tax rate in the Republic of ARC is t percent, where t is a positive integer.
There is a shop called Seisu-ya (integer shop) there. It sells each positive integer A for A yen (Japanese currency) excluding tax, that is, ⌊(100+t)A/100⌋ yen including tax. Here, ⌊x⌋ denotes the largest integer not greater than x for a real number x.

Although Seisu-ya sells every positive integer, there are some positive integer values that cannot be the tax-included price of an integer. Among those values, find the N-th smallest value.

Constraints
1≤t≤50
1≤N≤109

输入

Input is given from Standard Input in the following format:
t N

输出

Print the answer.

样例输入 

【样例1】
10 1
【样例2】
3 5
【样例3】
1 1000000000

样例输出

【样例1】
10
【样例2】
171
【样例3】
100999999999

提示

样例1解释
In this sample, the consumption tax rate is 10 percent.
The integer 9 is sold for ⌊110/100×9⌋=⌊9.9⌋=9 yen including tax.
The integer 10 is sold for ⌊110/100×10⌋=⌊11⌋=11 yen including tax.
From above, we can see that 10 is not the tax-included price of any integer, and this is the minimum such value.
样例2解释
If the consumption tax rate is 3 percent, the smallest values that cannot be the tax-included price of an integer are 34,68,102,137,171,…

思路:[X]是不大于,由公式 ⌊(100+t)A/100⌋不难理解

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int main() 
{
    ios;
    ll t, N; 
	cin >> t >> N;
    ll n = (100*N+t-1)/t;
    ll a = (100+t)*(n-1)/100;
    ll b = (100+t)*n/100;
    assert(b-a == 2);//assert是用来避免显而易见的错误的,而不是处理异常的。错误和异常是不一样的,错误是不应该出现的,异常是不可避免的
    cout << (a+b)/2 <<endl;
    return 0;
}


问题 B: Village of M People

题目描述

The Republic of ARC has N citizens, all of whom play competitive programming. Each citizen is given a dan (grade) which is 1, 2, …, or K, according to their skill.
A national census has revealed that there are exactly Ai citizens with dan i. To make this data easier to understand, the king has decided to describe the country as if it were a village of M people.

Set the number of people with dan i in the village, Bi, so that  is minimized, while satisfying the following:
each Bi is a non-negative integer, satisfying .Print one such way to set B=(B1,B2,…,BK).

Constraints
1≤K≤105
1≤N,M≤109
Each Ai is a non-negative integer satisfying .

输入

Input is given from Standard Input in the following format:
K N M
A1 A2 … AK

输出

Print the elements in your integer sequence B satisfying the requirement in one line, with spaces in between.
B1 B2 … BK
If multiple sequences satisfy the requirement, any of them will be accepted.

样例输入 

【样例1】
3 7 20
1 2 4
【样例2】
3 3 100
1 1 1
【样例3】
6 10006 10
10000 3 2 1 0 0
【样例4】
7 78314 1000
53515 10620 7271 3817 1910 956 225

思路:优先队列

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int k,n,m;
ll A[100005],B[100005];
priority_queue<pair<int,int>>q;
int main()
{
    ios
    cin>>k>>n>>m;
    int sum=0;
    for(int i=1;i<=k;i++){
        cin>>A[i];
        B[i]=((1.0*m)/n)*A[i];
        sum+=B[i];
        q.push({abs(n*B[i]-m*A[i]),i});
    }
    int x=m-sum;
    while(x--)
    {
        B[q.top().second]++;
        q.pop();
    }
    for(int i=1;i<=k;i++)
    cout<<B[i]<<" ";
    return 0;
}

问题 C: Coprime Set

题目描述

Given is a positive integer N. Print an integer sequence A=(A1,A2,…,AN) satisfying all of the following:

1≤Ai≤10000;
Ai≠Aj and gcd(Ai,Aj)>1 for i≠j;
gcd(A1,A2,…,AN)=1.
We can prove that, under the Constraints of this problem, such an integer sequence always exists.

Constraints
3≤N≤2500

输入

Input is given from Standard Input in the following format:

N

输出

Print the elements in your integer sequence A satisfying the conditions in one line, with spaces in between.
A1 A2 … AN
If multiple sequences satisfy the conditions, any of them will be accepted.

样例输入 

4

样例输出 

84 60 105 70

提示

All of the conditions are satisfied, since we have:
gcd(84,60)=12
gcd(84,105)=21
gcd(84,70)=14
gcd(60,105)=15
gcd(60,70)=10
gcd(105,70)=35
gcd(84,60,105,70)=1

思路:n个数的最大公因数是1

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ios ios::sync_with_stdio(false),cin.tie(0);
int main()
{
	ios
	int n;
	cin>>n;
	for(int i=n;i>0;i--)
	{
		cout<<i<<" ";
	}
	return 0;
}//看了大佬代码得到思路


问题 G: 漂亮的字符串

题目描述

Bob 有个文件,里面储存着很多字符串,他决定评判一下这些字符串,看看它们是漂亮的还是普通的字符串。 
漂亮的字符串就是那些删除掉若干字符后,剩余的 4 个字符满足“前两个和后两个分别相同”,或“中间和两边分别相同”的字符串,即 AABB 和 ABBA 形式的字符串(形如 AAAA的也是漂亮的)。 
剩下的都是普通的字符串

输入

第 1 行,字符串的组数 N。 
第 2~N+1 行,  每行输入一组字符串 

输出

共 N 行,每行输出:”pretty”表示该字符串很漂亮  ;”normal”表示该字符串比较普通 

样例输入 

5 
Hello 
WoWoWo 
LoraBit 
youngBoy 
Dejiwe

样例输出 

normal 
pretty 
normal 
pretty 
normal

提示

WoWoWo  删去一些字符后可变成 WWoo  也可以变成 WooW、oWWo 所以是漂亮的 
youngBoy  删去一些字符后可变成 yooy  所以是漂亮的 
 
对于 50%的数据: 1<=n<=100; 
对于 100%的数据: 1<=n<=10000;  1<=字符串长度<=10; 

思路:由于字符串太短,直接四重循环暴力。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ios ios::sync_with_stdio(false),cin.tie(0);
int main()
{
	int n;
	cin>>n;
	string s;
	bool flag=false;
	while(n--)
	{
		cin>>s;
		/*if(s.size()<4)
		cout<<"normal"<<endl;
		else if(s.size()==4)
		{
		if(s[0]!=s[3]&&s[1]!=s[2])
		cout<<"normal"<<endl;
		else if(s[0]==s[1]&&s[2]==s[3])
		cout<<"pretty"<<endl;
		else if(s[0]==s[3]&&s[1]==s[2])
		cout<<"pretty"<<endl;
		else if(s[0]==s[3]&&s[1]==s[2]&&s[0]==s[1])
		cout<<"pretty"<<endl;
	}*/
	/*else if(s.size()>4)
	*/
	        flag=false;
		    for(int i=0;i<s.size();i++)
		    {
			for(int j=i+1;j<s.size();j++)
			{
			for(int x=j+1;x<s.size();x++)
			{
			for(int y=x+1;y<s.size();y++)
			{
			if((s[i]==s[j]&&s[j]==s[x]&&s[x]==s[y])||(s[i]==s[j]&&s[x]==s[y])||(s[i]==s[y]&&s[x]==s[j])) 
			flag=true;
		}
	}
}
}
	if(flag) cout<<"pretty"<<endl;
	else cout<<"normal"<<endl;
}
}



问题 I: 外卖

题目描述

Bob 是一个重度外卖依赖者。这天他挑中了一家店,这家店总共有 n 种菜品,每种菜品限点一份,需要满 m 元钱才可配送,因此 Bob 想知道他至少需要花多少钱才能满足最低配送要求。

输入

输入共两行,第一行为两个正整数,n 和 m,第二行为 n 个正整数 ai  

输出

输出一个数,满足最低配送要求所花的最少钱数。

样例输入 

【样例1】
3 10 
3 7 9
【样例2】
5 12 
10 11 7 8 9
【样例3】
3 8 
1 6 9 

样例输出 

【样例1】
10
【样例2】
15
【样例3】
9

提示

对于第二个样例,最低配送要求为 12 元,最优解为点 7 块和 8 块的两个菜,最少花 15元。 

对于 30% 的数据,满足 n ≤ 15 。 
对于 100% 的数据,满足 n ≤ 200, m ≤所有ai的和 ≤ 50000 。

思路:0-1背包,本题容量和价值,v[i]以及w[i]相同,都用a[i]表示

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int a[50005],b[50005];
int main()
{
	int n,m,j,cnt=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++) 
	{
		cin>>a[i];
		cnt+=a[i];
	}
	memset(b,inf,sizeof(b));
	b[0]=0;
	for(int i=1;i<=n;i++)
	{
	for(j=cnt;j>=a[i];j--)
	if(b[j-a[i]]+a[i]<b[j])
	b[j]=b[j-a[i]]+a[i];
	for(j=a[i]-1;j>=1;j--)
	if(b[j+1]<b[j])
	b[j]=b[j+1];
}
	cout<<b[m]<<endl;
}

问题 J: 魔幻背包

(感觉原理与上题类似,但还没想出来)

题目描述

Bob 是个聪明的小孩,他在小学的时候就已经掌握了 01 背包的使用方法。所谓 01 背包问题,就是从 n 个物品中(每个物品有 w[i]的重量和 v[i]的价值)选出若干个,每个物品可以选或者不选,使得在总重量不超过 m 的情况下,总价值最大。 
有一天,Bob 买到了一个背包,这个背包能够承受重量也是 m。不一样的是,这个背包有一个特别的性质:如果背包还没满的话,放入下一件物品之后,背包内的重量可以超过 m。例如有 3 件物品,物品 1 的重量和价值分别为 3,3,物品 2 的为 2,1,物品 3 的为 3,3。假如背包的承受重量 m 为 6: 
  第一种情况下:先放入物品 1,3;则此时背包已满,不能放入物品 2,故最后的总价值为 6。 
  第二种情况下:先放入物品 1,2;此时背包中的重量为 5,还没有满,故可以继续放入物品 3。此时虽然背包的重量为 8,但是符合我们的条件,因此总价值为 7。 

输入

输入一共有 3 行,第一行依次为 n(物品数量),m(背包重量)。其中 n≤2000,m≤2000。 
第二行包含 n 个整数 w[i](1≤Wi≤2000)。 
第三行包含 n 个整数 v[i](1≤Ci≤106)。 

输出

输出共一行,为使用这个神奇背包能背的最大价值总和。 

样例输入 

【样例1】
3 6 
3 3 2 
3 3 1 
【样例2】
3 5 
3 3 2 
3 3 10 

样例输出 

【样例1】
7
【样例2】
13
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值