ZhangYu Speech

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

Submit Status

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:

ZhangYu brother choose an index x from 1 to n.

For all indices y ( y < x) calculate the difference by=ax−ay.

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 ifB1 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 (1≤n,m≤100000) denoting the number of digits and number of queries. The second line contains n digits (without spaces) a1,a2,…,an.(0≤ai≤9) Each of next m lines contains single integer x (1≤x≤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 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.

Source

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

错因:看懂题意后就直接根据题意暴力求解了,结果O(n^2)的复杂度果断超时

总结:看到数组题后分析下时间复杂度再做,暴力一般都会超时,需要进行下转化

比如 求和,打表 之类

解答分析:水题

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n[100005],s[100005];
char c[100005];
int main()
{
int p,m,x;
s[0]=0;
while(~scanf("%d %d",&p,&m))
{
scanf("%s",c);
for(int i=1;i<=p;i++)
n[i]=c[i-1]-'0';
for(int j=1;j<=p;j++)
s[j]=s[j-1]+n[j];
while(m--)
{
scanf("%d",&x);
int temp=(x-1)*n[x]-s[x-1];
if(temp>0)
printf("Keep some distance from me\n");
else if(temp<0)
printf("I agree\n");
else
printf("Next time\n");
}
}
return 0;
}

最新文章

  1. ajax删除DB数据
  2. 浅谈Android下的Bitmap之大Bitmap加载
  3. pickle 序列化反序列化
  4. 详解CALayer 和 UIView的区别和联系
  5. Chrome 开发者工具有了设备模拟器
  6. jquery 从页面获取li数组,删除不在数组中的key
  7. 用Objective-C的foundation框架解决表达式求值问题
  8. C++类继承中的构造函数和析构函数 调用顺序
  9. 移动平台下的Socket几个问题
  10. perl 获取系统时间
  11. 关于JDEV的连接问题
  12. 【 js 基础 】Javascript “继承”
  13. MongoDB副本集模式安装
  14. stm32开发之串口的调试
  15. .NET Core微服务之基于IdentityServer建立授权与验证服务(续)
  16. wordpress 图片上传冲突
  17. 7Linux存储结构和磁盘划分
  18. 6、Flutter Error waiting for a debug connection: ProcessException: adb did not report f(转)
  19. sublime text 3 笔记 简单配置
  20. Educational Codeforces Round 54 E. Vasya and a Tree(树上差分数组)

热门文章

  1. 19-Perl 特殊变量
  2. 如何配置数据库镜像&lt;一&gt;
  3. c#获取桌面路径和bin文件的路径
  4. 你不知道的css各类布局(一)之固定布局、静态布局
  5. 一行python能干什么?
  6. 深入理解hive之事务处理
  7. 经典i++和++i问题(附带运算符优先级问题)
  8. PXC集群的概述及搭建
  9. VM 下增加磁盘空间
  10. mysql数据库:分表、多表关联、外键约束、级联操作