走环概率问题(至今有点迷)--牛客第二场( Eddy Walker)

思路:

概率结论题,好像属于线性递推,现在也不太懂(lll¬ω¬)

  1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
  2 #include <cstdio>//sprintf islower isupper
  3 #include <cstdlib>//malloc  exit strcat itoa system("cls")
  4 #include <iostream>//pair
  5 #include <fstream>
  6 #include <bitset>
  7 //#include <map>
  8 //#include<unordered_map>
  9 #include <vector>
 10 #include <stack>
 11 #include <set>
 12 #include <string.h>//strstr substr
 13 #include <string>
 14 #include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
 15 #include <cmath>
 16 #include <deque>
 17 #include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
 18 #include <vector>//emplace_back
 19 //#include <math.h>
 20 //#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
 21 #include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
 22 using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
 23 #define mem(a,b) memset(a,b,sizeof(a))
 24 #define fo(a,b,c) for(a=b;a<=c;++a)//register int i
 25 #define fr(a,b,c) for(a=b;a>=c;--a)
 26 #define pr printf
 27 #define sc scanf
 28 void swapp(int &a,int &b);
 29 double fabss(double a);
 30 int maxx(int a,int b);
 31 int minn(int a,int b);
 32 int Del_bit_1(int n);
 33 int lowbit(int n);
 34 int abss(int a);
 35 //const long long INF=(1LL<<60);
 36 const double E=2.718281828;
 37 const double PI=acos(-1.0);
 38 const int inf=(1<<29);
 39 const double ESP=1e-9;
 40 const int mod=(int)1e9+7;
 41 const int N=(int)1e6+6;
 42 
 43 long long qpow(long long a,long long b,long long mod)
 44 {
 45     long long ans;
 46     a%=mod;
 47     ans=1;
 48     while(b!=0)
 49     {
 50         if(b&1)
 51             ans=(ans*a)%mod;
 52         b/=2;
 53         a=(a*a)%mod;
 54     }
 55     return ans;
 56 }
 57 
 58 int main()
 59 {
 60     int T;
 61     sc("%d",&T);
 62     long long ans=1,res;
 63     while(T--)
 64     {
 65         long long n,m;
 66         sc("%lld%lld",&n,&m);
 67         if(n==1)
 68         {
 69             res=1;
 70         }
 71         else
 72         {
 73             if(m==0)
 74             {
 75                 res=0;
 76             }
 77             else
 78                 res=qpow(n-1,mod-2,mod);
 79         }
 80         ans=ans*res;
 81         ans%=mod;
 82         pr("%lld\n",ans);
 83     }
 84     return 0;
 85 }
 86 
 87 /**************************************************************************************/
 88 
 89 int maxx(int a,int b)
 90 {
 91     return a>b?a:b;
 92 }
 93 
 94 void swapp(int &a,int &b)
 95 {
 96     a^=b^=a^=b;
 97 }
 98 
 99 int lowbit(int n)
100 {
101     return n&(-n);
102 }
103 
104 int Del_bit_1(int n)
105 {
106     return n&(n-1);
107 }
108 
109 int abss(int a)
110 {
111     return a>0?a:-a;
112 }
113 
114 double fabss(double a)
115 {
116     return a>0?a:-a;
117 }
118 
119 int minn(int a,int b)
120 {
121     return a<b?a:b;
122 }

 

posted @ 2019-08-30 19:45  ZMWLxh  阅读(226)  评论(0编辑  收藏  举报