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 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?
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.
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.
3 1
1 1
2 3
2 0
7 3
3 2
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.
水题代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
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 beluxurious 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 thei-th house to make it luxurious?" (for alli 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 housei does not affect other answers (i.e., the floors to the houses are not actually added).
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.
Print n integers a1, a2, ..., an, where numberai is the number of floors that need to be added to the house numberi to make it luxurious. If the house is already luxurious and nothing needs to be added to it, thenai should be equal to zero.
All houses are numbered from left to right, starting from one.
5 1 2 3 1 2
3 2 0 2 0
4 3 2 1 4
2 3 4 0
水题:注意为负值时直接改成0
代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
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 integerai from 0 to 100. The higher the numberai is, the higher is thei-th skill of the character. The total rating of the character is calculated as the sum of the values of 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 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.
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 integersai (0 ≤ ai ≤ 100), whereai characterizes the level of thei-th skill of the character.
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.
2 4 7 9
2
3 8 17 15 19
5
2 2 99 100
20
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 .
代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
Three companies decided to order a billboard with pictures of their logos. A billboard is a bigsquare 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.
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 xi andyi determine the length and width of the logo of thei-th company respectively.
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:
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.
5 1 2 5 5 2
5 AAAAA BBBBB BBBBB CCCCC CCCCC
4 4 2 6 4 2
6 BBBBBB BBBBBB AAAACC AAAACC AAAACC AAAACC
题意:给出三个company的logo所占的矩形的长宽,问能否组成一个正方形,若可以,则输出边长,及任意一种拼凑方案,否则输出-1;
先看面积是不是平方数,如果不是平方数那么绝对不可能拼凑出正方形直接输出-1,;
若是平方数,则去找到一种平凑方案;
对于拼凑方案只有两种情况:
情况1:
情况2:
对于情况一直接输出就好了,对于情况二,循环找到所属的情况输出;
代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include