CDOJ 1269 ZhangYu Speech 数组处理
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 数组处理的更多相关文章
- CDOJ 1269 ZhangYu Speech
预处理打表,sum[i][j]表示1.....i这些数字中 j 有几个.然后就很好处理询问了. #include<stdio.h> #include<math.h> #incl ...
- [cdoj 1344]树状数组区间加等差数列
题目链接:http://acm.uestc.edu.cn/#/problem/show/1344 区间加等差数列本质上就是区间修改区间查询,本来想用线段树做,结果这个题就是卡空间和时间……不得已学了区 ...
- CDOJ 1256 打表+数组 统计
昊昊爱运动 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit St ...
- UESTC--1269--ZhangYu Speech(模拟)
ZhangYu Speech Time Limit: 1000MS Memory Limit: 65535KB 64bit IO Format: %lld & %llu Submit ...
- 第七届ACM趣味程序设计竞赛第四场(正式赛) 题解
Final Pan's prime numbers 题目连接: http://acm.uestc.edu.cn/#/problem/show/1272 题意 给你n,要求你在[4,n]范围内找到一个最 ...
- LeetCode Top 100 Liked 点赞最高的 100 道算法题
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:刷题顺序,刷题路径,好题,top100,怎么刷题,Leet ...
- CDOJ 838 母仪天下 树状数组 (2014数据结构专题
母仪天下 Time Limit: 1 Sec Memory Limit: 162 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/838 Descrip ...
- cdoj 841 休生伤杜景死惊开 逆序数/树状数组
休生伤杜景死惊开 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) 陆伯言军陷八卦 ...
- CDOJ 842 天下归晋 树状数组
天下归晋 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/842 Descrip ...
随机推荐
- Python基础『二』
目录 语句,表达式 赋值语句 打印语句 分支语句 循环语句 函数 函数的作用 函数的三要素 函数定义 DEF语句 RETURN语句 函数调用 作用域 闭包 递归函数 匿名函数 迭代 语句,表达式 赋值 ...
- 怎样理解 Vue 中的 v-if 和 v-show ?
1. v-if 实现了真正的 条件渲染, 条件为真时, 节点被创建, 相应的监听函数也会生效, 条件为假时, 节点被销毁, 触发事件监听函数不会生效. 而 v-show 只是使用了 display:n ...
- kafka运维填坑
转载自:https://www.jianshu.com/p/d2cbaae38014 前提: 只针对Kafka 0.9.0.1版本; 说是运维,其实偏重于问题解决; 大部分解决方案都是google而来 ...
- C#文本_文件夹操作
1我们常用的File类 可以用来对文件的一些操作 下面看代码. using System;using System.Collections.Generic;using System.IO;using ...
- windows server12 FTP 创建后常见问题
一:用administrator 关闭防火墙可以访问,但是开启后不能访问 今天在windows server 2008 R2上安装了FTP,安装过程如下,然后添加内置防火墙设置,设置后发现本地可以访问 ...
- mqtt协议实现 java服务端推送功能(一)安装
最近有个新需求,需要通过java服务端把信息推送到mqtt服务器上,安卓和ios端从mqtt服务器上获取信息实现推送. 1. 本地需要安装Mosquitto服务器 http://mosquitto. ...
- 微信小程序子传父
子组件 父组件
- latex公式居中环境
一般能够用到的环境是 \begin{equation} \begin{aligned} ... \end{aligned} \end{equation} 然而,这种环境用&只能够保证左对齐或者 ...
- Win7系统打开防火墙出现0x6D9错误的解决方法
防火墙是Windows系统内的一道屏障,开启防火墙可以对系统起到一定的保护作用,可以说非常重要.但是有些Win7系统用户在开启防火墙时会被系统提示出现0x6D9的错误代码,从而不能打开防火墙. 当我们 ...
- DHCP显示
两种PXE启动芯片 开机显示:Inter® Boot Agent GE V1.2.45或者Intel UNDI PXE2.0 (Build 082):其中UNDI是Universal Network ...