zoukankan      html  css  js  c++  java
  • 小猴打架

    题目描述

    一开始森林里面有N只互不相识的小猴子,它们经常打架,但打架的双方都必须不是好朋友。每次打完架后,打架的双方以及它们的好朋友就会互相认识,成为好朋友。经过N-1次打架之后,整个森林的小猴都会成为好朋友。
    现在的问题是,总共有多少种不同的打架过程。
    比如当N=3时,就有{1-2,1-3}{1-2,2-3}{1-3,1-2}{1-3,2-3}{2-3,1-2}{2-3,1-3}六种不同的打架过程。

    输入

    一个整数N。

    输出

    一行,方案数mod 9999991。看好模数

    样例输入

    4

    样例输出

    96

    提示

    50%的数据N<=10^3。
    100%的数据N<=10^6。
    题目分析在代码下面

    #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
    #pragma GCC optimize("Ofast")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize (2)
    #pragma G++ optimize (2)
    #include <bits/stdc++.h>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #include <string>
    #include <vector>
    using namespace std;
    #define wuyt main
    typedef long long ll;
    #define HEAP(...) priority_queue<__VA_ARGS__ >
    #define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
    template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
    template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
    //#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
    //char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
    ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
    if(c == '-')Nig = -1,c = getchar();
    while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
    return Nig*x;}
    #define read read()
    const ll inf = 1e15;
    const int maxn = 3e5 + 10;
    const int mod = 1e9 + 7;
    #define start int wuyt()
    #define end return 0
    ll num[maxn],ans=1;
    ll n,m;
    ll a[maxn],s[maxn];
    const ll number = 9999991;
    start{
        int n=read;
        for(int i=1;i<=n-2;i++)
            ans=(ans*n)%number;
        for(int i=1;i<=n-1;i++)
            ans=(ans*i)%number;
        cout<<ans<<endl;
    	end;
    }
    
    

    来自博客园的截图(侵删)
    原文链接:
    https://www.cnblogs.com/withhope/p/11838778.html
    在这里插入图片描述
    答案是
    (n-1)!*nn-2 %9999991
    两个for循环

  • 相关阅读:
    《Twinkle Twinkle Little Star》
    《牛客IOI周赛24-普及组B》
    You have to remove (or rename) that container to be able to reuse that name.
    MySQL查看服务器状态、数据库、表的命令
    【用户不在sudoers文件中】的两种解决方式
    Ubuntu20.04安装Docker时摊上的那些事儿
    Ubuntu20.04安装Docker以后设置阿里云镜像加速
    Ubuntu20.04默认更新源sources.list和第三方源推荐(干货!)
    Ubuntu必备软件之搜狗输入法
    Ubuntu20.04必备软件之截图工具
  • 原文地址:https://www.cnblogs.com/PushyTao/p/13144216.html
Copyright © 2011-2022 走看看