CodeForces 44B Cola
2016-02-23 22:56
267 查看
B. Cola
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 test(s)
Input
Output
Input
Output
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 test(s)
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,i,j,ans,temp; while(cin>>n>>a>>b>>c){ ans=0; for(i=0;i<=c;i++){ for(j=0;j<=b;j++){ temp=n-i*2-j; if(temp>=0&&a*0.5>=temp){ ans++; } } } cout<<ans<<endl; } return 0; }
相关文章推荐
- Canopy使用教程 (2)
- vTPM架构分析与环境部署
- 动态树(LCT):HDU 4010 Query on The Trees
- uva 11400
- Hibernate与代理模式
- 一路奔跑,一路寻找
- LeetCode 136. Single Number
- Failed to convert value of type...no matching editors or conversion strategy found
- 1045. 快速排序
- storm tuple 结构
- 分类算法的R语言实现案例
- c++中堆、栈内存分配
- Ubuntu linux 关机、重启、注销 命令
- jqery
- 几种方式实现tab---fragment
- 百度地图实现计算两点之间的距离
- [linux]linux下开启wifi热点
- HTML5新特性之WebRTC
- 开场白
- sudo 和 su 的区别