UESTC第七届ACM趣味程序设计竞赛第四场(正式赛)

111 篇文章 0 订阅
54 篇文章 0 订阅

Memory

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
 

小x和小h是好盆友,小h从小体弱多病,而且还非常健忘,于是把自己平时吃的 n 瓶药都给小x等人保管。

某一天由于雾都的pm2.5爆表,小h的慢性呼吸道疾病又发作了,但当小x掏出药瓶的时候,却发现了异常情况。

小x现在有n瓶药,每瓶药里面有无限个药片,每片药重量严格等于1克。但是,吹毛求疵的小x发现 n 瓶药中有2瓶药的每一片药片在重量上是不合格的,不合格的药片比正常药片轻0.1g。

小x现在有一个电子称 ( 能够显示具体重量 ) ,由于时间紧急,小x决定从每瓶药中选择 bi(1bi) 个药片,称量它们的总和,并且只称一次,从而找出这两瓶不合格药的编号。

现在,请问最小字典序的序列 b( bi 构成 ) 是多少?

Input

一行一个整数 n(2n52)

Output

一行 n 个数字,两两间用空格隔开,注意结尾没有空格。

Sample input and output

Sample Input Sample Output
3
1 2 3

Hint

若  a1,a2..an  比  b1,b2..bn  字典序小,则必存在  j(1jn)  使得  aj  <  bj  且 对于所有 i<j 都有 ai=bi

样例的解释:如果称出来是5.7g,那么就是第1和第2瓶不合格;如果是5.6g,那么就是第1和第3瓶不合格;如果是5.5g,那么就是第2和第3瓶不合格。

Source

第七届ACM趣味程序设计竞赛第三场(正式赛)
比赛时想的是斐波那契数列结果打了大数斐波那契还是不能过然后就没再做了。赛后才知道暴力可以过
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
long long num[55];
long long vis[(55*54)/2];
void dabiao(){
	int cnt=4,ans=4,n=52,i,j,nv=3;
	num[1]=1;num[2]=2;num[3]=3;
	vis[0]=3;vis[1]=4;vis[2]=5;
	for(long long m=4;1;++m){
		for(i=1;i<cnt;++i){
			for(j=0;j<nv;++j){
				if((num[i]+m)==vis[j])break;
			}
			if(j<nv)break;
		}
		if(i>=cnt){
			num[cnt]=m;
			for(i=1;i<cnt;++i){
				vis[nv++]=num[i]+m;
			}
			cnt++;
		}
		if(cnt>n)break;
	}
}
int main()
{
	dabiao();
	int n,i,j,k;
	while(scanf("%d",&n)!=EOF){
		if(n==2){
			printf("1 1\n");
		}
		else {
			for(i=1;i<n;++i){
				printf("%d ",num[i]);
			}
			printf("%d\n",num[n]);
		}
	}
	return 0;
}

The Desire of Asuna

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
 

ZYHAzwraith用自己心爱的键盘换来了很多支漂亮的荧光棒!

一天,他准备用一条由很多个莹光圈相互连接而成的荧光链送给女神Asuna。每个荧光圈只能由一支荧光棒首尾相接成一个环得到。现在他手中有  n  条荧光链,为了最后把这些链拼接成一条链,每次他可以选择任意一条荧光链中的任意一个荧光圈并用魔法把这个圈断开,然后用这个断开的荧光圈去连接任意两条荧光链使之成为一条。

现在ZYHAzwraith想知道最少需要多少次才能把这些荧光链链拼接成一条长链?

Input

第一行是一个整数  n  (  1n2000 ), 表示有  n  条荧光链。 接下来一行有  n  个数,每个数  ai  ( 1ai105 )表示第  i  条链由  ai  个荧光圈相互连接

Output

输出一个整数表示最少的次数。

Sample input and output

Sample Input Sample Output
3
3 2 1
1
3
4 3 4  
2

Hint

第一组样例解释: title

Source

