C16H:Magical Balls 总时间限制:  1000ms 内存限制:  262144kB 描述 Wenwen has a magical ball. When put on an infinite plane, it will keep duplicating itself forever. Initially, Wenwen puts the ball on the location (x0, y0) of the plane. Then the ball starts to dup…
Problem A Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 463    Accepted Submission(s): 162 Problem Description 度熊手上有一本字典存储了大量的单词,有一次,他把所有单词组成了一个很长很长的字符串.现在麻烦来了,他忘记了原来的字符串都是什么,神奇的是他竟然记得原来那些字符串的…
瞬间移动 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2121    Accepted Submission(s): 949 Problem Description 有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次你都可以选择一个右下方格子,并瞬移过去(如从下图中的红色格子能直接瞬移到蓝色格子),求到第n行第m列的格子有几…
题意:有N个座位,人可以选座位,但选的座位不能相邻,且旋转不同构的坐法有几种.如4个座位有3种做法.\( 1≤N≤1000000000 (10^9) \). 题解:首先考虑座位不相邻的选法问题,如果不考虑同构,可以发现其种数是一类斐波那契函数,只不过fib(1)是1 fib(2)是3. 由于n很大,所以使用矩阵快速幂来求fib. 再者考虑到旋转同构问题,枚举旋转i (2π/n) 度,其等价类即\( gcd(i, n) \)种,那么可以得\[S(n)=\frac{1}{n}\sum_{d|n}^{…
等比式子: Sn=(a1-an*q)/(1-q) n很大,搞一发快速幂,除法不适用于取膜,逆元一下(利用费马小定理) 假如p是质数,且gcd(a,p)=1,那么 a^(p-1)≡1(mod p).刚好在本道题目一样适用,mod=1e9+7就是质数,那么gcd也就是=1,OK,那么b*k=1 这个逆元就等于 a^(mod-2); #include <cstdio> #include <stack> #include <iostream> #include <stri…
题目地址:https://www.nowcoder.com/acm/contest/136/F 树状数组.快速幂.逆元的模板运用: #include<iostream> #include<cstdio> using namespace std; #define LL long long #define lowbit(x) x&-x ; ; int n, m; LL sum[N]; void read(int &x) { ; x = ; char ch = getch…
题目地址:https://www.nowcoder.com/acm/contest/136/J 解法一: 推数学公式求前n项和: 当k=1时,即为等差数列,Sn = n+pn(n−1)/2 当k≠1时,an+p/(k−1) = k(an−1+p/(k-1)),等比数列,Sn = (kn+1+(p−1)kn−(np+1)k+(n−1)p+1) / ((k-1)*(k-1)) 因为是除法取模,故除快速幂外还需逆元: Knowledge Point: 除法取模逆元:https://www.cnblog…
A Boring Question 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5793 Description Input The first line of the input contains the only integer T, Then T lines follow,the i-th line contains two integers n,m. Output For each n and m,output the answer i…
J-Super Sum 题目大意就是给定N个三元组<a,b,c>求Σ(a1^k1*a2^k2*...*ai^ki*..an^kn)(bi<=ki<=ci) 唉.其实题目本身不难的,怪我不知道当时怎么想的...本来观察式子很容易能得出结论: 比如<5,2,3>,<2,1,4>,<3,2,2>这组: 5^2*2^1*3^2+5^2*2^2*3^2+5^2*2^3*3^2+5^2*2^4*^32=5^2*(2^1+2^2+2^3+2^4)*3^2; 5…
Sumdiv Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16466   Accepted: 4101 Description Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S modulo 9901 (the rest of the division of S by 99…
E - The Boss on Mars Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4059 Description On Mars, there is a huge company called ACM (A huge Company on Mars), and it’s owned by a younger boss. Due…
题目链接:https://codeforces.com/problemset/problem/785/D 题解: 首先很好想的,如果我们预处理出每个 "(" 的左边还有 $x$ 个 "(",以及右边有 $y$ 个 ")",那么就有式子如下: ① 若 $x+1 \le y$:$C_{x}^{0} C_{y}^{1} + C_{x}^{1} C_{y}^{2} + \cdots + C_{x}^{x} C_{y}^{x+1} = \sum_{i=0}…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1965 题意: 对于扑克牌的一次洗牌是这样定义的,将一叠N(N为偶数)张扑克牌平均分成上下两叠,取下面一叠的第一张作为新的一叠的第一张,然后取上面一叠的第一张作为新的一叠的第二张,再取下面一叠的第二张作为新的一叠的第三张……如此交替直到所有的牌取完. 如果对一叠6张的扑克牌1 2 3 4 5 6,进行一次洗牌的过程如下图所示: 游戏是这样的,如果给定长度为N的一叠扑克牌,并且牌面大小从1开…
[题目大意] 若用F[i][j]来表示矩阵中第i行第j列的元素,则F[i][j]满足下面的递推式:F[1][1]=1F[i,j]=a*F[i][j-1]+b (j!=1)①F[i,1]=c*F[i-1][m]+d (i!=1)②递推式中a,b,c,d都是给定的常数.求F[n][m]. [思路] 磨了一个早上,然而UOJ上的额外数据还没有过去..BZOJ上已AC先放上来,后续慢慢磨…… *还有一点,最后输出答案的时候要先+MOD再%MOD. *MOD要勤快一点,不然会爆. #include<ios…
#include <iostream> #include <algorithm> #include <string> #define MOD 1000000007 using namespace std; long long quick_pow(long long a, long long b, long long c){ ; a = a%c; ){ == ){ ans = (ans*a) % c; } b = b / ; a = (a*a) % c; } return…
题目描述 给定一个多项式(by+ax)^k,请求出多项式展开后x^n*y^m 项的系数. 输入输出格式 输入格式: 输入文件名为factor.in. 共一行,包含5 个整数,分别为 a ,b ,k ,n ,m,每两个整数之间用一个空格隔开. 输出格式: 输出共1 行,包含一个整数,表示所求的系数,这个系数可能很大,输出对10007 取模后的结果. 输入输出样例 输入样例#1: 1 1 3 1 2 输出样例#1: 3 说明 [数据范围] 对于30% 的数据,有 0 ≤k ≤10 : 对于50% 的…
1.gcd int gcd(int a,int b){ return b?gcd(b,a%b):a; } 2.扩展gcd )extend great common divisor ll exgcd(ll l,ll r,ll &x,ll &y) { if(r==0){x=1;y=0;return l;} else { ll d=exgcd(r,l%r,y,x); y-=l/r*x; return d; } } 3.求a关于m的乘法逆元 ll mod_inverse(ll a,ll m){ l…
原题:ZOJ 3774  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3774 ---------------------------------------------------------------------------------------------------------------------- 这题比较复杂,看这篇比较详细:http://blog.csdn.net/acdreamers/artic…
A Boring Question Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 156    Accepted Submission(s): 72 Problem Description       Input   The first line of the input contains the only integer T,(1≤T…
题目:传送门. 题意:t组数据,每组给定n,m,k.有n个格子,m种颜色,要求把每个格子涂上颜色且正好适用k种颜色且相邻的格子颜色不同,求一共有多少种方案,结果对1e9+7取余. 题解: 首先可以将m 与后面的讨论分离.从m 种颜色中取出k 种颜色涂色,取色部分有C(m, k) 种情况: 然后通过尝试可以发现,第一个有k种选择,第二个因不能与第一个相同,只有(k-1) 种选择,第三个也只需与第二个不同,也有(k-1) 种选择.总的情况数为k ×(k-1)^(n-1).但这仅保证了相邻颜色不同,总…
题意: 给出n次翻转和m张牌,牌相同且一开始背面向上,输入n个数xi,表示xi张牌翻转,问最后得到的牌的情况的总数. 思路: 首先我们可以假设一开始牌背面状态为0,正面则为1,最后即是求ΣC(m,k),k为所有能取到1的情况.首先我们要确认最后1的奇偶性.因为一次翻转0->1,或者1->0,则最后所有1的情况的奇偶性相同.然后我们要找到最小的1的个数i和最大的1的个数j,i为能翻1则翻1,j为能翻0则翻0,介于中间的情况是取偶数步数,一半翻1,一半翻0,保持1的个数不变.那么k为(i<=…
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1004 共n个卡片,染成r,b,g三种颜色,每种颜色的个数有规定.给出一些置换,可以由置换得到的染色方案视为等价的,求等价类计数. 分析 给出置换求等价类计数,用Burnside引理:等价类计数=(每一个置换不动点的和)/置换数.(不知道的建议去看白书) 其中不动点是指一个染色方案经过置换以后染色与之前完全相同. 1.求不动点个数. 不动点的话同一个循环内的每一个点的颜色必须相同(否则不同颜色…
Problem Description Considera positive integer X,and let S be the sum of all positive integer divisors of2004^X. Your job is to determine S modulo 29 (the rest of the division of S by29). Take X = 1 for an example. The positive integer divisors of 20…
方便复制 快速乘/幂 时间复杂度 \(O(\log n)\). ll nmod; //快速乘 ll qmul(ll a,ll b){ ll l=a*(b>>hb)%nmod*(1ll<<hb)%nmod; ll r=a*(b&((1<<hb)-1))%nmod; return (l+r)%nmod; } //快速幂 ll qpow(ll a,ll b){ ll res=1; while(b){ if(b&1)res=res*a%nmod; a=a*a%n…
It is said that a dormitory with 6 persons has 7 chat groups ^_^. But the number can be even larger: since every 3 or more persons could make a chat group, there can be 42 different chat groups. Given N persons in a dormitory, and every K or more per…
题目来源 The 2018 ACM-ICPC China JiangSu Provincial Programming Contest 35.4% 1000ms 65536K Persona5 Persona5 is a famous video game. In the game, you are going to build relationship with your friends. You have N friends and each friends have his upper b…
A/B Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10383    Accepted Submission(s): 8302 Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1).   Input 数据的第一行是…
题目链接:https://vjudge.net/problem/POJ-1845 题意:求A的B次方的所有因子(包括1)的和对9901的模. 思路:首先对A利用唯一分解定理得A=p1x1*p2x2*...*pnxn,则A^B=p1B*x1*p2B*x2*...*pnB*xn.且其所有因子的和等于: (1+p11+...+p1B*x1)*(1+p21+...+p2B*x2)*...*(1+pn1+...+pnB*xn). 对其中的1+pi1+...+piB*xi,可以用等比数列的求和公式来计算,即…
是2017江苏省赛的第一题,当时在场上没做出来(废话,那个时候又不懂高斯消元怎么写……而且数论也学得一塌糊涂,现在回来补了) 省赛结束之后,题解pdf就出来了,一看题解,嗯……加一行再求逆矩阵从而得到伴随矩阵从而得到答案,emmmmm真是非常通俗易懂呢! 于是在回学校的路上强行回忆上学期学的线性代数,把这题题解的原理想通了,然后到现在把高斯消元法补了,才把这题做出来…… #include<cstdio> #include<algorithm> #define MAXN 205 #d…
Description Mr. Mindless has many balls and many boxes,he wants to put all the balls into some of the boxes.Now, he wants to know how many different solutions he can have. you know,he could put all the balls in one box,and there could be no balls in…