码迷,mamicode.com
首页 > 编程语言 > 详细

UESTC1269 (数组优化)

时间:2016-01-16 23:47:39      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:

Description

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 技术分享 digits(lets give them indices from 技术分享 to 技术分享 and name them 技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享) and some queries.

for each query:

  1. ZhangYu brother choose an index 技术分享 from 技术分享 to 技术分享.
  2. For all indices 技术分享 ( 技术分享 < 技术分享) calculate the difference 技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享.
  3. Then ZhangYu brother calculate 技术分享技术分享 ,the sum of all by which are greater than 技术分享 , and scfkcf calculate 技术分享技术分享 , the sum of all by which are less than 技术分享.

if 技术分享技术分享技术分享技术分享技术分享技术分享技术分享 , ZhangYu brother won and did not agree with scfkcf to contact him; 
else if 技术分享技术分享 is equals to 技术分享技术分享技术分享技术分享 , ZhangYu brother would ignore the result; 
else if 技术分享技术分享 < 技术分享技术分享技术分享技术分享 , ZhangYu brother lost and agreed with scfkcf to contact him.

Input

The first line contains two integers 技术分享技术分享 技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享 denoting the number of digits and number of queries. The second line contains 技术分享 digits (without spaces) 技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享.技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享 
Each of next 技术分享 lines contains single integer 技术分享 技术分享技术分享技术分享技术分享技术分享技术分享技术分享 denoting the index for current query.

Output

For each of 技术分享 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

10 3 
0324152397 


7

Sample Output

Next time 
Keep some distance from me 
I agree

Hint

It‘s better to use “scanf” instead of “cin” in your code.

分析题吧, 多用一个数组, 少一层循环

#include <cstdio>
const int N = 100001;
int a[N], b[N];
char c[N];
int main()
{
    int n, m;
    while(scanf("%d%d", &n, &m) != EOF)
    {
        b[0]=0;
        scanf("%s", c);
        for(int i = 1; i <= n; i++)
            a[i]=c[i-1]-0;
        for(int i = 1; i <= n; i++)
            b[i]=b[i-1]+c[i-1]-0;
        for(int i = 0; i < m; i++)
        {
            int d;
            scanf("%d", &d);
            int tem=(d-1)*a[d]-b[d-1];
            if(tem>0) printf("Keep some distance from me\n");
            else if(tem==0) printf("Next time\n");
            else printf("I agree\n");
        }
    }
    return 0;
}

UESTC1269 (数组优化)

标签:

原文地址:http://www.cnblogs.com/fengshun/p/5136501.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!