第七届ACM趣味程序设计竞赛第三场(正式赛)
模拟它的过程即可每次选两个环数最多的和一个环数最少的结合
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<list>
using namespace std;
list<int>l;
int main()
{
	int n,i,j,k;
	while(scanf("%d",&n)!=EOF){
		for(i=0;i<n;++i){
			scanf("%d",&k);
			l.push_back(k);
		}
		int ans=0;
		while(1){
			l.sort();
			int a=l.back();l.pop_back();
			if(l.empty())break;
			int b=l.back();l.pop_back();
			ans++;
			if(l.empty())break;
			int c=l.front();l.pop_front();
			if(c==1){
				l.push_back(a+b+1);
			}
			else {
				l.push_back(a+b+1);
				l.push_back(c-1);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

人民币的构造

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
 

我们都知道人民币的面值是 12510 ,为什么是这个数值呢,我们分析了下发现,从 110 的每个数字都可以由每种面值选出至多一张通过加法和减法(找钱)来构成,(比如: 1+2=351=45+1=65+2=71+2+5=8101=9

但是实际上,我们只需要 127 三种面值就可以组成 110 的每一个数字了

1+2=3712=472=571=67+1=87+2=97+1+2=10

那么现在问题来了,给一个数 n ,请问最少需要多少种不同的面值就可以构成从 1n 的所有数字,注意在构成每一个数字时同种面值不能超过 1 张。

Input

一个数字 n (1<= n <=100000)

Output

一个数字,代表最少需要多少种不同的面值可以构成从 1n 的所有数字。

Sample input and output

Sample Input Sample Output
10
3

Source

第七届ACM趣味程序设计竞赛第三场(正式赛)
比赛时一直在想这道题最终还是没想出来当时想的是组成的数肯定都是素数然后一直在找和素数的关系。到比赛快结束是才慢慢的换了思路
思路:已知能1能有一张组成则加上一个它的二倍的数即为两个数能组成的最大值同理一步一步往后推即可
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
int main()
{
	int n,i,j,k;
	while(scanf("%d",&n)!=EOF){
		int num=1,ans=1;
		while(num<n){
			num=num+num*2+1;
			ans++;
		}
		printf("%d\n",ans);
	}
	return 0;
}


宝贵资源

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
 

有一个城市需要建造,给你 N 个矿场的坐标 X , Y ,问把这么多矿坑全都包进城市的话,城市所需最小面积是多少(注意,城市为平行于坐标轴的正方形)

Input

第一行为 N ,表示矿场数目

下面为 N 行 每行两个数字 xi yi ,表示第 i 行表示第 i 个矿场的坐标

2N1000

0xi,yi1000000000

Output

城市所需最小面积

Sample input and output

Sample Input Sample Output
2
0 0
2 2
4

Hint

long long 请使用%lld输入输出

Source

第七届ACM趣味程序设计竞赛第三场(正式赛)
刚开始做的时候用的double型结果wa了换成long long型就过了
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define inf 1000000000+10
using namespace std;
const int maxn=1010;
int main()
{
	int n,i,j,k;
	while(scanf("%d",&n)!=EOF){
		long long  x1=inf,y1=inf,x2=0,y2=0;
		long long  x,y;
		for(i=0;i<n;++i){
			scanf("%lld%lld",&x,&y);
			x1=min(x1,x);y1=min(y1,y);
			x2=max(x2,x);y2=max(y2,y);
		}
		long long  a=x2-x1,b=y2-y1;
		if(a>b){
			printf("%lld\n",a*a);
		}
		else {
			printf("%lld\n",b*b);
		}
	}
	return 0;
}

ZhangYu Speech

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
 

as we all know, ZhangYu(Octopus vulgaris) brother has a very famous speech - "Keep some distance from me". ZhangYu brother is so rich that everyone want to contact he, and scfkcf is one of them. One day , ZhangYu brother agreed with scfkcf to contact him if scfkcf could beat him. There are  n  digits(lets give them indices from  1  to  n  and name them  a1,a2...aN ) and some queries.

for each query:

  1. ZhangYu brother choose an index  x  from  1  to  n .
  2. For all indices  y  (  y  <  x ) calculate the difference  by=axay .
  3. Then ZhangYu brother calculate  B1  ,the sum of all by which are greater than  0  , and scfkcf calculate  B2  , the sum of all by which are less than  0 .

if  B1>|B2|  , ZhangYu brother won and did not agree with scfkcf to contact him; else if  B1  is equals to  |B2|  , ZhangYu brother would ignore the result; else if  B1  <  |B2| , ZhangYu brother lost and agreed with scfkcf to contact him.

Input

The first line contains two integers  n m   (1n,m100000)  denoting the number of digits and number of queries. The second line contains  n  digits (without spaces)  a1,a2,...,an . (0ai9)  Each of next  m  lines contains single integer  x   (1xn)  denoting the index for current query.

Output

For each of  m  queries print "Keep some distance from me" if ZhangYu won, else print "Next time" if ZhangYu brother ignored the result, else print "I agree" if ZhangYu brother lost in a line - answer of the query.

Sample input and output

Sample Input Sample Output
10 3
0324152397
1
4
7
Next time
Keep some distance from me
I agree

Hint

It's better to use "scanf" instead of "cin" in your code.

解题思路:记录每个数字的前缀和即可;

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
const int maxn=1000010;
int vis[maxn][10];
char str[maxn];
int main()
{
	int n,m,i,j,k;
	while(scanf("%d%d",&n,&m)!=EOF){
		scanf("%s",str+1);
		memset(vis,0,sizeof(vis));
		for(i=1;i<=n;++i){
			vis[i][str[i]-'0']++;
			//vis[i][str[i]-'0']+=vis[i-1][str[i]-'0'];
			for(j=0;j<=9;++j){
				vis[i][j]+=vis[i-1][j];
			}
		}
		while(m--){
			scanf("%d",&k);
			int ansa=0,ansb=0;
			for(i=str[k]-'0';i<=9;++i){
				int num=vis[k][i]-vis[0][i];
				ansa+=(i-(str[k]-'0'))*num;
			}
			for(i=str[k]-'0';i>=0;--i){
				int num=vis[k][i]-vis[0][i];
				ansb+=((str[k]-'0')-i)*num;
			}
			if(ansa>ansb){
				printf("I agree\n");
			}
			else if(ansa==ansb){
				printf("Next time\n");
			}
			else {
				printf("Keep some distance from me\n");
			}
		}
	}
	return 0;
}

Search gold

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
 

Dreams of finding lost treasure almost came true recently. A new machine called 'The Revealer' has been invented and it has been used to detect gold which has been buried in the ground. The machine was used in a cave near the seashore where -- it is said -- pirates used to hide gold. The pirates would often bury gold in the cave and then fail to collect it. Armed with the new machine, a search party went into the cave hoping to find buried treasure. The leader of the party was examining the soil near the entrance to the cave when the machine showed that there was gold under the ground. Very excited, the party dug a hole two feel deep. They finally found a small gold coin which was almost worthless. The party then searched the whole cave thoroughly but did not find anything except an empty tin trunk. In spite of this, many people are confident that 'The Revealer' may reveal something of value fairly soon.

So,now you are in the point (1,1)  and initially you have 0 gold.In the  n * m  grid there are some traps and you will lose gold.If your gold is not enough you will be die.And there are some treasure and you will get gold.If you are in the point(x,y),you can only walk to point  (x+1,y),(x,y+1),(x+1,y+2) and (x+2,y+1) .Of course you can not walk out of the grid.Tell me how many gold you can get most in the trip.

It`s guarantee that (1,1) is not a trap;

Input

first come  2  integers,  n,m ( 1n1000 , 1m1000 )

Then follows  n  lines with  m  numbers  aij

(100<=aij<=100)

the number in the grid means the gold you will get or lose.

Output

print how many gold you can get most.

Sample input and output

Sample Input Sample Output
3 3
1 1 1
1 -5 1
1 1 1
5
3 3
1 -100 -100
-100 -100 -100
-100 -100 -100
1
简单dp表示比赛的时候根本就没读这题一直在想a和c
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=1010;
int n,m;
int dp[maxn][maxn];
int map[maxn][maxn];
int main()
{
	int i,j,k;
	while(scanf("%d%d",&n,&m)!=EOF){
		for(i=2;i<=n+1;++i){
			for(j=2;j<=m+1;++j){
				scanf("%d",&map[i][j]);
			}
		}
		for(i=0;i<=n+1;++i){
			for(j=0;j<=m+1;++j){
				dp[i][j]=-inf;
			}
		}
		int ans=map[2][2];
		for(i=2;i<=n+1;++i){
			for(j=2;j<=m+1;++j){
				if(i==2&&j==2){
					dp[2][2]=map[i][j];
					continue;
				}
				dp[i][j]=max(max(dp[i-1][j]+map[i][j],dp[i][j-1]+map[i][j]),max(dp[i-1][j-2]+map[i][j],dp[i-2][j-1]+map[i][j]));
				if(dp[i][j]<=0)dp[i][j]=-inf;
				ans=max(dp[i][j],ans);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Final Pan's prime numbers

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
 

Final Pan likes prime numbers very much.

One day, he want to find the super prime numbers.A prime numbers  n ( n >4) is a super prime number only if  n -4 and  n +4 are both prime numbers,too.

Your task is really easy:Give  N ,find the maximum super prime number  n  that  n <= N .

Input

Only one integer  N.(4<N<1012)

Output

If there is no such interger  n ,print' 1 ',otherwise print  n .

Sample input and output

Sample Input Sample Output
8
7

打个表即可看出
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	long long n;
	while(scanf("%lld",&n)!=EOF){
		if(n>=7){
			printf("7\n");
		}
		else {
			printf("-1\n");
		}
	}
	return 0;
}













评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值