2019icpc沈阳网络赛

J题:

题意:给你一张大小为n的不确定的图,这个图不确定,每个点的入度和出度都为1。那么这样的图的一个特点就是肯定由若干个欧拉回路组成的。   可以得到递推公式就是n!

然后就再看它还有一个特点。要求每个点必须走不大于x条边能回到自身。。。。。。。    (n<=2*x<2e9)

我们肯定只能从反面想,把它不符合条件的都去除,因为(n<=2*x<2e9) 这个条件注定了可以这样想。。。。。。。

由于有 p(m)=c(m,n)*(m-1)!*(n-m)!/n!=1/m    所以对于每个的概率是1/i  (x<i<=n)

预处理一下即可,下面是代码:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <bitset>
 5 #include <iostream>
 6 #include <algorithm>
 7 typedef long long ll;
 8 using namespace std;
 9 const ll mod=(ll)(1e9+7);
10 const int maxn=(int)(1e6+10);
11 ll sum[maxn];
12 int t;
13 ll x,n;
14
15 ll fast_pow(ll a,ll b){
16    ll res=1;
17    while(b){
18        if(b%2==1) res=(res*a)%mod;
19        a=(a*a)%mod;
20        b=b/2;
21    }
22    return res;
23 }
24
25 void init(){
26     sum[0]=0;
27     for(ll i=1;i<maxn;i++){
28         sum[i]=(sum[i-1]+fast_pow(i,mod-2))%mod;
29     }
30 }
31
32
33
34 int main(){
35     init();
36     scanf("%d",&t);
37     while(t--){
38         scanf("%lld%lld",&n,&x);
39         if(x>=n){
40             printf("1\n");
41             continue;
42         }else{
43             ll ans1=1,ans2=1;
44             for(ll i=x+1;i<=n;i++)  ans1=(ans1*i)%mod;
45             ans2=(ans1-(ans1*(sum[n]-sum[x]+2*mod))%mod+2*mod)%mod;
46             //cout<<ans1<<"  "<<ans2<<endl;
47             printf("%lld\n",ans2*fast_pow(ans1,mod-2)%mod);
48         }
49     }
50     return 0;
51 }

原文地址:https://www.cnblogs.com/pandaking/p/11520485.html

时间: 2024-07-30 20:33:27

2019icpc沈阳网络赛的相关文章

【2019.09.14】2019icpc沈阳网络赛

题目地址:https://www.jisuanke.com/contest/3007 A: B: C: D: E: F: G: H: I: J: K: 原文地址:https://www.cnblogs.com/ncu2019/p/11565338.html

2015沈阳网络赛1003 Minimum Cut 树链剖分 数组维护前缀和进行区间增减

2015沈阳网络赛1003  Minimum Cut   树链剖分 数组维护前缀和进行区间增减 Minimum Cut Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Given a simple unweighted graph G 

2019ACM-ICPC沈阳网络赛-C-Dawn-K&#39;s water(完全背包模板题)

Dawn-K's water  1000ms 262144K Dawn-K recently discovered a very magical phenomenon in the supermarket of Northeastern University: The large package is not necessarily more expensive than the small package. On this day, Dawn-K came to the supermarket

2019ACM-ICPC沈阳网络赛-K-Guanguan&#39;s Happy water(思维+暴力)

Guanguan's Happy water 4000ms 262144K Rather than drinking happy water, Guanguan loves storing happy water. So he bought a refrigerator and stored a_iai? bottles of cola into it every day. When the storage is finished on the kk-th day, the refrigerat

2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)

2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a square matrix of n * nn?n, each lattice has its value (nn must be odd), and the center value is n * nn?n. Its spiral decline along the center of the squar

2015长春、沈阳网络赛总结

我所说的总结并不是谈什么题目解法之类的东西 这些东西网上有很多题解 说说这两场网赛吧! 这两场我的状态还行,只是xiaodong还没有找到状态,长春赛lucas+中国剩余定理他硬是打了一整场,还是没打出来,版题没打出来确实不该 wzb状态一般,不过看题的能力依然那么厉害 长春赛中,很遗憾的只出了5道题,按当时过题数目,应该是7道德,可是小东的lucas那题没打出来,而我打得后缀数组那题,当顺时针的时候不用看是否是下标最前面的,但是反过来就需要看了,当时想当然的认为不用,交了4发,一直wa到比赛结

沈阳网络赛G-Spare Tire【容斥】

17.64% 1000ms 131072K A sequence of integer \lbrace a_n \rbrace{an?} can be expressed as: \displaystyle a_n = \left\{ \begin{array}{lr} 0, & n=0\\ 2, & n=1\\ \frac{3a_{n-1}-a_{n-2}}{2}+n+1, & n>1 \end{array} \right.an?=????0,2,23an?1??an?2?

HDU 6205 2017沈阳网络赛 思维题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6205 题意:给你n堆牌,原本每一堆的所有牌(a[i]张)默认向下,每次从第一堆开始,将固定个数的牌(b[i]张)翻上,然后下一堆继续,直到没有足够的牌翻上,然后你可以获得当前已经操作过的堆的所有牌.最初你可以调整堆的顺序,把第一堆放到最后一堆(逆时针旋转),你可以重复这个操作,问你要重复多少次这个操作,才能获得最多的牌. 解法:先把这个序列复制一遍放在原来的序列后面.当i=n的时候结束就可以了,每次

HDU 6200 2017沈阳网络赛 树上区间更新,求和

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6200 题意:给个图,有2种操作,一种是加一条无向边,二是查询u,v之间必须有的边的条数,所谓必须有的边就是对于u,v必须通过这条边才能到达. 解法:一个很简单的想法,搞出图上的一颗树,然后剩下的边当成询问点队加到更新点集,每加入一个更新点对,直接把u,v区间的值置为0即可,查询就直接区间求和,可以直接树剖来维护,简单暴力,读入挂卡过.还有1个log的做法,可以用LCT维护(这个没写,口胡的) #in