UVA11313 Gourmet Games【数学】

Wolfgang Puck is opening a new exclusive restaurant in Las Vegas and is looking for a chef. His nephew Hansel caught him thinking of posting an ad in newspapers. (Note: Wolfgang has heard of “this Internet thingy”, but didn’t find it interesting because one could not spread some Internet on a piece of bread, which is the mere minimum that has to be satisfied for something to be interesting, according to Mr. Puck.)
    Hansel knows what the advantages of the Internet job postings are, but he came up with an even better idea – given the success of various reality TV shows and given the fact that the restaurant is opening in Las Vegas, why not organize a sort of a cook-off tournament that will decide who Mr. Puck will hire?
    The idea basically combines the Iron Chef™ show with the World Series Of Poker™: Every
show m cooks prepare a five-course meal for judges and the best one (according to the said judges) advances to the next round. All candidates are ranked based on the previous experience so, even if the number of the candidates is not divisible by m, some of them can get a “bye” and compete in later rounds. The winner of the final show gets the honour of being the chef in the best Wolfgang Puck’s restaurant ever.
在这里插入图片描述
    Hansel realized that even with the byes it might not be possible to hold a tournament with m chefs per show, so he is trying to find out what the best m for the given number of candidates is. If you can just help him by letting him know if he can run a tournament as described with n candidates and m chefs per show and, in the case he can, how many shows he needs, he will be so grateful that he might even convince Mr. Puck to share the Secret Cheesecake Base Recipe with you.
Input
Input file starts with the line containing a single integer t, the number of test cases. Next t lines each contain two integers separated by spaces, n and m (2 ≤ n ≤ 10000, 2 ≤ m ≤ n), where n is the total number of candidates and m is the number of chefs participating in a single TV show.
Output
For each test case print the number of shows that need to be run to get the new chef. In the case that the tournament cannot be run with given n and m, print ‘cannot do this’.
Sample Input
3
3 2
4 3
4 4
Sample Output
2
cannot do this
1

问题链接UVA11313 Gourmet Games
问题简述:(略)
问题分析
    数学杂题不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA11313 Gourmet Games */

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t, n, m, ans;
    scanf("%d", &t);
    while(t--) {
        scanf("%d%d", &n, &m);

        ans = 0;
        for(;;) {
            if(n == m) {
                ans++;
                break;
            } else if(n < m) {
                ans = -1;
                break;
            } else {
                ans += n / m;
                n = n / m + n % m;
            }
        }

        if(ans == -1)
            printf("cannot do this\n");
        else
            printf("%d\n", ans);
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值