HRY and Abbas

题目描述
In a parallel universe, HRY is the president of the Kassel Academy Student Union. Once he and the Lionheart Association President Abdullah Abbas performed a secret mission: to investigate the mixed blood drug trafficking group in country X.

However, an accident happened and they were caught together. They were forced to play Russian gambling roulette games!

The terrorists brought a revolver which works as follows: a revolver has n places 1,2,…,n to place bullet, and these n places forms a circle. The revolver has a position it is currently pointing at, and when pulling the trigger, the revolver will shoot out the bullet (if it has) at the current position and turn to the next position. The next position of i (1≤i≤n−1) is i+1, and for n the next position is 1. Now the terrorist puts m bullets in the revolver, and turned the wheel of the revolver, which means the starting position is randomly chosen. He orders HRY and Abbas shoot at their heads in turn using the same revolver. If someone is hit by bullet, then the game is over.

HRY and Abbas are both not ordinary mixed blood, so the revolver can do no harm to them. However, they still decided to play the game. Now they want to know the probability of the game ending exactly after the ith shoot.

输入描述:
The first line is an integer T, indicating the number of test cases.
For each test case there are two lines :
The first line contains two integers n,m, and the second line contains m different positive integers ai, indicating the initial positions of bullets.
1≤T≤1000,1≤m≤n≤105,1≤ai≤n.
The sum of n does not exceed
10
6
106.
输出描述:
For each test case output n lines, the ith line indicates the probability of game ending exactly after the ith shoot. The probability is in the form of irreducible fraction p/q, which means the greatest common divisor of p and q is 1. If the answer is 0, output 0 directly.
输入

10 2
1 3
10 4
1 2 6 10

输出

1/5
1/5
1/10
1/10
1/10
1/10
1/10
1/10
0
0
2/5
1/5
1/5
1/5
0
0
0
0
0
0

模拟即可

#include <bits/stdc++.h>

using namespace std;

const int MAX_LEN = 1e5 + 10;
int a[MAX_LEN];
int b[MAX_LEN];
int gcd(int a, int b)
{
    int c = a % b;
    while (c)
    {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T; cin >> T;
    while (T--)
    {
        int n, m;
        cin >> n >> m;
        for (int i = 1; i <= m; i++)
            cin >> a[i];
        sort(a + 1, a + m + 1);
        b[1] = n - a[m] + a[1];
        for (int i = 2; i <= m; i++)
        	b[i] = a[i] - a[i - 1];
        sort(b + 1, b + m + 1);
        int p = 0;
        for (int i = 1; i <= n; i++)
        {
        	while (p < m && b[p + 1] < i) p++;
        	int t;
        	t = m - p;
        	if (!t)
        	{
        		cout << 0 << '\n';
        	}
        	else
        	{
        		int g = gcd(t, n);
        		cout << t / g << '/' << n / g << '\n';
        	}
        }
    }
    
    return 0;
}

链接:https://ac.nowcoder.com/acm/contest/874/C
来源:牛客网

全部评论

相关推荐

无情咸鱼王的秋招日记之薛定谔的Offer:好拒信,偷了,希望有机会用到
点赞 评论 收藏
分享
努力学习的小绵羊:我反倒觉得这种挺好的,给不到我想要的就别浪费大家时间了
点赞 评论 收藏
分享
评论
3
1
分享
正在热议
# 25届秋招总结 #
440428次浏览 4493人参与
# 春招别灰心,我们一人来一句鼓励 #
41455次浏览 524人参与
# 北方华创开奖 #
107295次浏览 599人参与
# 地方国企笔面经互助 #
7923次浏览 18人参与
# 虾皮求职进展汇总 #
114057次浏览 883人参与
# 实习,投递多份简历没人回复怎么办 #
2453918次浏览 34847人参与
# 阿里云管培生offer #
119782次浏览 2219人参与
# 实习必须要去大厂吗? #
55665次浏览 960人参与
# 同bg的你秋招战况如何? #
75478次浏览 551人参与
# 提前批简历挂麻了怎么办 #
149813次浏览 1977人参与
# 投递实习岗位前的准备 #
1195668次浏览 18546人参与
# 你投递的公司有几家约面了? #
33170次浏览 188人参与
# 双非本科求职如何逆袭 #
661868次浏览 7394人参与
# 机械人春招想让哪家公司来捞你? #
157600次浏览 2267人参与
# 如果公司给你放一天假,你会怎么度过? #
4723次浏览 54人参与
# 如果你有一天可以担任公司的CEO,你会做哪三件事? #
11332次浏览 270人参与
# 发工资后,你做的第一件事是什么 #
12405次浏览 61人参与
# 工作中,努力重要还是选择重要? #
35599次浏览 384人参与
# 参加完秋招的机械人,还参加春招吗? #
20087次浏览 240人参与
# 实习想申请秋招offer,能不能argue薪资 #
39225次浏览 314人参与
# 我的上岸简历长这样 #
451915次浏览 8088人参与
# 非技术岗是怎么找实习的 #
155842次浏览 2120人参与
牛客网
牛客企业服务