URAL 1820 Ural Steaks (贪心)
2015-03-04 14:38
357 查看
Ural Steaks
Time limit: 0.5 secondMemory limit: 64 MB
After the personal contest, happy but hungry programmers dropped into the restaurant “Ural Steaks” and ordered n specialty steaks. Each steak is cooked by frying each of its sides on a frying
pan for one minute.
Unfortunately, the chef has only one frying pan, on which at most k steaks can be cooked simultaneously. Find the time the chef needs to cook the steaks.
Input
The only input line contains the integers n and k separated with a space (1 ≤ n, k ≤ 1000).Output
Output the minimal number of minutes in which the chef can cook n steaks.Sample
input | output |
---|---|
3 2 | 3 |
解析:先让所有的饼都先煎一面,然后再考虑煎第二面,同时尽量让锅的空间尽可能利用。当2*n%k == 0时,通过这样的顺序调整,我们可以让所有锅空间都利用上,直接计算总面数即可;否则,我们就要加上一次多余的。
AC代码:
#include <iostream> using namespace std; int main(){ int n, k, ans; while(cin>>n>>k){ if(n <= k) ans = 2; else{ ans = 2 * n / k; //直接按面数计算即可 if(2 * n % k) ans ++; } cout<<ans<<endl; } return 0; }
相关文章推荐
- ural 1820. Ural Steaks 贪心
- URAL1820 - Ural Steaks - 贪心
- URAL - 1820 Ural Steaks(小学生题)
- URAL 1820. Ural Steaks
- ural 1820. Ural Steaks -思维题
- URAL 1820. Ural Steaks(数学啊 )
- URAL 1820. Ural Steaks(数学啊 )
- URAL 1901 Space Elevators(贪心)
- URAL 1303 Minimal Coverage (贪心)
- URAL 1161 Stripies(数学+贪心)
- URAL 2021 Scarily interesting! (贪心+题意)
- URAL 2021. Scarily interesting!(*贪心? set整理)
- URAL 2026 Dean and Schedule 贪心、双端队列(deque)、队列(queue)
- Ural 1303 Minimal Coverage(贪心)
- URAL 1826. Minefield 贪心
- URAL 1203 Scientific Conference(贪心 || DP)
- URAL 1876. Centipede's Morning (贪心)
- URAL - 1785,1293,1877,1409,1820,1787,1264,2012
- ural 1880. Psych Up's Eigenvalues 贪心
- URAL 1014 Product of Digits 贪心