zoukankan      html  css  js  c++  java
  • CodeForces #186(div.2) A B C

    40分钟做完A,B然后把C 题看错,一直WA到结束。。。。。。。。

    A水题。
    A. Ilya and Bank Account
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money.

    Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance.

    Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.

    Input

    The single line contains integer n (10≤|n|≤109) — the state of Ilya's bank account.

    Output

    In a single line print an integer — the maximum state of the bank account that Ilya can get.

    Sample test(s)
    input
    2230
    output
    2230
    input
    -10
    output
    0
    input
    -100003
    output
    -10000
    Note

    In the first test sample Ilya doesn't profit from using the present.

    In the second test sample you can delete digit 1 and get the state of the account equal to 0.


    #include <iostream>

    using namespace std;

    int main()
    {
        int a;
        int b1,b2,t;
        cin>>a;
        b1=a/10;
        b2=(a/100)*10+a%10;
        t=max(max(b1,b2),a);

        cout<<t;

        return 0;
    }

    为了防超时用了树状数组,
    其实什么都不用都能AC  
    B. Ilya and Queries
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.

    You've got string s=s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li,ri (1≤li<rin). The answer to the query li,ri is the number of such integers i (lii<ri), that si=si+1.

    Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.

    Input

    The first line contains string s of length n (2≤n≤105). It is guaranteed that the given string only consists of characters "." and "#".

    The next line contains integer m (1≤m≤105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li,ri (1≤li<rin).

    Output

    Print m integers — the answers to the queries in the order in which they are given in the input.

    Sample test(s)
    input
    ......
    4
    3 4
    2 3
    1 6
    2 6
    output
    1
    1
    5
    4
    input
    #..###
    5
    1 3
    5 6
    1 5
    3 6
    3 4
    output
    1
    1
    2
    2
    0


      #include <iostream>
    #include <cstring>
    #include <string>

    using namespace std;

    int n;
    int tree[100010];
    int a[100010];

    int lowbit(int x)
    {
        return x&(-x);
    }

    void update(int pos,int val)
    {
        while(pos<=n)
        {
            tree[pos]+=val;
            pos+=lowbit(pos);
        }
    }

    int query(int x)
    {
        int sum=0;
        while(x>0)
        {
            sum+=tree[x];
            x-=lowbit(x);
        }

        return sum;
    }

    int main()
    {
        string s;
        cin>>s;
        int len=s.length();
        memset(tree,0,sizeof(tree));
        for(int i=0;i<len-1;i++)
        {
            if(s==s[i+1])
               a[i+1]=1;
        }

     //   for(int i=1;i<=len-1;i++)
     //   cout<<a<<" ";

        n=len-1;
    //    cout<<"jjjjjjjjjjjjj"<<endl;
        for(int i=1;i<=len-1;i++)
          update(i,a);
    //cout<<"jjjjjjjjjjjjj"<<endl;
        int m;
        cin>>m;
        while(m--)
        {
            int t,k;
            cin>>t>>k;
            cout<<query(k-1)-query(t-1)<<endl;
        }

        return 0;
    }

    看错题了
    C. Ilya and Matrix
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve.

    He's got a square 2n×2n-sized matrix and 4n integers. You need to arrange all these numbers in the matrix (put each number in a single individual cell) so that the beauty of the resulting matrix with numbers is maximum.

    The beauty of a 2n×2n-sized matrix is an integer, obtained by the following algorithm:

    1. Find the maximum element in the matrix. Let's denote it as m.
    2. If n=0, then the beauty of the matrix equals m. Otherwise, a matrix can be split into 4 non-intersecting 2n-1×2n-1-sized submatrices, then the beauty of the matrix equals the sum of number m and other four beauties of the described submatrices.

    As you can see, the algorithm is recursive.

    Help Ilya, solve the problem and print the resulting maximum beauty of the matrix.

    Input

    The first line contains integer 4n (1≤4n≤2·106). The next line contains 4n integers ai (1≤ai≤109) — the numbers you need to arrange in the 2n×2n-sized matrix.

    Output

    On a single line print the maximum value of the beauty of the described matrix.

    Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cincout streams or the%I64d specifier.

    Sample test(s)
    input
    1
    13
    output
    13
    input
    4
    1 2 3 4
    output
    14
    Note

    Consider the second sample. You need to arrange the numbers in the matrix as follows:


    1 2
    3 4

    Then the beauty of the matrix will equal: 4 + 1 + 2 + 3 + 4 = 14.



    #include <iostream>
    #include <algorithm>
    #include <cmath>

    using namespace std;
    int n;

    long long int a[2222222];

    int main()
    {
        long long ans=0;
        cin>>n;
        for(int i=0;i<n;i++)
        {
            cin>>a;
            ans+=a;
        }

        sort(a,a+n);

        for(int b=1;b<n;b*=4)
        {
            for(int i=n-b;i<n;i++)
              ans+=a;
        }

         cout<<ans;
        return 0;
    }
     
  • 相关阅读:
    AspNetCore打造一个“最安全”的api接口
    efcore分表分库原理解析
    对于经常接触的分页你确定你真的会吗
    Monitor的扩展支持string的超时锁
    Excel导出
    搭建私有Git服务器-GitLab
    C# 爬取网易Buff进行购买
    .Net Core 使用弹性和瞬态故障处理库Polly
    JS Table表格添加多选框
    JS 用户头像展示
  • 原文地址:https://www.cnblogs.com/CKboss/p/3351048.html
Copyright © 2011-2022 走看看