UESTC 65 CD Making 贪心法
2015-11-28 19:10
435 查看
CD Making
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
Submit
Status
Tom has N songs
and he would like to record them into CDs. A single CD can contain at most K songs.
In addition, Tom is very superstitious
and he believes the number
13would
bring bad luck, so he will never let a CD contain exactly 13 songs.
Tom wants to use as few CDs as
possible to record all these songs. Please help him.
Input
There are T testcases. The first line gives T,
number of test cases. T lines
follow, each contains N and K,
number of songs Tom wants to
record into CDs, and the maximum number of songs a single CD can contain.
1≤N≤1000,1≤K≤1000
Output
For each test case, output the minimum number of CDs required, if the above constraints are satisfied.
Sample input and output
Sample Input | Sample Output |
---|---|
2 5 2 13 13 | 3 2 |
Hint
If Tom has 5 songsto record and a single CD can contain up to 2 songs,
Tom has to use 3 CDs
at minimum, each contains 2, 2, 1 songs,
respectively.
In the second case, Tom wants to record 13 songs,
and a single CD can hold 13 songs
at most. He would have been able to use only 1 CD
if
he were not so superstitious. However, since he will not record exactly 13 songs
into a single CD, he has to use 2 CDs
at least, the first
contains
12 songs
and the second contains one(Other solutions to achieve 2 CDs
are possible, such as (11, 2),
(10, 3),
etc.).
Source
The 5th UESTC Programming Contest Preliminary
My Solution
秒杀题,就是那个K==14的时候要想到,要额外处理#include <iostream> #include <cstdio> using namespace std; int main() { int T,N,K,ans; scanf("%d",&T); while(T--){ ans=0; scanf("%d%d",&N,&K); if(N<=K) {if(N!=13)printf("1"); else printf("2");} else { if(K==13) {ans=N/12;if(N%12!=0) ans+=1;} else if(K<13||K>14) { ans=N/K; if(N%K!=0) ans+=1; //如果K>14&&N%K==13,只要从另外一个地方补个过来变成14就可以了,不用另外加CD } else { //K==14 ans=N/K; if(N%K!=0){ if(N%K!=13) ans+=1; else ans+=2; } } printf("%d",ans); } if(T) printf("\n"); } return 0; }
谢谢
相关文章推荐
- UI-之plist文件解析
- 【Leetcode】N-Queens II
- UINavigationController设置导航栏属性
- 【Leetcode】N-Queens
- UITabBarController
- Codeforces 288E Polo the Penguin and Lucky Numbers
- UITableView 的结构
- 使用druid连接池的超时回收机制排查连接泄露问题
- 在Legacy BIOS与UEFI 两种模式安装Windows 8操作系统的方法
- iOS 9人机界面指南:UI设计基础--模态情景(Modal Contexts)
- HDFS Short-Circuit Local Reads
- iOS流布局UICollectionView系列一——初识与简单使用UICollectionView
- Duilib源码分析(四)绘制管理器—CPaintManagerUI—(前期准备四)
- easyui datagrid 表格组件列属性formatter和styler使用方法
- 导航栏控制器和标签栏控制器(UINavigationController和UITabBarController)混用
- codeforces B.Queries about less or equal elements
- UIViewController、UINavigationController与UITabBarController的整合使用
- Android属性之build.prop生成过程分析
- 软件测试自动化之- 基于反射的UI自动化测试框架 - UI Automation Test Framework
- H+响应式后台主题UI