OUC_Summer Training_ DIV2_#9 719

其实自己只会做很简单的题,有时都不想写解题报告,觉得不值得一写,但是又想到今后也许就不会做ACM了,能留下来的东西只有解题报告了,所以要好好写,很渣的题也要写,是今后的纪念。

B - B
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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 Input

Input
2230
Output
2230
Input
-10
Output
0
Input
-100003
Output
-10000

 输入一个整数(可正可负)可以改变最后一位数或者倒数第二个数,使这个数最大。

 1 #include<stdio.h>
 2 int main()
 3 {
 4     int acc;
 5     int new1,new2;
 6     scanf("%d",&acc);
 7     if(acc >= 0)printf("%d",acc);
 8     else
 9     {
10         new1 = acc/10;
11         new2 = new1/10 * 10+(acc - new1 * 10);
12         if(new1 > new2)printf("%d",new1);
13         else printf("%d",new2);
14     }
15     return 0;
16 }
View Code
C - C
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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 < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), thatsi = 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 < ri ≤ n).

Output

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

Sample Input

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

 

 有一个由#.组成的字符串输入一对数a,b输出在字符串中从a到b连续相同的字符个数。不过这个题一个值得注意的地方是字符串存入的时候就要找出到目前为止的结果,这样读入数据的时候直接输出就行,不然会超时。
 1 #include<stdio.h>
 2 #include<string.h>
 3 char a[100010];
 4 int b[100010];
 5 int main()
 6 {
 7 
 8     int n,x,y,i,j,len;
 9     scanf("%s",a);
10     len = strlen(a);
11     for(i = 1;i < len;i++)
12     {
13         if(a[i-1]== a[i])
14         b[i] = b[i - 1]+1;
15         else
16             b[i] = b[i - 1];
17     }
18     scanf("%d",&n);
19     while(n--)
20     {
21         scanf("%d%d",&x,&y);
22         printf("%d\n",b[y-1] - b[x-1] );
23     }
24     return 0;
25 }
View Code
D - D
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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 %I64dspecifier.

Sample Input

Input
1
13
Output
13
Input
4
1 2 3 4
Output14
有4的n次方个数排成一个矩阵,求所有最美的数的和,可以对矩阵进行重新排列,使得最美的数的和最大。找出最美的数的规则是把矩阵分成四个2的n次方的矩阵,如果n==0最美的数就是他自己,否则是小矩阵中最大的数。没有用longlong,wa了几次。做法是:既然要找最大的和就把大的数分配给每个小矩阵,这样和就等于所有的和再加上后n=n/4个数的和,一直加到n==1.

 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 long long int a[2000001];
 5 long long int sum = 0;
 6 int main()
 7 {
 8     
 9     int N,n,i,j,k,m = 0;
10     cin >> N;
11     n = N;
12     while(n != 1)
13     {
14         n = n/4;
15         m++;
16     }
17     for(i = 0;i < N;i++)
18     {
19         cin >> a[i];
20         sum += a[i];
21     }
22     sort(a,a+N);
23     for(i = N/4;i >= 1;i= i/4)
24     {
25         for(j = N-1;j >= N-1-i+1;j--)
26             sum += a[j];
27     }
28     cout << sum;
29     return 0;
30         
31 }
View Code

A - A
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

median in an array with the length of n is an element which occupies position number  after we sort the elements in the non-decreasing order (the array elements are numbered starting with 1). A median of an array (2, 6, 1, 2, 3) is the number 2, and a median of array (0, 96, 17, 23) — the number 17.

We define an expression  as the integer part of dividing number a by number b.

One day Vasya showed Petya an array consisting of n integers and suggested finding the array's median. Petya didn't even look at the array and said that it equals x. Petya is a very honest boy, so he decided to add several numbers to the given array so that the median of the resulting array would be equal to x.

Petya can add any integers from 1 to 105 to the array, including the same numbers. Of course, he can add nothing to the array. If a number is added multiple times, then we should consider it the number of times it occurs. It is not allowed to delete of change initial numbers of the array.

While Petya is busy distracting Vasya, your task is to find the minimum number of elements he will need.

Input

The first input line contains two space-separated integers n and x (1 ≤ n ≤ 5001 ≤ x ≤ 105) — the initial array's length and the required median's value. The second line contains n space-separated numbers — the initial array. The elements of the array are integers from 1 to 105. The array elements are not necessarily different.

Output

Print the only integer — the minimum number of elements Petya needs to add to the array so that its median equals x.

Sample Input

Input
3 10
10 20 30
Output
1
Input
3 4
1 2 3
Output
4

Hint

In the first sample we can add number 9 to array (10, 20, 30). The resulting array (9, 10, 20, 30) will have a median in position , that is, 10.

In the second sample you should add numbers 4555. The resulting array has median equal to 4.

有一个数组(任意顺序要从小到大排序)和一个数,改变这个数组,要使这个数处于数组中间位置,输出改变的次数。

交了不对,也把代码贴上,再贴几个大神的代码。

 1 #include<iostream>
 2 #include<algorithm>
 3 using namespace std;
 4 int main()
 5 {
 6     int a[51] = {-1};
 7     int n,i,j,m,num = 0,x,y;
 8     cin >> n >> m;
 9     for(i = 1;i <= n;i++)
10     {
11         cin >> a[i];
12     }
13     sort(a,a+n);
14     for(i = 1;i <= n;i++)
15     {
16         if(a[i] <= m)
17         {
18             if(a[i] == m && i == (n+1)/2)
19             {
20                 cout << 0<< endl;
21                 return 0;
22             }
23             else continue;
24         }
25         else break;
26     }
27     x = i - 1;
28     y = n - i + 1;
29     num = (x < y)? y - x:x - y;
30     if((n + num)/2 == i)
31     cout << num ;
32     else cout << num+1;
33     return 0;
34 }
View Code
 
 大神的
 1 #include<stdio.h>
 2 int data[505];
 3 
 4 int d(double x);
 5 
 6 int main(void)
 7 {
 8     int n,x;
 9     while(scanf("%d%d",&n,&x)!=-1)
10     {
11         int bigger=0;
12         int smaller=0;
13         int counter=0;
14         for(int i=0;i<n;i++)
15         {
16             scanf("%d",&data[i]);
17             if(data[i]>x)
18             {
19                 bigger++;
20             }
21             if(data[i]<x)
22             {
23                 smaller++;
24             }
25             if(data[i]==x)
26             {
27                 counter++;
28             }
29         }
30         if(smaller<d(n)&&smaller+counter>=d(n))
31         {
32             printf("0\n");
33         }
34         else if(smaller<counter+bigger)
35         {
36             printf("%d\n",bigger-smaller-counter);
37         }
38         else
39         {
40             printf("%d\n",smaller-bigger+1-counter);
41         }
42         //printf("bigger: %d, smaller: %d, counter: %d, \n",bigger,smaller,counter);
43     }
44     return 0;
45 }
46 
47 int d(double x)
48 {
49     return (int)(x+1)*1.0/2.0;
50 }
View Code

 




 
 
posted @ 2013-07-20 23:27  lwy_kitty  阅读(321)  评论(0编辑  收藏  举报