2018 BACS Contest Replay A - A Criminal (模拟)

原题地址:http://codeforces.com/gym/101864/attachments

题意:这就是约瑟夫环为2的情况,每次给出$X,L,N$,让你求编号为x,且选取的人数是[L,N]时,存活的概率.

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define eps 1e-8
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define CLR(x,y) memset((x),y,sizeof(x))
#define fuck(x) cerr << #x << "=" << x << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int seed = 131;
const int maxn = 1e5 + 5;
const int mod = 998244353;

int t;
ll x, l, n;
ll func(ll s) {
   ll  ans = 0;
    if (x % 2 == 0) return 0;
    for (ll i = 1; i <= s; i*=2) {
        ll up = min(2 * i - 1, s);//上界
        ll down = i;//下界
        ll num = up - down + 1;//数量
        if (x <= 2 * num - 1) ans++;//判断
    }
    return ans;
}
int main() {
    scanf("%d", &t);
    for (int cas = 1; cas <= t; cas++) {
        scanf("%I64d%I64d%I64d", &x, &l, &n);
        ll ret = func(n) - func(l - 1);
        if (x > l) ret += x - l;
        ll all = n - l + 1;
        ll gcd = __gcd(all, ret);
        printf("Case %d: %I64d/%I64d\n", cas, ret / gcd, all / gcd);
    }
    return 0;
}

 

你可能感兴趣的:(ACM_模拟)