UESTC 1269 ZhangYu Speech 预处理、前缀和
来源:互联网 发布:江门美工家具定制 编辑:程序博客网 时间:2024/06/07 09:28
ZhangYu Speech
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
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
for each query:
- ZhangYu brother choose an index
x from1 ton . - For all indices
y (y <x ) calculate the differenceby=ax−ay . - Then ZhangYu brother calculate
B1 ,the sum of all by which are greater than0 , and scfkcf calculateB2 , the sum of all by which are - less than
0 .
if
the result; else if
Input
The first line contains two integers
contains
index for current query.
Output
For each of
print "I agree" if ZhangYu brother lost in a line - answer of the query.
Sample input and output
10 30324152397147
Next timeKeep some distance from meI agree
Hint
It's better to use "scanf" instead of "cin" in your code.
Source
My Solution
#include <iostream>#include <cstdio>//#define LOCALconst int maxn=100008;char ch[maxn];int line[maxn],sum[maxn];using namespace std;int main(){ #ifdef LOCAL freopen("a.txt","r",stdin); #endif // LOCAL int n,m,x,t; scanf("%d%d",&n,&m); scanf("%s",ch); //直接先转化过来,这样扫一遍就好了。不然要好多边临时的转化 for(int i=0;i<n;i++){ line[i]=ch[i]-'0'; } //直接预处理出前i项和 前缀和 t=0; for(int i=0;i<n;i++){ t+=line[i]; sum[i]=t; } //每次询问直接用sum[x-1]; while(m--){ scanf("%d",&x); //x1=ch[x-1]-'0';//cout<<x1<<" "; if(sum[x-1]-line[x-1]*(x)<0) printf("Keep some distance from me"); else if(sum[x-1]-line[x-1]*(x)>0) printf("I agree"); else if(sum[x-1]-line[x-1]*(x)==0)printf("Next time"); if(m) printf("\n"); } return 0;}
谢谢
- UESTC 1269 ZhangYu Speech 预处理、前缀和
- UESTC 1269 ZhangYu Speech (预处理)
- UESTC 1269-ZhangYu Speech
- UESTC 1269 ZhangYu Speech
- UESTC - 1269:ZhangYu Speech【思维】
- UESTC--1269--ZhangYu Speech(模拟)
- UESTC ZhangYu Speech 1269 (模拟&技巧转换)
- CDOJ 1269 ZhangYu Speech 数组处理
- UESTC 1299 Date 预处理、打表、找周期、前缀和
- C - ZhangYu Speech (水题)
- UESTC 1256 昊昊喜欢运动 n^2的预处理 or 前缀和
- The 14th UESTC Programming Contest Final B - Banana Watch 预处理、前缀和
- 预处理之前缀和
- hdu 5084 前缀和预处理
- UESTC 929 Post office【前缀和+贪心】
- zhangyu
- HDU 2089 不要62 预处理+前缀和
- C. Star sky【前缀和预处理】
- 安卓中对数据库的操作(增删改查)
- 【杭电】[2054]A==B
- 杭电2546 饭卡 (变形0-1背包)
- Android开发之第一个小项目--我的MP3播放器之主界面的实现(二)
- 【杭电】[2029]Palindromes _easy version
- UESTC 1269 ZhangYu Speech 预处理、前缀和
- android-Wi-Fi Peer-to-Peer
- git命令
- NFV SDN
- 关闭应用程序
- c#知识点整理
- UITableViewCell中如何添加图片数组
- autolayout的使用
- AJAX POST&跨域 解决方案 - CORS