UESTC - 1269:ZhangYu Speech【思维】

Time Limit: 1000MS Memory Limit: 65535KB 64bit IO Format: %lld & %llu

 Status

Description

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   digits(lets give them indices from   to   and name them  ) and some queries.

for each query:

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

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

Input

The first line contains two integers     denoting the number of digits and number of queries. The second line contains   digits (without spaces)  .  
Each of next   lines contains single integer     denoting the index for current query.

Output

For each of   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

10 3 
0324152397 


7

Sample Output

Next time 
Keep some distance from me 
I agree

Hint

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

Source

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

注意优化。。

AC-code:

#include<cstdio>
#include<cstring>
char str[100005];
int q[100005];
int main()
{
	int sum,n,m,a,i;
	scanf("%d%d",&n,&m);
	scanf("%s",str);
	q[0]=q[1]=0;
	sum=0;
	for(i=1;i<n;i++)
	{
		sum+=str[i-1]-'0';
		if(sum>i*(str[i]-'0'))
			q[i+1]=-1;
		else if(sum<i*(str[i]-'0'))
			q[i+1]=1;
		else
			q[i+1]=0;
	}
	while(m--)
	{
		scanf("%d",&a);
		if(q[a]==-1)
			printf("I agree\n");
		else if(q[a]==1)
			printf("Keep some distance from me\n");
		else
			printf("Next time\n");
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值