C - ZhangYu Speech (水题)


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 n digits(lets give them indices from 1 to n and name them a_1, a_2 … a_N) 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 b_y = a_x - a_y.
  3. Then ZhangYu brother calculate B_1 ,the sum of all by which are greater than 0 , and scfkcf calculate B_2 , the sum of all by which are less than 0.

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

Input

The first line contains two integers nm (1 \le n,m \le 100000) denoting the number of digits and number of queries. The second line contains n digits (without spaces) a_1, a_2, …, a_n.(0 \le a_i \le 9) 
Each of next m lines contains single integer x (1 \le x \le n) 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

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.


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 100000 + 100;
int c[N][11];
char str[N];
int a[N];
int main()
{
	int i,j,n,m,q;
	while(scanf("%d%d",&n,&m)!=EOF) {
		memset(c,0,sizeof(c));
		scanf("%s",str+1);
		for(i=1;i<=n;i++) {
			q=str[i]-'0';
			a[i]=q;
			c[i][q]++;
			for(j=0;j<10;j++) c[i][j]+=c[i-1][j];
		}
		while(m--) {
			scanf("%d",&q);
			int t1=0,t2=0,s1=0,s2=0;
			for(i=0;i<a[q];i++) {
				t1+=c[q][i];
				s1+=c[q][i]*i;
			}
			for(i=a[q]+1;i<10;i++) {
				t2+=c[q][i];
				s2+=c[q][i]*i;
			}
			s1=t1*a[q]-s1;
			s2=s2-t2*a[q];
		//	cout<<s1<<" "<<s2<<endl;
			if(s1<s2) printf("I agree\n");
			else if(s1>s2) printf("Keep some distance from me\n");
			else printf("Next time\n");
		}
	}
	return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值