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;
}

CDOJ 1269 ZhangYu Speech 数组处理的更多相关文章

  1. CDOJ 1269 ZhangYu Speech

    预处理打表,sum[i][j]表示1.....i这些数字中 j 有几个.然后就很好处理询问了. #include<stdio.h> #include<math.h> #incl ...

  2. [cdoj 1344]树状数组区间加等差数列

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1344 区间加等差数列本质上就是区间修改区间查询,本来想用线段树做,结果这个题就是卡空间和时间……不得已学了区 ...

  3. CDOJ 1256 打表+数组 统计

    昊昊爱运动 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit  St ...

  4. UESTC--1269--ZhangYu Speech(模拟)

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

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

    Final Pan's prime numbers 题目连接: http://acm.uestc.edu.cn/#/problem/show/1272 题意 给你n,要求你在[4,n]范围内找到一个最 ...

  6. LeetCode Top 100 Liked 点赞最高的 100 道算法题

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:刷题顺序,刷题路径,好题,top100,怎么刷题,Leet ...

  7. CDOJ 838 母仪天下 树状数组 (2014数据结构专题

    母仪天下 Time Limit: 1 Sec  Memory Limit: 162 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/838 Descrip ...

  8. cdoj 841 休生伤杜景死惊开 逆序数/树状数组

    休生伤杜景死惊开 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) 陆伯言军陷八卦 ...

  9. CDOJ 842 天下归晋 树状数组

    天下归晋 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/842 Descrip ...

随机推荐

  1. 使用AI算法进行手写数字识别

    人工智能   人工智能(Artificial Intelligence,简称AI)一词最初是在1956年Dartmouth学会上提出的,从那以后,研究者们发展了众多理论和原理,人工智能的概念也随之扩展 ...

  2. mysql 8.x 登陆提示 Access denied for user 'root'@'localhost' (using password: YES)

    第一步:修改 /etc/mysql/my.cnf. 在[mysql]下添加skip-grant-table:重启. 第二步:通过mysql命令登陆: flush privileges; use mys ...

  3. shell、bash、terminal和kernel之间的关系

    shell.bash.terminal和kernel之间的关系 本文是<鸟哥的Linux私房菜>的学习笔记 什么是kernel kernel的中文是"操作系统核心",主 ...

  4. Ubuntu12.04+Caffe (+OpenCV+CPU-only)

    经过一天的努力发现12.04 的pcre的库太低了,   要解决这个bug只能升级系统到16.04   麻蛋!!! 1.  下载大神MTCNN 源码,内含caffe https://github.co ...

  5. ubuntu18.3完美安装qq

    创建一个脚本全自动安装 #!/bin/bash # 安装 deepin-wine sudo mkdir deepin-wine deepin-qq cd deepin-wine git clone h ...

  6. API工具下载地址记录一下

    java 1.6 帮助文档中文链接:http://download.csdn.net/detail/qw599186875/9608735 中文 – 谷歌版在线版: https://blog.fond ...

  7. Java学习笔记【七、时间、日期、数字】

    参考:http://www.runoob.com/java/java-date-time.html Date类 构造: Date() 使用当前的日期时间 Date(long millisec) 197 ...

  8. 使用js打印时去除页眉页脚

    写在前面 今天的开发遇到了使用window.print()功能进行当前页面打印的功能,因为页脚左边部分显示了url,这是不能存在的,已解决,写在这里. 正文 很多网上的方法都是不能用的,最后我找到一个 ...

  9. 【TCP】拥塞控制

    TCP拥塞控制 出现拥塞           ∑对资源的需求 > ∑可用资源 拥塞控制是防止过多的数据注入到网络中,使网络中的路由器或链路不过载,这是一个全局性的. 流量控制是点对点的通信量的控 ...

  10. SCU 4584 tarjan+最大权闭合子图

    把每个点的点权当做是W[i]-V[i] 题目一眼是最大权闭合子图 但是可能会有重边自环和环 需要先搞成简单图 再tarjan缩点 缩点后就是裸的最大权闭合子图 #include<bits/std ...