链接:https://ac.nowcoder.com/acm/contest/874/C
题意:有2个人玩俄罗斯转盘(不知道的百度一下),一个可以装n个子弹,已知抢装了m颗子弹,而且知道,每颗子弹的位置,问你分别在1-n次开枪结束游戏的概率。
思路:模拟- -,我们可以在遍历每一颗子弹的位置,然后向前推,如果子弹位置为i,而i-1没有子弹,那么该位置就是开第2枪结束游戏的位置,直到某一位有子弹为止。
#include<iostream>
#include<deque>
#include<memory.h>
#include<stdio.h>
#include<map>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
using namespace std;
typedef long long int ll;
int n,m,t,arr[100100],book[100100],book2[100100];
int gcd(int a,int b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
int main()
{
cin>>t;
while(t--)
{
memset(book2,0,sizeof(book2));
memset(book,0,sizeof(book));
cin>>n>>m;
for(int i=1;i<=m;i++)
scanf("%d",&arr[i]),book2[arr[i]]=1;
for(int i=1;i<=m;i++)
{
int k=2;
int temp=arr[i]-1;
if(temp<=0)
temp=n;
while(!book2[temp])
{
temp--;
if(temp<=0)
temp=n;
book[k]++;
k++;
}
}
book[1]=m;
for(int i=1;i<=n;i++)
{
if(!book[i])
printf("0\n");
else
{
int temp=gcd(n,book[i]);
printf("%d/%d\n",book[i]/temp,n/temp);
}
}
}
return 0;
}