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
来源:牛客网

全部评论

相关推荐

01-30 22:03
门头沟学院 Java
用微笑面对困难:我滴妈,【俩月】【实习】【主管】仨debuff吃满了,独立设计开发的项目写了绝大占比的运营板块,你独立开发,那维护、问题复盘、日志更新、bug、策划书全是自己整的? 不建议写那么大,可以从小出发更容易
点赞 评论 收藏
分享
评论
3
1
分享

创作者周榜

更多
正在热议
更多
# 春招至今,你的战绩如何? #
8962次浏览 81人参与
# 你的实习产出是真实的还是包装的? #
1659次浏览 40人参与
# MiniMax求职进展汇总 #
23704次浏览 306人参与
# 军工所铁饭碗 vs 互联网高薪资,你会选谁 #
7358次浏览 40人参与
# 重来一次,我还会选择这个专业吗 #
433282次浏览 3926人参与
# 简历第一个项目做什么 #
31486次浏览 326人参与
# 巨人网络春招 #
11296次浏览 223人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
186851次浏览 1118人参与
# 不考虑薪资和职业,你最想做什么工作呢? #
152256次浏览 887人参与
# 研究所笔面经互助 #
118841次浏览 577人参与
# 简历中的项目经历要怎么写? #
309928次浏览 4186人参与
# 面试紧张时你会有什么表现? #
30468次浏览 188人参与
# 你今年的平均薪资是多少? #
212968次浏览 1039人参与
# AI时代,哪些岗位最容易被淘汰 #
63273次浏览 795人参与
# 我的求职精神状态 #
447952次浏览 3128人参与
# 你最满意的offer薪资是哪家公司? #
76404次浏览 374人参与
# 高学历就一定能找到好工作吗? #
64288次浏览 620人参与
# 牛客AI文生图 #
21398次浏览 238人参与
# 你怎么看待AI面试 #
179765次浏览 1227人参与
# 正在春招的你,也参与了去年秋招吗? #
363143次浏览 2635人参与
# 腾讯音乐求职进展汇总 #
160549次浏览 1109人参与
# 职能管理面试记录 #
10794次浏览 59人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务