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

· · 题解

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

题目链接

思路

首先分类讨论:

当今日胜率 P_D0\% 时,总局胜率 P_G 不能是 100\%,因为今日至少玩了一局且全输;

P_D100\%时,P_G 不能是 0\%,因为今日至少赢了一局。

对于 1\%-99\% 的情况,需要计算最小可能的 D 值,若这个最小 D 超过 N 则不可能。此外,P_G 不能为 0\%100\%,否则会导致矛盾。

最后输出判断结果。

Code

#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,n,pd,pg;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>t;
    for(int cas=1;cas<=t;cas++){
        cin>>n>>pd>>pg;
        cout<<"Case #"<<cas<<": ";
        if(pd==0){
            if(pg!=100)cout<<"Possible\n";
            else cout<<"Broken\n";
        }
        else if(pd==100){
            if(pg!=0)cout<<"Possible\n";
            else cout<<"Broken\n";
        }
        else{
            int g=__gcd(pd,100ll);
            int d=100/g;
            if(d>n)cout<<"Broken\n";
            else{
                if(pg!=0&&pg!=100)cout<<"Possible\n";
                else cout<<"Broken\n";
            }
        }
    }
    return 0;
}