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

    1430: 小猴打架

    Time Limit: 5 Sec  Memory Limit: 162 MB
    Submit: 328  Solved: 234
    [Submit][Status]

    Description

    一开始森林里面有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}六种不同的打架过程。

    Input

    一个整数N。

    Output

    一行,方案数mod 9999991。

    Sample Input

    4

    Sample Output

    96

    HINT

    50%的数据N<=10^3。
    100%的数据N<=10^6。

    Source

    题解:

    水题。。。

    n个点不同形态的生成数有n^(n-2)个,然后打架过程还分先后相当于全排列

    所以 ans=n^(n-2) * (n-1)!

    代码:

     1 #include<cstdio>
     2 
     3 #include<cstdlib>
     4 
     5 #include<cmath>
     6 
     7 #include<cstring>
     8 
     9 #include<algorithm>
    10 
    11 #include<iostream>
    12 
    13 #include<vector>
    14 
    15 #include<map>
    16 
    17 #include<set>
    18 
    19 #include<queue>
    20 
    21 #include<string>
    22 
    23 #define inf 1000000000
    24 
    25 #define maxn 500+100
    26 
    27 #define maxm 500+100
    28 
    29 #define eps 1e-10
    30 
    31 #define ll long long
    32 
    33 #define pa pair<int,int>
    34 
    35 #define for0(i,n) for(int i=0;i<=(n);i++)
    36 
    37 #define for1(i,n) for(int i=1;i<=(n);i++)
    38 
    39 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
    40 
    41 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
    42 
    43 #define mod 9999991
    44 
    45 using namespace std;
    46 
    47 inline int read()
    48 
    49 {
    50 
    51     int x=0,f=1;char ch=getchar();
    52 
    53     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    54 
    55     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
    56 
    57     return x*f;
    58 
    59 }
    60 
    61 int main()
    62 
    63 {
    64 
    65     freopen("input.txt","r",stdin);
    66 
    67     freopen("output.txt","w",stdout);
    68 
    69     ll n=read(),ans=1;
    70     for1(i,n-2)ans=(ans*n)%mod;
    71     for1(i,n-1)ans=(ans*i)%mod;
    72     printf("%lld
    ",ans);
    73 
    74     return 0;
    75 
    76 }
    View Code
  • 相关阅读:
    syslog日志格式解析
    Linux打补丁的一个简单例子
    Linux打补丁的一些问题
    安全漏洞整改解决方案(很不错网络文章)
    Linux系统启动过程
    chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息
    主机名/etc/hosts文件的作用
    Linux中如何配置IP相关文件
    /bin、/sbin、/usr/bin、/usr/sbin目录Linux执行文档的区别
    日志生成控制文件syslog.conf
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/3992623.html
Copyright © 2011-2022 走看看