
数学
不拿牌不改名
ACM刚入门,博客写错了可以留言给我啊
展开
-
GCD+LCM Codeforces Round #641 (Div. 2) C题 Orac and LCM
Orac and LCM题目大意:给 n 个数,先求出所有 lcm(a[i],a[j]),i<j ;然后对新得到的数组所有数求gcd;其实就是要知道这个推论:GCD(LCM(a1,a2),LCM(a1,a3),LCM(a1,a4))==LCM(a1,GCD(a2,a3,a4))预处理出gcd后缀,然后求出每个数的 lcm(a[i],gcd(a[i+1]…a[n])) ,对求的数再做一遍gcd;代码:#include<bits/stdc++.h>#define LL lo原创 2020-09-04 16:49:34 · 336 阅读 · 0 评论 -
基础数学知识学习笔记
一、分解质因数1. 试除法模板:复杂度 O(sqrt(n))void solve(int n){ for(int i=2;i<=n/i;i++){ if(n%i==0){ int sum=0; while(n%i==0){ n/=i; sum++; } cout<<i<<" "<<sum<<endl; } } if(n>1) cout<<n<<" "<<原创 2020-08-26 19:56:46 · 489 阅读 · 1 评论 -
Codeforces Round #619 (Div. 2) C题
Ayoub’s functionAyoub thinks that he is a very smart person, so he created a function f(s), where s is a binary string (a string which contains only symbols “0” and “1”). The function f(s) is equal ...原创 2020-02-14 21:02:36 · 398 阅读 · 0 评论 -
Fractions Again?!(UVA - 10976 )
Fractions Again?!It is easy to see that for every fraction in the form 1k(k > 0), we can always find two positive integersx and y, x ≥ y, such that:1k=1x+1yNow our question is: can you wr...原创 2020-01-07 17:34:58 · 203 阅读 · 0 评论 -
Hello 2020 C题
New Year and PermutationRecall that the permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permu...原创 2020-01-06 22:56:19 · 472 阅读 · 0 评论 -
Codeforces Global Round 6 C题
Diverse MatrixLet a be a matrix of size r×c containing positive integers, not necessarily distinct. Rows of the matrix are numbered from 1 to r, columns are numbered from 1 to c. We can construct an ...原创 2019-12-18 09:22:23 · 221 阅读 · 0 评论 -
Educational Codeforces Round 77 (Rated for Div. 2) C题
C. Infinite FenceYou are a rebel leader and you are planning to start a revolution in your country. But the evil Government found out about your plans and set your punishment in the form of correctio...原创 2019-11-28 23:24:22 · 413 阅读 · 0 评论 -
错排问题
错排问题n个有序的元素应有n!个不同的排列,如若一个排列使得所有的元素不在原来的位置上,则称这个排列为错排;解法一:暴力递归;解法二:推公式当 n 个编号元素放在n个编号位置,元素编号与位置编号各不对应的方法数用 D(n)表示,那么公式为:D(n)=(n−1)∗(D(n−2)+D(n−1)) 特殊地,D(1) = 0, D(2) = 1模板题:模板题...原创 2019-11-09 10:50:28 · 166 阅读 · 0 评论 -
K皇后(洛谷P2105)
K皇后题目描述小Z最近捡到了一个棋盘,他想在棋盘上摆放K个皇后。他想知道在他摆完这K个皇后之后,棋盘上还有多少了格子是不会被攻击到的。(Ps:一个皇后会攻击到这个皇后所在的那一行,那一列,以及两条对角线)输入格式第一行三个正整数 n,m,K,表示棋盘的行列,以及小Z摆放了K个皇后。接下来K行,每行两个正整数x,y,表示这个皇后被摆在了第x行,第y列,数据保证没有任何两个皇后会被摆在同一...原创 2019-10-30 09:38:32 · 884 阅读 · 0 评论 -
Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) C题
p-binaryVasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer p (which may be positive, negative, or zer...原创 2019-10-27 16:44:26 · 1872 阅读 · 0 评论 -
[1007]魔法少女小Scarlet(洛谷 P4924)
[1007]魔法少女小Scarlet题目描述Scarlet最近学会了一个数组魔法,她会在n*nn∗n二维数组上将一个奇数阶方阵按照顺时针或者逆时针旋转90°,首先,Scarlet会把11到n^2n2的正整数按照从左往右,从上至下的顺序填入初始的二维数组中,然后她会施放一些简易的魔法。Scarlet既不会什么分块特技,也不会什么Splay套Splay,她现在提供给你她的魔法执行顺序,想让...原创 2019-10-17 23:33:38 · 824 阅读 · 0 评论 -
天然气井(P1708)
天然气井题目描述Mary试图控制成都的天然气市场。专家已经标示出了最好的天然气井和中转站在成都的地图。现在需要将中转站和天然气井连接起来。每个中转站必须被连接到正好一个钻油井,反之亦然。Mary特别指名,建设的天然气管道必须从某个天然气井开始,向南或者向东建设。Mary想知道怎么连接每个天然气井和中转站,使得需要的天然气管道的总长度最小。输入格式输入文件的第一行为一个正整数n(2<...原创 2019-09-28 14:55:36 · 400 阅读 · 0 评论 -
两个∑符号,两个∏符号运算公式
两个∑符号,两个∏符号运算∑符号的意思是累加,∏符号的意思是累乘;比如两个这种符号怎么运算呢?一个∑i=1ni\sum_{i=1}^{n} i∑i=1ni就是一个累加而已,等于(n+1)∗(n)2\frac{(n+1)*(n)}{2}2(n+1)∗(n),我们可以把∑j=1nj\sum_{j=1}^{n} j∑j=1nj当做常数,提出来,变成了∑j=1nj\sum_{j=1}^{n}...原创 2019-09-16 11:08:10 · 70134 阅读 · 9 评论 -
集合(P1621)
集合题目描述现在给你一些连续的整数,它们是从A到B的整数。一开始每个整数都属于各自的集合,然后你需要进行一下的操作:每次选择两个属于不同集合的整数,如果这两个整数拥有大于等于P的公共质因数,那么把它们所在的集合合并。反复如上操作,直到没有可以合并的集合为止。现在Caima想知道,最后有多少个集合。输入格式一行,三个整数A,B,P。【数据规模】A≤B≤100000;2≤P≤B。...原创 2019-09-12 18:49:46 · 848 阅读 · 0 评论 -
牛客练习赛51(C题 勾股定理)
勾股定理题目描述给出直角三角形其中一条边的长度n,你的任务是构造剩下的两条边,使这三条边能构成一个直角三角形。输入描述:一个整数n。输出描述:另外两条边b,c。答案不唯一,只要输出任意一组即为合理,如果无法构造请输出-1。输入3输出4 5官方题解:对小范围数据进行打表,即可发现存在以下规律:1.当n>2时总有方法可以构造2.当n是奇数总存在两条边b,c使得...原创 2019-09-07 16:15:51 · 311 阅读 · 0 评论 -
Rolling The Polygon(银川区域赛网络赛B题)
Rolling The PolygonBahiyyah has a convex polygon with n vertices P0,P1,⋯,Pn−1 in the counterclockwise order. Two vertices with consecutive indexes are adjacent, and besides, P0 and Pn−1 are adjacent....原创 2019-08-31 20:26:12 · 210 阅读 · 0 评论