UESTC 1143.CD Making

1143.CD Making

Description

Tom has N songs and he would like to record them into CDs. A single CD can contain at mostK songs. In addition, Tom is very superstitious and he believes the number '13' would 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 test cases. The first line givesT, number of test cases.T lines follow, each contains N andK, 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

2
5 2
13 13

Sample Output

3
2

Source

The 5th UESTC Programming Contest Preliminary 


       这样的题出来就是坑人的,看似很简单,可是一旦漏掉了某些特殊情况,提交时总是出现的“wrong anwser”就实在让人抓狂。。。

不急,慢慢分析:

        ⑴、K<13时,显然,如果N%K==0,那就是N/K个光盘;

                                          如果N%K!=0,那就需要N/K+1个光盘。

        ⑵、K=13时,要当12来对待,同上:

                                          如果N%12==0,那就是N/12个光盘;

                                          如果N%12!=0,那就需要N/12+1个光盘。

        K>13时,是不是如果N%K==13,就一定需要多加2个光盘呢,非也:

       ⑶、K=14时,如果N%K==0,那就是N/K个光盘;

                              如果N%K==13,那就是N/K+2个光盘;

                              如果N%K!=0、13;那就是N/K+1个光盘;

       ⑷、K>14时,如果N%K==0,那就是N/K个光盘;

       (如果N%K==13,那就是N/K+2个光盘???NO,因为要光盘数最小,所以我们可以把任意一个前面的一张光盘里面的一首歌移到这张光盘上,这样就是14首,而被移走歌曲的那张光盘也不会剩余13首歌,因为K>14。。这种做法对于K=14就不适合了!!)

       所以如果N%K!=0,那就是N/K+1个光盘;

       好了,到这就结束了??如果提交程序的话,依然会是“wrong anwser”,到底少了神马咧?

    ⑸、如果TOM总共就13首歌,即N=13时,应用到K<13,K=13,K=14三种情况,都没问题。可是K>14时,按我们的思路,N%K==13!=0,那么就是N/K+1=1个光盘。可是这样的话,这个光盘上就会有13首歌,这时我就想了,难道不能把一首歌重复刻录两次,这样就是14首歌??可惜出题人并没有考虑到这点,我们也无法和服务器的评判标准对抗。。。。所以N=13,K>14时,就需要2个光盘。。。。

#include<iostream>
using namespace std;

int main()
{
   int T;
   cin>>T;
   while(T--)
   {
             int N,K,cd;
             cin>>N>>K;
             if(K<13)
             {
                     if(N%K==0)
                        cd=N/K;
                     else
                         cd=N/K+1;
             }
             else if(K==13)
             { 
                  if(N%12==0)
                        cd=N/12;
                  else
                        cd=N/12+1;
             }
             else if(K==14)
             {
                 if(N%K==0)
                        cd=N/K;
                 else if(N%K==13)
                        cd=N/K+2;
                 else
                        cd=N/K+1;
             }
             else 
             {
                  if(N==13)
                         cd=2;
                  else if(N%K==0)
                        cd=N/K;
                  else
                        cd=N/K+1;
             }
             cout<<cd<<endl;
     }
     return 0;
}
 				    


    


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值