hdu 3895 Inverting Cups 每次翻转b个杯子,最少多少次把所有杯子都翻转一次

本文深入探讨了游戏开发领域的核心技术,包括游戏引擎、图形渲染、3D空间视频等关键概念,为开发者提供了一站式的学习指南。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem Description
When people drink some tea in the teahouse, they also play some casual games. Now, inverting cups is a popular game. The meaning of the question is, now there are some cups which are upturned, we can regard the total number of the cups as a positive integer number A , and we can invert some cups, the number is B and B is also a positive integer number. We define one retroflexion that if the original cup is upturned, one retroflexion makes it downward, and if the original cup is downward, one retroflexion makes it upturned. So the question is if the whole original cups are upturned , can we invert these cups to make all the cups downward? And if it is possible, how many is the least of times?
 

Input
The input contains multiple test cases(cases<=100000). Each case one line given two numbers , the first integer A (1<=A<=2^63) and the second integer B (1<=B<=A). The input is terminated by the end of file.
 

Output
For each test case, you should output how many the least of times if it is possible for us to invert all the cups, and if it is impossible please output “No Solution!”
 

Sample Input
5 3 14 4 8 5 11 4
 

Sample Output
3 4 4 No Solution!

//

#include<iostream>
#include<cstdio>
using namespace std;
int main() {
    __int64 a, b, t, ans;
    while (scanf("%I64d%I64d",&a,&b)==2) {
        ans = 0;
        if (a % 2 && b % 2 == 0) {
            printf("No Solution!\n");
            continue;
        }
        while (1) {
                if (a / b >= 3) {
                t = (a-2*b)/b;
                ans += t;
                a -= t*b;
            }
            if (a % b == 0)ans += a / b;
            else if (a % 2 == b % 2)ans += 3;
            else if (a / b >= 2)ans += 4;
            else {
                b = a - b;
                continue;
            }
            break;
        }
        printf("%I64d\n", ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值