华南理工大学 “三七互娱杯” C HRY and Abaas

https://ac.nowcoder.com/acm/contest/874/C

题目大意是两人俄罗斯轮盘赌 n个位置 有m个子弹 已知哪些位置上有子弹 子弹打出 游戏结束 求第i次扣动扳机游戏才结束的概率

直接模拟就过了  注意输出的时候分数要约分 c++真的好用 直接就有gcd函数

#include<bits/stdc++.h>

using namespace std;

int a[100010];
int x[100010];
int main()
{
    int m;
    scanf("%d",&m);
    while(m--)
    {
        int n,t;
        scanf("%d%d",&n,&t);
        memset(x,0,sizeof(x));
        memset(a,0,sizeof(a));
        for(int i=1;i<=t;i++)
        {  
            scanf("%d",&a[i]);
        }
        sort(a+1,a+1+t);    //保证位置是从小到大按顺序存储的
        for(int i=2;i<=t;i++)
        {
            for(int j=1;j<=a[i]-a[i-1];j++)
            {
                x[j]++;
            }
        }
        for(int i=1;i<=(a[1]+n-a[t]);i++)   //对最后一个进行特判,因为涉及到环
        {
            x[i]++;
        }
        for(int i=1;i<=n;i++)
        {
 
            if(x[i]==0)
            printf("0\n");
            else
            {
                int xx=__gcd(x[i],n);
                printf("%d/%d\n",x[i]/xx,n/xx);
            }
        }
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/dyhaohaoxuexi/p/10857152.html
今日推荐