华南理工大学“三七互娱杯”程序设计竞赛(重现赛)C HRY and Abbas

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

  • 题目描述
    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
    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 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.
  • 输入
    2
    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

  现在有两个人一起玩游戏,有一把左轮手枪,两个人轮流向自己开枪(枪中某些位置有子弹),如果哪个人死了那么这个游戏就结束了.题目要求我们输出n个数,这n个数表示:还好在第i次开枪的时候游戏结束.首先我们需要计算有子弹的地方最多开机枪这个游戏结束.然后我们枚举1~n,二分查找最多开i枪游戏结束的位置有几个.然后进行输出.另外一种思路就是我们把当前能够计算的位置全部放在优先队列中,如果第i次可以结束游戏那么我们看优先队列中有多少元素,如果刚好第i次结束我们就需要把队列中的元素删除.

//优先队列
#include<bits/stdc++.h>
using namespace std;

const int Max_n=1e5+10;
int a[Max_n],b[Max_n];

priority_queue<int,vector<int>,greater<int> >q;

int gcd1(int a,int b){
    return b==0?a:gcd1(b,a%b);
}

int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=0;i<m;i++)
            scanf("%d",&a[i]);
        sort(a,a+m);
        for(int i=1;i<m;i++)
            b[i]=a[i]-a[i-1];
        b[0]=n-a[m-1]+a[0];
        for(int i=0;i<m;i++)
            q.push(b[i]);
        for(int i=1;i<=n;i++){
            if(q.empty()){
                printf("0\n");
            }else{
                int gcd=gcd1(q.size(),n);
                printf("%d/%d\n",q.size()/gcd,n/gcd);
                while(!q.empty()&&q.top()==i) q.pop();
            }
        }
    }
    return 0;
}
//二分查找
#include<bits/stdc++.h>
using namespace std;

const int Max_n=1e5+10;
int a[Max_n],b[Max_n];

int gcd1(int a,int b){
    return b==0?a:gcd1(b,a%b);
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=0;i<m;i++)
            scanf("%d",&a[i]);
        sort(a,a+m);
        for(int i=1;i<m;i++)
            b[i]=a[i]-a[i-1];
        b[0]=n-a[m-1]+a[0];
        sort(b,b+m);
        for(int i=1;i<=n;i++){
            int pos=m-(lower_bound(b,b+m,i)-b);
            if(!pos) printf("0\n");
            else{
                int gcd=gcd1(pos,n);
                printf("%d/%d\n",pos/gcd,n/gcd);
            }
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值