zoukankan      html  css  js  c++  java
  • UESTC1269 (数组优化)

    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
    ");
                else if(tem==0) printf("Next time
    ");
                else printf("I agree
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    sqlserver---基本函数
    sql server---外键
    数据关系模式设计的标准化
    二进制补码,原码,反码和移码
    ES6优雅的异步操作Promise()
    Vue封装公共组件TarBar
    Vue-Cli4.x配置文件路径别名
    Vue中解决新脚手架3创建项目的移动端双击屏幕放大,双手拉动放大的方法
    02.vue-router的进阶使用
    Vue路由-详细总结
  • 原文地址:https://www.cnblogs.com/soTired/p/5136501.html
Copyright © 2011-2022 走看看