UVa 11174 - Stand in a Line
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2115
数学的特点在于不断的推导,此题还需要用到
欧拉定理和逆元的相关性质,推荐博客(有部分小错误):http://www.cnblogs.com/vongang/archive/2013/06/04/3117370.html
代码:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>#define ll long long
using namespace std;const ll MOD=1000000007;
const int N=100005;
ll power(ll x,ll y)
{ll tmp=1;while(y){if(y&1)tmp=tmp*x%MOD;x=x*x%MOD;y=y>>1;}return tmp;
}
int num[N],f[N],sum[N];
queue<int>qt;
int main()
{//freopen("data.in","r",stdin);int T;cin>>T;while(T--){int n,m;cin>>n>>m;memset(num,0,sizeof(num));memset(sum,0,sizeof(sum));memset(f,0,sizeof(f));while(!qt.empty()) qt.pop();while(m--){int a,b;cin>>a>>b;++num[b];f[a]=b;}for(int i=1;i<=n;++i)if(num[i]==0)qt.push(i);ll x=1,y=1;while(!qt.empty()){int i=qt.front();qt.pop();++sum[i];y=y*sum[i]%MOD;sum[f[i]]+=sum[i];if((--num[f[i]])==0)qt.push(f[i]);}for(int i=1;i<=n;++i)x=x*i%MOD;cout<<(x*power(y,MOD-2))%MOD<<endl;}return 0;
}
转载于:https://www.cnblogs.com/liulangye/p/3175284.html
UVa 11174 - Stand in a Line相关推荐
- UVA 12657 Boxes in a Line
题目链接:https://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&page=show_proble ...
- uva 11174(排列组合+搜索)
依然是liurujia计数练习题.依然是自己想没想出来,在MOD是素数的情况下除以x即为乘x的逆.这个真心以前没听过,用了这个方法后处理就变得十分巧妙. 整个程序步骤还是很清晰的,先上来算阶乘与逆(求 ...
- UVa 12657 - Boxes in a Line ( 双向链表 )
题意 你有一行盒子,从左到右依次编号为1, 2, 3,-, n.可以执行以下4种指令: 1 X Y表示把盒子X移动到盒子Y左边(如果X已经在Y的左边则忽略此指令). 2 X Y表示把盒子X移动到盒子Y ...
- Uva 12657 Boxes in a Line 双向链表
操作4比较特殊,为了避免一次性修改所有元素的指针,由于题目只要求输出奇数盒子的编号,所以我们可以灵活的根据是否进行过操作4对操作1 操作2 进行改动 操作3不受操作4影响 上代码.... #inclu ...
- hdoj 5199 Gunner map
Gunner Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5199 D ...
- CodeChef--EQUAKE
题目链接 Earthquake in Bytetown! Situation is getting out of control! All buildings in Bytetown stand on ...
- ACM训练赛--递推专题
1001: Buy the Ticket Problem Description The "Harry Potter and the Goblet of Fire" will be ...
- hdu 5199 Gunner(STL之map,水)
Problem Description Long long ago, there is a gunner whose name is Jack. He likes to go hunting very ...
- Mind Control CodeForces - 1291C(思维)
You and your n−1n−1 friends have found an array of integers a1,a2,-,ana1,a2,-,an. You have decided t ...
最新文章
- jQuery.append()、jQuery.html()存在的XSS漏洞
- jQuery选择器的工作原理和优化
- groupadd - 建 立 新 群 组
- C语言SQLite3基本操作Demo
- TABLES ABOUT CRM MARTETING
- java标识符 width_width(宽度)
- git 本地重新关联新的远程仓库命令/查看本地关联远程仓库
- Java-idea-生成for循环
- Linux内核深入理解中断和异常(1)
- AI何时能懂环境会沟通?别急,这个“你说我画”小游戏开了个好头 | 论文
- 【TSP】基于matlab GUI蚁群算法求解旅行商问题【含Matlab源码 929期】
- python字典统计排序1_python笔记17-字典如何按value排序
- Python——公司又双叒叕更新通讯录了,利用itchat实现微信速查公司通讯录
- Dos 模拟器 DosBox 下载使用
- 模式识别属于计算机科学吗,模式识别与智能系统这个学科属于什么类?
- JS—— 常用图片后缀正则校验
- 微信公众号信息推送实现业务解耦
- 美国软件供应链安全行动中的科技巨头们
- vue下载大文件时浏览器不显示下载进度
- 发疯的腾讯微博邀请码
热门文章
- 2021-2027年中国手机壳行业现状研究及发展趋势分析报告
- SVN优化(一) SVN忽略maven项目的target
- liunx上mysql源码安装mysql,搞定linux上MySQL编程(一):linux上源码安装MySQL
- 机房收费系统【VB版】——前期准备
- mysql engine innodb myisam 区别
- 运行一段时间后,RestTemplate请求报400错误
- LeetCode简单题之二叉搜索树的最小绝对差/最小距离
- k8s核心组件详细介绍教程(配超详细实例演示)
- 2021年大数据Spark(五):大环境搭建本地模式 Local
- python时区转换_在python 不同时区之间的差值与转换方法