FOJ有奖月赛-2016年8月(daxia专场之过四题方有奖)
http://acm.fzu.edu.cn/contest/list.php?cid=152
主要是a题, lucas定理, 就这一版能过.. 记录一下代码, 另外两个最短路 一个模拟,没什么记录价值.
- //#define txtout
- //#define debug
- #include<cstdio>
- #include<cstring>
- #include<cmath>
- #include<algorithm>
- #include<queue>
- #define mt(a,b) memset(a,b,sizeof(a))
- using namespace std;
- typedef long long LL;
- const double pi=acos(-1.0);
- const double eps=1e-;
- const int inf=0x3f3f3f3f;
- //const int M=1e7+10;
- LL pow_mod (LL a, LL n, LL p) {
- LL ans = ,t = a;
- while (n) {
- if (n & ) {
- ans = ans * t % p;
- }
- t = t * t % p;
- n >>= ;
- }
- return ans;
- }
- LL cal (LL n, LL m, LL p) {
- if(m > n-m) m = n - m;
- LL ans = ;
- for (int i = ; i <= m; i++) {
- ans = ans * (n - i + ) % p;
- int a = pow_mod(i,p-,p);
- ans = ans * a % p;
- }
- return ans;
- }
- LL com_mod (LL n,LL m,LL p) {
- if (n < m)return ;
- return cal(n,m,p);
- }
- LL lucas (LL n, LL m, LL p) {
- LL r = ;
- while(n && m && r) {
- r = r *com_mod(n%p, m%p, p) % p;
- n /= p;
- m /= p;
- }
- return r;
- }
- LL a,d,m,n;
- //int c[M];
- //LL C(int n,int m) {
- // LL result=1;
- // for(int i=0; i<m; i++) {
- // result*=(n-i);
- // }
- // for(int i=0; i<m; i++) {
- // result/=(1+i);
- // }
- // return result;
- //}
- const LL MOD=;
- LL solve() {
- if(n==){
- return a;
- }
- LL answer=lucas(m+n-,n-,MOD)*a%MOD;
- if(n->=) answer+=lucas(m+n-,n-,MOD)*d%MOD;
- answer%=MOD;
- return answer;
- }
- int main() {
- #ifdef txtout
- freopen("in.txt","r",stdin);
- freopen("out.txt","w",stdout);
- #endif // txtout
- // num=sieve(MAXN);
- while(~scanf("%I64d%I64d%I64d%I64d",&a,&d,&m,&n)) {
- printf("%I64d\n",solve());
- }
- return ;
- }
end
FOJ有奖月赛-2016年8月(daxia专场之过四题方有奖)的更多相关文章
- FZU 8月有奖月赛A Daxia & Wzc's problem (Lucas)
Problem A Daxia & Wzc's problem Accept: 42 Submit: 228Time Limit: 1000 mSec Memory Limit : ...
- 2016年12月31日 星期六 --出埃及记 Exodus 21:26
2016年12月31日 星期六 --出埃及记 Exodus 21:26 "If a man hits a manservant or maidservant in the eye and d ...
- 2016年12月30日 星期五 --出埃及记 Exodus 21:25
2016年12月30日 星期五 --出埃及记 Exodus 21:25 burn for burn, wound for wound, bruise for bruise.以烙还烙,以伤还伤,以打还打 ...
- 2016年12月29日 星期四 --出埃及记 Exodus 21:24
2016年12月29日 星期四 --出埃及记 Exodus 21:24 eye for eye, tooth for tooth, hand for hand, foot for foot,以眼还眼, ...
- 2016年12月28日 星期三 --出埃及记 Exodus 21:23
2016年12月28日 星期三 --出埃及记 Exodus 21:23 But if there is serious injury, you are to take life for life,若有 ...
- 2016年12月27日 星期二 --出埃及记 Exodus 21:22
2016年12月27日 星期二 --出埃及记 Exodus 21:22 "If men who are fighting hit a pregnant woman and she gives ...
- 2016年2月16日开始,每天一篇,记录学习心得,【基本技能篇】>>开篇《如何阅读一本书——心得》
如何阅读一本书——心得 ——2016年2月12日 要达到阅读的所有目的,就必须在阅读不同书籍的时候,运用适当的不同速度.读的太快或太慢,都一无所获. 四个阅读层次:①基础阅读,具有基本阅读的能力,包括 ...
- Python array,list,dataframe索引切片操作 2016年07月19日——智浪文档
array,list,dataframe索引切片操作 2016年07月19日——智浪文档 list,一维,二维array,datafrme,loc.iloc.ix的简单探讨 Numpy数组的索引和切片 ...
- c++中变量声明和变量定义的区别。2016年12月6日
整个流程: 1.程序告诉cpu,程序将要使用一个变量.(暂时不一定用到,先说一下.) 2.程序告诉CPU,程序现在就要使用一个变量.(现在就用) 3.cpu按照这个变量的类型,把内存划分出几个单位(b ...
随机推荐
- ORA-600 [Kcbz_check_objd_typ_1] Running a Job (Doc ID 785899.1)
ORA-600 [Kcbz_check_objd_typ_1] Running a Job (Doc ID 785899.1) To Bottom In this Document Symptom ...
- 深入浅出的webpack构建工具---PostCss(五)
一:PostCss是什么? PostCss是一个样式处理工具,它通过自定义的插件和工具生态体系来重新定义css.它鼓励开发者使用规范的css原生语法编写代码,然后配置编译器转换需要兼容的浏览器版本, ...
- Luogu P1962 斐波那契数列(矩阵乘法模板)
传送门(其实就是求斐波那契数列....) 累了 明天再解释 做这道题需要一些关于矩阵乘法的基础知识. 1. 矩阵乘法的基础运算 只有当矩阵A的列数等于矩阵B的行数时,A与B可以相乘(A的行数不一定等于 ...
- win10 + VS2010 + OpenCV2.4.10重编译OpenCV开发环境搭建
win10 + VS2010 + OpenCV2.4.10重编译OpenCV开发环境搭建 重编译的优点:能够调试的时候看OpenCV的源码. 重编译要得到的东西:Debug版本号和Release版本号 ...
- python3 编程使用技巧
from random import randint data = {"Student{}".format(i):randint(60,100) for i in range(1, ...
- Springboot 2.0.4 整合Mybatis出现异常Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
在使用Springboot 2.0.4 整合Mybatis的时候出现异常Property 'sqlSessionFactory' or 'sqlSessionTemplate' are require ...
- python 的zip 函数小例子
In [57]: name = ('Tome','Rick','Stephon') In [58]: age = (45,23,55) In [59]: for a,n in zip (name,ag ...
- python 常见矩阵运算
python 的 numpy 库提供矩阵运算的功能,因此我们在需要矩阵运算的时候,需要导入 numpy 的包. 1.numpy 的导入和使用 from numpy import *;#导入numpy的 ...
- [HAOI2017]方案数[组合计数、容斥、dp]
题意 题目链接 分析 先考虑没有障碍怎么做,定义 f(i,j,k) 每一维走了 i,j,k 位的方案数,转移乘个组合数即可. 现在多了一些障碍,考虑容斥.实际我们走过的点都有严格的大小关系,所以先把所 ...
- for循环两个略骚的写法
骚写法 或许你知道,总之我觉得很酷,希望你也这么认为. 递增遍历 最常见场景,从 0 到 10 的遍历,不输出 10: for(let i = -1; ++i < 10;) { console. ...