56 megabytes
You have r red,g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number t of tables can be decorated if we know number of balloons of each color?
Your task is to write a program that for given valuesr, g andb will find the maximum number t of tables, that can be decorated in the required manner.
Input
The single line contains three integers r, g and b (0?≤?r,?g,?b?≤?2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.
Output
Print a single integer t — the maximum number of tables that can be decorated in the required manner.
Sample test(s) Input
5 4 3
Output
4
Input
1 1 1
Output
1
Input
2 3 3
Output
2
Note
In the first sample you can decorate the tables with the following balloon sets: rgg, gbb, brr, rrg, where r, g and b represent the red, green and blue balls, respectively.
?
?
分析:大概写几个yy一下
?
?
#include
#include
#define ll long long using namespace std; int main() { ll a[3], ans = 0; scanf(%I64d %I64d %I64d, &a[0], &a[1], &a[2]); sort(a, a + 3); if((a[0] + a[1]) <= a[2] / 2) ans = a[0] + a[1]; else ans = (a[0] + a[1] + a[2]) / 3; printf(%I64d ,ans); }
?
?
?
?
?
D. Red-Green Towers time limit per test 2 seconds memory limit per test 256 megabytes
There are r red andg green blocks for construction of the red-green tower. Red-green tower can be built following next rules:
?
Red-green tower is consisting of some number of levels;
?
Let the red-green tower consist of
n levels, then the first level of this tower should consist of
n blocks, second level — of
n?-?1 blocks, the third one — of
n?-?2 blocks, and so on — the last level of such tower should consist of the one block. In other words, each successive level should contain one block less than the previous one;
?
Each level of the red-green tower should contain blocks of the same color.
Let h be the maximum possible number of levels of red-green tower, that can be built out ofr red and g green blocks meeting the rules above. The task is to determine how many different red-green towers havingh levels can be built out of the available blocks.
Two red-green towers are considered different if there exists some level, that consists of red blocks in the one tower and consists of green blocks in the other tower.
You are to write a program that will find the number of different red-green towers of heighth modulo 109?+?7.
Input
The only line of input contains two integers r and g, separated by a single space — the number of available red and green blocks respectively (0?≤?r,?g?≤?2·105,r?+?g?≥?1).
Output
Output the only integer — the number of different possible red-green towers of heighth modulo 109?+?7.
Sample test(s) Input
4 6
Output
2
Input
9 7
Output
6
Input
1 1
Output
2
Note
The image in the problem statement shows all possible red-green towers for the first sample.
分析 :dp,算下高度,然后算出r的最小需要的个数,高度i,1-h枚举,红色j,r-0枚举dp[j] += dp[j - i];最后把满足条件的dp值加起来即可
?
?
?
#include
#include
#define ll long long int const MOD = 1e9 + 7; int const MAX = 200000 + 5; int dp[MAX]; int main() { int r, g, h, ans = 0, tmp = 0; scanf(%d %d, &r, &g); ll min_r; memset(dp, 0, sizeof(dp)); dp[0] = 1; for(int i = 1; tmp <= (r + g) ;i++) { tmp += i; if(tmp > (r + g)) { h = i - 1; break; } } min_r = h * (h + 1) / 2 - g; for(int i = 1; i <= h; i++) { for(int j = r; j >= 0; j--) { if(j - i >= 0) dp[j] = (dp[j] % MOD + dp[j - i] % MOD) % MOD; if(i == h && j >= min_r) ans = (ans % MOD + dp[j] % MOD) % MOD; } } printf(%d , ans); }
?
?
?