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. X86逆向14:常见的脱壳手法

    本章节内容将介绍软件的脱壳技术.什么是加壳?加壳就是用来压缩或者保护软件不被非法修改破解的一种工具,而脱壳就是将已经加壳的程序从壳中剥离出来,既然能给程序进行加壳,那也就会有相应的脱壳方法,本节课我们 ...

  2. 项目实践 hrm项目的设计过程

    人事管理系统的设计过程 一.数据库表和持久化类 1.1   进行需求分析,根据功能模块设计数据库表 1.2   设计持久化实体 面向对象分析,即根据系统需求提取出应用中的对象,将这些对象抽象成类,再抽 ...

  3. MySQL中的DML、DQL和子查询

    一.MySQL中的DML语句 1.使用insert插入数据记录: INSERT INTO `myschool`.`student` (`studentNo`, `loginPwd`, `student ...

  4. 怎样在 Vue 中使用 v-model 实现双向数据绑定?

    1. 所谓 双向数据绑定, 可以理解为: 修改 A , B 会跟着被修改, 修改 B , A 会跟着被修改. 常用在需要 进行用户输入的地方, 比如 这些 html 标签:  input.select ...

  5. winfrom_根据checkbox勾选项增减dgv字段列

    1.效果: 2.点击‘配置’按钮: private void btn_configure_Click(object sender, EventArgs e) { string sum = string ...

  6. WPF 遍历资源字典中的控件

    object obItem=this.FindResource("canvasdt"); if (obItem is System.Windows.DataTemplate) { ...

  7. centos7安装nginx服务

    Nginx发音引擎x是一个免费的开源高性能HTTP和反向代理服务器,负责处理互联网上一些最大的网站的负载. 本教程将教你如何在你的CentOS Linux 7.5机器上安装和管理Nginx. 安装Ng ...

  8. jvm之java类加载机制和类加载器(ClassLoader),方法区结构,堆中实例对象结构的详解

    一.类加载或类初始化:当程序主动使用某个类时,如果该类还未被加载到内存中,则JVM会通过加载.连接.初始化3个步骤来对该类进行初始化.如果没有意外,JVM将会连续完成3个步骤. 二.类加载时机:  1 ...

  9. MYSQL 创建数据库以及表

    创建数据库,表 创建一个数据库,再在数据库下创建一个或多个表,不难,记不住的同学可以直接copy,慢慢的用会即刻,懂的同学请看代码,没有太多基础的同学,除了看代码,请看最下方的知识点 创建数据库: C ...

  10. Delphi10.2.3利用THttpClient实现http异步下载

    随着Delphi 10.2.3的发布,随之带来更稳定.更完善的版本.今天借官方的例子,解读一下如何实现Http异步下载并显示下载进度. 使用的核心组件是THttpClient,首先建立一个THttpC ...