跳到正文

题解

题解:P13365 [GCJ 2011 #1A] FreeCell Statistics

xtzhangziche约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 3 分钟
题目
P13365

版本

  1. v1当前

题目传送门

思路

我们需要判断是否存在满足条件的 DD 和 GG,使得:

D≤ND \leq N(今天玩的局数不超过 NN)

D×PD100\displaystyle \frac{D \times P_D}{100} 是整数(今天赢的局数为整数)

G×PG100\displaystyle \frac{G \times P_G}{100} 是整数(总赢的局数为整数)

G≥DG \geq D(总局数不少于今天玩的局数)

Broken 的情况 直接排除以下不可能的情况:

  • PG=0P_G = 0 且 PD>0P_D > 0(总胜率为 00% 时,今天不可能有正胜率)。

  • PG=100P_G = 100 且 PD<100P_D < 100(总胜率为 100100% 时,今天不可能有非全胜)。

  • 最小 D>ND > N(今天玩的局数不可能超过 NN)。

求最小 DD 的方法 我们需要找到最小的 DD 使得 D×PD≡0(mod100)D \times P_D \equiv 0 \pmod{100}。

设 g=gcd⁡(PD,100)g = \gcd(P_D, 100)。

设 kk 和 mm。

分解:

PD=g×kP_D = g \times k

100=g×m100 = g \times m

其中 gcd⁡(k,m)=1\gcd(k, m) = 1(kk 和 mm 互质)。

最小 DD 必须满足 D×k≡0(modm)D \times k \equiv 0 \pmod{m}。

因为 gcd⁡(k,m)=1\gcd(k, m) = 1,所以 DD 必须是 mm 的倍数。

因此,最小 D=m=100gD = m = \displaystyle \frac{100}{g}。

结论 若 PG=0P_G = 0 且 PD>0P_D > 0,或 PG=100P_G = 100 且 PD<100P_D < 100,或 100gcd⁡(PD,100)>N\displaystyle \frac{100}{\gcd(P_D, 100)} > N,则输出 Broken。

否则输出 Possible。

Code

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,t;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>T;
    while(T--)
    {
        int n,pd,pg;
        cin>>n>>pd>>pg;
        int d=100/__gcd(pd,100ll);
        cout<<"Case #"<<++t<<": ";
        if((pg==0&&pd>0)||(pg==100&&pd<100)||(d>n)) cout<<"Broken";
        else cout<<"Possible";
        cout<<'\n';
    }
    return 0;
}
原文