A. Vasya the hipster time limit per test 1 second memory limit per test megabytes input standard input output standard Output
One day Vasya the hipster decided to count how many socks he had. It turned out that he hada red socks and B blue socks.
According to the latest fashion, hipsters should wear the socks of different colors:a red one in the left foot, a blue on E on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before the going to bed as he doesn ' t want to wash them.
Vasya wonders, what's the maximum number of days if he can dress fashionable and wear different socks, and after that, For what 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 the positive integers a and B (1≤a, b≤100)-the number of red and blue socks th At Vasya ' s got. Output
Print space-separated integers-the Maximum number of days if 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 so at the end of the day Vasya throws away the socks so he ' s been wearing on that day. Sample Test (s) 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 had both red socks left to wear on th e second day.
Water Problem Code:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <math.h>
#include <map>
#include <stdlib.h>
#include <algorithm>
#define EPS 1e-5
# Define INF 0x3f3f3f3f
#define MAX (a) > (b)? ( A):(B)
#define MIN ( a) < (b) ( A):(B))
#define Lson l,m,rt<<1
#define Rson m+1,r,rt<<1 | 1
#define LC rt<<1
# Define RC Rt<<1 | 1
#define GETX2 (a) ((a) * (a))
#define Pi ACOs ( -1.0)
typedef long long LL;
using namespace std;
int main ()
{
int a A, B;
scanf ("%d%d", &a,&b);
printf ("%d%d\n", Min (A, b), (max (b)-min (b))/2);
return 0;
}
B. Luxurious houses time limit per test 1 second memory limit per test megabytes input standard input output standard Output
The capital of Berland has n multifloor buildings. The architect who built is 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 was considered to beluxurious if the number of floors in it was strictly greater than in all the houses with larger Numbers. In other words, a house was luxurious if the number of floors in it was strictly greater than in all the houses, which was L Ocated to the right from it. In this task it was assumed that the heights of floors in the houses was the same.
The new architect is interested in n questions,i-th of them are about the following: ' How many floors should being added to th Ei-th House to make it luxurious? " (for Alli from 1 to N, inclusive). You need to help him cope with the this task.
Note that all these questions is independent from each other-the answer to the question in Housei does not affect othe R answers (i.e., the floors to the houses is 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 Integershi (1≤hi≤109), Wherehi equals the number of floors in thei -th House. Output
Print n integers a1, a2, ..., an, where Numberai are the number of floors that need to being added to the house Numberi to Mak e it luxurious. If The house was already luxurious and nothing needs to being added to it, Thenai should was equal to zero.
All houses is numbered from left to right, starting from one. Sample Test (s) Input
5
1 2 3 1 2
Output
Input
4
3 2) 1 4
Output
Water problem: note as negative when directly changed to 0
Code:
#include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <queue > #include <stack> #include <vector> #include <math.h> #include <map> #include <stdlib.h&
Gt #include <algorithm> #define EPS 1e-5 #define INF 0x3f3f3f3f #define MAX (a) (a) > (b)? ( A):(b) #define MIN (a) < (b) ( A):(B)) #define Lson l,m,rt<<1 #define Rson m+1,r,rt<<1 | 1 #define LC rt<<1 #define RC Rt<<1 |
1 #define GETX2 (a) ((a) * (a)) #define Pi ACOs ( -1.0) #define N 100010 typedef long Long LL;
using namespace Std;
int a[n];
int b[n];
int main () {int n;
scanf ("%d", &n);
memset (A,0,sizeof (a));
Memset (b,0,sizeof (b));
for (int i=0; i<n; i++) {scanf ("%d", &a[i]);
} int max1=a[n-1];
for (int i=n-2; i>=0; i--) {b[i]=max1-a[i]+1;
if (b[i]<0) b[i]=0;//negative value is changed directly to 0 if (Max1<a[i]) {max1=a[i];
} } for (int i=0; i<n-1; i++) printf ("%d", b[i]);
printf ("%d\n", b[n-1]);
return 0; }
C. Developing Skills time limit per test 1 second memory limit per test megabytes input standard input output standard Output
Petya loves computer games. Finally a game that he's been waiting for so long came out!
The main character of this game have n different skills, each of the which are characterized by a integerai from 0 to 100. The higher the Numberai is, and the higher is thei-th skill of the character. The total rating of the character is calculated as the sum of the values of a for Alli from 1 to N. The expression⌊x⌋denotes the result of rounding the Numberx down to the nearest integer.
At the beginning of the game Petya got K improvement units as a bonus so he can use for increase the skills of his Charac ter and his total rating. One improvement unit can increase any skill of the Petya ' s character by exactly one. For example, if A4 = $, after using one imporvement the unit to this skill, it becomes equal to 47. A hero ' s skill cannot rise higher more than 100. Thus, it's permissible that some of the units would remain unused.
Your task is to determine the optimal, the using the improvement units so as to maximize the overall rating of the Chara Cter. It is not a necessary to use all the improvement units. Input
The first line of the input contains, 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 Integersai (0≤ai≤100), Whereai characterizes the level of thei-t H 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 usingk or less improvement units. Sample Test (s) 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 have to improve the first skill to the spending 3 improvement units, and the second skill to ten, by spending one IM Provement Unit. Thus, Petya spends all he improvement units and the total rating of the character becomes equal to Lfloor FRAC{100}{10}RF Loor + Lfloor frac{100}{10} rfloor = 10 + 10 = 20.
In the second Test, the optimal strategy for Petya are to improve the first skill to (by spending 3 improvement units) an D to improve the third skill to 1 improvement units). Thus, Petya is left with 4 improvement units and he'll be able to increase the second skill to + (which does not change The overall rating, so Petya does not necessarily has to do it). Therefore, the highest possible total rating in this example is.
In the third test case the optimal strategy for Petya are to increase the first skill to the spending 1 improvement unit . Thereafter, both skills of the character would be equal to, so Petya would not be able to spend the remaining improvemen T unit. So the answer are equal to. Test instructions: Given n skills, the score for each skill is A[I]/10, and a[i] cannot exceed 100, you can spend a K skill enhancement point to enhance the skill K point, the maximum value of the last skill;
Code:
#include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <queue > #include <stack> #include <vector> #include <math.h> #include <map> #include <stdlib.h&
Gt #include <algorithm> #define EPS 1e-5 #define INF 0x3f3f3f3f #define MAX (a) (a) > (b)? ( A):(b) #define MIN (a) < (b) ( A):(B)) #define Lson l,m,rt<<1 #define Rson m+1,r,rt<<1 | 1 #define LC rt<<1 #define RC Rt<<1 |
1 #define GETX2 (a) ((a) * (a)) #define Pi ACOs ( -1.0) #define N 100010 typedef long Long LL;
using namespace Std;
int a[n];
int b[n];
int cmp (const void *a,const void *b) {return * (int *) a-* (int *) b;} int main () {int n,k;
scanf ("%d%d", &n,&k);
int ans=0;
int min1=inf;
for (int i=0; i<n; i++) {scanf ("%d", &a[i]);
ANS+=A[I]/10;
b[i]= (10-a[i]%10)%10;///Note here, the range of b[i] can only be 0-9, so to 10 to take more if (MIN1>A[I]/10) MIN1=A[I]/10; } qSort (b,n,sizeof (b[0]), CMP);////////Difference value (difference from the whole point) int sum=0;
for (int i=0; i<n; i++) {if (K>=b[i]&&b[i])///{ans++;
K-=b[i];
A[i]+=b[i];
} sum+= (100-a[i]);
} if (k>sum) {ANS+=SUM/10;
} else {ANS+=K/10;
} printf ("%d\n", ans);
return 0; }
D. Three Logos time limit per test 1 second memory limit per test megabytes input standard input output standard OUTPU T
Three companies decided to order a billboard with pictures of their logos. A billboard is a Bigsquare board. A logo of each company are a rectangle of a non-zero area.
Advertisers'll put up the ad only if it's possible to place all three logos on the billboard so that they does not overla P and the Billboard have no empty space left. When you put a logo on the Billboard, you should rotate it so, the sides were parallel to the sides of the billboard.
Your task is to determine if it's possible to put the logos of the three companies on some square billboard without B Reaking 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), wher E XI Andyi determine the length and width of the logo of thei-th company respectively. Output
If It is impossible to place all the three logos in 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 中文版 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 is equal to the sizes of the logo of the first company, the sizes of the rectangle composed from letters "B" s Hould is equal to the sizes of the logo of the second company, the sizes of the rectangle composed from letters "C" should Being equal to the sizes of the logo of the third company,
Note that the logos of the companies can is rotated for printing on the billboard. The Billboard Mustn ' t has any empty space. If a square billboard can be filled with the logos in multiple ways, you is allowed to print any of the them.
See the samples to better understand the statement. Sample Test (s) 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
Test instructions: Give three company logo of the width of the rectangle, ask whether to form a square, if possible, the output edge length, and any one piece of patchwork scheme, otherwise output-1;
First look at the area is not the square number, if not the square number then absolutely cannot be pieced together the square direct output-1,;
If the square number, then to find a flat scheme;
There are only two cases of patchwork scenarios:
Scenario 1:
Scenario 2:
For the situation a direct output is good, for case two, the loop to find the condition of the output;
Code:
#include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <queue > #include <stack> #include <vector> #include <math.h> #include <map> #include <stdlib.h&
Gt #include <algorithm> #define EPS 1e-5 #define INF 0x3f3f3f3f #define MAX (a) (a) > (b)? ( A):(b) #define MIN (a) < (b) ( A):(B)) #define Lson l,m,rt<<1 #define Rson m+1,r,rt<<1 | 1 #define LC rt<<1 #define RC Rt<<1 |
1 #define GETX2 (a) ((a) * (a)) #define Pi ACOs ( -1.0) typedef long Long LL;
using namespace Std;
int main () {int p[3][2];
Char c[3]= {' A ', ' B ', ' C '};
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]);
if (p[0][0]<p[0][1]) swap (p[0][0],p[0][1]);
if (p[1][0]<p[1][1]) swap (p[1][0],p[1][1]);
if (p[2][0]<p[2][1]) swap (p[2][0],p[2][1]);
int sum=0;
for (int i=0; i<3; i++) {sum+=p[i][0]*p[i][1]; } inT n=sqrt (sum);
if (sum!=n*n) {printf (" -1\n");
return 0; } 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))///
Condition 1 {printf ("%d\n", N); for (int k=0, k<3; k++) for (int. i=0; i<p[k][1]; i++) {for (int j=0; J<p[k] [0];
J + +) printf ("%c", C[k]);
printf ("\ n");
}} else {///Enumeration Condition 2 for (int r=0; r<3; r++) {for (int cc=0; cc<3; cc++)
{if (R!=CC) {for (int i=0; i<2; i++) {
for (int j=0; j<2; J + +) {int KK; if ((r==0&&cc==1) | | | (r==1&&cc==0))
kk=2; if ((r==1&&cc==2) | | | (r==2&&cc==1))
kk=0;if ((r==2&&cc==0) | | | (r==0&&cc==2))
kk=1;
if (p[r][i]+p[cc][j]==n&&p[r][(i+1)%2]+p[kk][1]==n&&p[kk][0]==n)//Find scenario {
printf ("%d\n", n);///output for (int rr=0; rr<p[r][(i+1)%2]; rr++) {for (int ccc=0; ccc<p[r][i]; ccc++) printf ("%c", C[r
]);
for (int ccc=0; ccc<p[cc][j]; ccc++) printf ("%c", C[CC]);
printf ("\ n");
} for (int rr=0; rr<p[kk][1]; rr++) {
for (int ccc=0; ccc<p[kk][0]; ccc++) printf ("%c", C[kk]);
printf ("\ n");
} return 0; }}}}}//cannot find the schema output
-1 printf (" -1\n");
} return 0;
}