标签:puts bbb das ace sum using therefore compute his
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn‘t want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he‘s got.
Can you help him?
Input
The single line of the input contains two positive integers a and b (1 ≤ a, b ≤ 100) — the number of red and blue socks that Vasya‘s got.
Output
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he‘s got.
Keep in mind that at the end of the day Vasya throws away the socks that he‘s been wearing on that day.
Examples
input
3 1
output
1 1
input
2 3
output
2 0
input
7 3
output
3 2
Note
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
Code:
1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int r , b; 6 scanf("%d%d" , &r , &b); 7 int tr = min(r , b); 8 int al = max(r - tr , b - tr) / 2; 9 printf("%d %d" , tr , al); 10 }
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row.
Let‘s enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all the houses with larger numbers. In other words, a house is luxurious if the number of floors in it is strictly greater than in all the houses, which are located to the right from it. In this task it is assumed that the heights of floors in the houses are the same.
The new architect is interested in n questions, i-th of them is about the following: "how many floors should be added to the i-th house to make it luxurious?" (for all i from 1 to n, inclusive). You need to help him cope with this task.
Note that all these questions are independent from each other — the answer to the question for house i does not affect other answers (i.e., the floors to the houses are not actually added).
Input
The first line of the input contains a single number n (1 ≤ n ≤ 105) — the number of houses in the capital of Berland.
The second line contains n space-separated positive integers h**i (1 ≤ h**i ≤ 109), where h**i equals the number of floors in the i-th house.
Output
Print n integers a1, a2, ..., a**n, where number a**i is the number of floors that need to be added to the house number i to make it luxurious. If the house is already luxurious and nothing needs to be added to it, then a**i should be equal to zero.
All houses are numbered from left to right, starting from one.
Examples
input
5 1 2 3 1 2
output
3 2 0 2 0
input
4 3 2 1 4
output
2 3 4 0
Code:
1 #include <bits/stdc++.h> 2 using namespace std; 3 static const int MAXN = 1e5 + 10; 4 int n; 5 int data[MAXN]; 6 int tail[MAXN]; 7 int main() 8 { 9 scanf("%d" , &n); 10 for(int i = 1 ; i <= n ; ++i) 11 { 12 scanf("%d" , data + i); 13 } 14 for(int i = n ; i > 0 ; --i) 15 { 16 tail[i] = max(tail[i + 1] , data[i + 1]); 17 } 18 for(int i = 1 ; i <= n ; ++i) 19 { 20 printf("%d " , max(tail[i] + 1 - data[i] , 0)); 21 } 22 }
Petya loves computer games. Finally a game that he‘s been waiting for so long came out!
The main character of this game has n different skills, each of which is characterized by an integer a**i from 0 to 100. The higher the number a**i is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values of for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya‘s character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero‘s skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.
Input
The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya‘s disposal.
The second line of the input contains a sequence of n integers a**i (0 ≤ a**i ≤ 100), where a**i characterizes the level of the i-th skill of the character.
Output
The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units.
Examples
input
2 4 7 9
output
2
input
3 8 17 15 19
output
5
input
2 2 99 100
output
20
Note
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is .
In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to .
Code:
1 #include <bits/stdc++.h> 2 using namespace std; 3 static const int MAXN = 1e5 + 10; 4 int n , k; 5 int ans; 6 int data[MAXN]; 7 int has[MAXN]; 8 int main() 9 { 10 scanf("%d%d" , &n , &k); 11 for(int i = 1 ; i <= n ; ++i) 12 { 13 scanf("%d" , &data[i]); 14 ++has[data[i] % 10]; 15 ans += data[i] / 10; 16 } 17 for(int i = 1 ; i < 10 ; ++i) 18 { 19 int s = min(has[10 - i] , k / i); 20 k -= i * s; 21 ans += s; 22 if(s != has[10 - i]) 23 break; 24 } 25 ans += min(10 * n - ans , k / 10); 26 printf("%d" , ans); 27 }
Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area.
Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no empty space left. When you put a logo on the billboard, you should rotate it so that the sides were parallel to the sides of the billboard.
Your task is to determine if it is possible to put the logos of all the three companies on some square billboard without breaking any of the described rules.
Input
The first line of the input contains six positive integers x1, y1, x2, y2, x3, y3 (1 ≤ x1, y1, x2, y2, x3, y3 ≤ 100), where x**i and y**i determine the length and width of the logo of the i-th company respectively.
Output
If it is impossible to place all the three logos on a square shield, print a single integer "-1" (without the quotes).
If it is possible, print in the first line the length of a side of square n, where you can place all the three logos. Each of the next n lines should contain n uppercase English letters "A", "B" or "C". The sets of the same letters should form solid rectangles, provided that:
the sizes of the rectangle composed from letters "A" should be equal to the sizes of the logo of the first company,
the sizes of the rectangle composed from letters "B" should be equal to the sizes of the logo of the second company,
the sizes of the rectangle composed from letters "C" should be equal to the sizes of the logo of the third company,
Note that the logos of the companies can be rotated for printing on the billboard. The billboard mustn‘t have any empty space. If a square billboard can be filled with the logos in multiple ways, you are allowed to print any of them.
See the samples to better understand the statement.
Examples
input
5 1 2 5 5 2
output
5 AAAAA BBBBB BBBBB CCCCC CCCCC
input
4 4 2 6 4 2
output
6 BBBBBB BBBBBB AAAACC AAAACC AAAACC AAAACC
Code:
1 #include <bits/stdc++.h> 2 3 #define eps 1e-5 4 #define inf 0x3f3f3f3f 5 #define max(a,b) ((a)>(b)?(a):(b)) 6 #define min(a,b) ((a)<(b)?(a):(b)) 7 #define lson l,m,rt<<1 8 #define rson m+1,r,rt<<1 | 1 9 #define lc rt<<1 10 #define rc rt<<1 | 1 11 #define getx2(a) ((a)*(a)) 12 #define Pi acos(-1.0) 13 14 typedef long long LL; 15 using namespace std; 16 int main() 17 { 18 int p[3][2]; 19 char c[3]= {‘A‘,‘B‘,‘C‘}; 20 scanf("%d%d%d%d%d%d",&p[0][0],&p[0][1],&p[1][0],&p[1][1],&p[2][0],&p[2][1]); 21 if(p[0][0]<p[0][1])swap(p[0][0],p[0][1]); 22 if(p[1][0]<p[1][1])swap(p[1][0],p[1][1]); 23 if(p[2][0]<p[2][1])swap(p[2][0],p[2][1]); 24 int sum=0; 25 for(int i=0; i<3; i++) 26 { 27 sum+=p[i][0]*p[i][1]; 28 } 29 int n=sqrt(sum); 30 if(sum!=n*n) 31 { 32 printf("-1\n"); 33 return 0; 34 } 35 if(p[0][0]==p[1][0]&&p[1][0]==p[2][0]&&(p[0][0]==n&&p[0][1]+p[1][1]+p[2][1]==n))///情况1 36 { 37 printf("%d\n",n); 38 for(int k=0; k<3; k++) 39 for(int i=0; i<p[k][1]; i++) 40 { 41 for(int j=0; j<p[k][0]; j++) 42 printf("%c",c[k]); 43 printf("\n"); 44 } 45 } 46 else 47 {///枚举情况2 48 for(int r=0; r<3; r++) 49 { 50 for(int cc=0; cc<3; cc++) 51 { 52 if(r!=cc) 53 { 54 for(int i=0; i<2; i++) 55 { 56 for(int j=0; j<2; j++) 57 { 58 int kk; 59 if((r==0&&cc==1)||(r==1&&cc==0))kk=2; 60 if((r==1&&cc==2)||(r==2&&cc==1))kk=0; 61 if((r==2&&cc==0)||(r==0&&cc==2))kk=1; 62 if(p[r][i]+p[cc][j]==n&&p[r][(i+1)%2]+p[kk][1]==n&&p[kk][0]==n)//找到方案 63 { 64 printf("%d\n",n);///输出 65 for(int rr=0; rr<p[r][(i+1)%2]; rr++) 66 { 67 for(int ccc=0; ccc<p[r][i]; ccc++)printf("%c",c[r]); 68 for(int ccc=0; ccc<p[cc][j]; ccc++)printf("%c",c[cc]); 69 printf("\n"); 70 } 71 for(int rr=0; rr<p[kk][1]; rr++) 72 { 73 for(int ccc=0; ccc<p[kk][0]; ccc++) 74 printf("%c",c[kk]); 75 printf("\n"); 76 } 77 return 0; 78 } 79 80 } 81 } 82 } 83 } 84 }//找不到方案输出-1 85 printf("-1\n"); 86 } 87 return 0; 88 }
2017-5-7-Train: Codeforces Round #322 (Div. 2)
标签:puts bbb das ace sum using therefore compute his
原文地址:http://www.cnblogs.com/jianglingxin/p/6820221.html