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;
}
 

转载于:https://www.cnblogs.com/CKboss/archive/2013/05/31/3351048.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值