CodeForces - 44B Cola
2015-03-23 00:35
761 查看
Cola
Submit Status
Description
To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned
out that cola is sold in bottles 0.5, 1 and 2 liters
in volume. At that, there are exactly a bottles 0.5 in volume,b one-liter
bottles and c of two-liter ones. The organizers have enough money to buy any amount of cola. What did cause the heated arguments was how many bottles of every kind to buy,
as this question is pivotal for the distribution of cola among the participants (and organizers as well).
Thus, while the organizers are having the argument, discussing different variants of buying cola, the Winter School can't start. Your task is to count the number of all the possible ways to buy exactly n liters
of cola and persuade the organizers that this number is too large, and if they keep on arguing, then the Winter Computer School will have to be organized in summer.
All the bottles of cola are considered indistinguishable, i.e. two variants of buying are different from each other only if they differ in the number of bottles of at least one kind.
Input
The first line contains four integers — n, a, b, c (1 ≤ n ≤ 10000, 0 ≤ a, b, c ≤ 5000).
Output
Print the unique number — the solution to the problem. If it is impossible to buy exactly n liters of cola, print 0.
Sample Input
Input
Output
Input
Output
枚举,剪枝一下就过了,两重循环和三重循环真的不一样。
Time Limit: 2000MS | Memory Limit: 262144KB | 64bit IO Format: %I64d & %I64u |
Description
To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned
out that cola is sold in bottles 0.5, 1 and 2 liters
in volume. At that, there are exactly a bottles 0.5 in volume,b one-liter
bottles and c of two-liter ones. The organizers have enough money to buy any amount of cola. What did cause the heated arguments was how many bottles of every kind to buy,
as this question is pivotal for the distribution of cola among the participants (and organizers as well).
Thus, while the organizers are having the argument, discussing different variants of buying cola, the Winter School can't start. Your task is to count the number of all the possible ways to buy exactly n liters
of cola and persuade the organizers that this number is too large, and if they keep on arguing, then the Winter Computer School will have to be organized in summer.
All the bottles of cola are considered indistinguishable, i.e. two variants of buying are different from each other only if they differ in the number of bottles of at least one kind.
Input
The first line contains four integers — n, a, b, c (1 ≤ n ≤ 10000, 0 ≤ a, b, c ≤ 5000).
Output
Print the unique number — the solution to the problem. If it is impossible to buy exactly n liters of cola, print 0.
Sample Input
Input
10 5 5 5
Output
9
Input
3 0 0 2
Output
0
枚举,剪枝一下就过了,两重循环和三重循环真的不一样。
#include<iostream> using namespace std; int main() { int n, a, b, c; while (cin >> n >> a >> b >> c) { int ans = 0; for (int i = 0; i <= c;i++) for (int j = 0; j <= b; j++) { int temp = n - i * 2 - j; if (temp >= 0 && a * 0.5 >= temp) ans++; } cout << ans << endl; } }
相关文章推荐
- CodeForces 44B Cola
- CodeForces 44B Cola
- CodeForces 257C View Angle
- codeforces 540B School Marks
- codeforces 707D D. Persistent Bookcase(dfs)
- 【Codeforces Round #403】Codeforces 781A Andryusha and Colored Balloons
- Codeforces 841 CLeha and Function
- Codeforces 932D - Tree 【树上倍增】
- CodeForces 514D R2D2 and Droid Army RMQ+二分
- CodeForces - 630N Forecast (解一元二次方程组)
- CodeForces 707C Pythagorean Triples (数论)
- codeforces 782B The Meeting Place Cannot Be Changed
- codeforces840D Destiny -- 可持久化线段树
- Codeforces 918A Eleven(水的不能在水的打表题)
- Codeforces 78E Evacuation
- CodeForces 520C DNA Alignment
- codeforces 628B
- 【模拟】Codeforces 705A Hulk
- Codeforces 300C Beautiful Numbers 组合数取模+暴力
- Journey CodeForces - 839C