Math
文章平均质量分 59
chr1st0pher
Dancer on the keyboard
展开
-
Codeforces 621C. Wet Shark and Flower(数学 + 期望)
Source:http://codeforces.com/problemset/problem/621/CDescriptionThere are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours ...原创 2021-03-02 15:48:36 · 448 阅读 · 0 评论 -
剑指 Offer 64. 求1+2+…+n (二进制)
DescriptionSolution第一眼觉得有点离谱,啥都不让用;突然想到一种只用加减和移位运算符来模拟乘法的方法,核心思想类似快速乘(龟速乘),将乘数进行二进制差分,对被除数进行移位后再相加。Codeclass Solution {public: typedef long long ll; ll mul(ll a,ll b) { ll res = 0, cnt = 0; res += ((a << cnt) & ((b&a原创 2021-02-05 23:08:47 · 105 阅读 · 0 评论 -
2020 ICPC Asia Taipei-Hsinchu Site A.Right-Coupled Numbers(数学)
DescriptionSolution质因数分解Codeint main(int argc, char const *argv[]){ int T;scanf("%d",&T); while(T--) { int x;scanf("%d",&x); bool flag = false; for(int i = 1;i * i <= x;++i) { if(x % i == 0) { int a = i, b = x / i; if(b原创 2020-11-25 21:27:42 · 345 阅读 · 0 评论 -
Codeforces 1454D. Number into Sequence(思维+数学)
DescriptionExampleinput4236049999999374998207083output1232 2 901499999993714998207083Solution显然答案为分解质因数后个数最多的那个质因数的个数,设为k构造成k-1个该因子+1个剩下的数Codemap<ll,int>fac;ll solve(ll n) { ll mx = 0, cnt = 0; fac.clear(); for(ll i = 2;i *原创 2020-11-25 21:16:44 · 369 阅读 · 0 评论 -
2018 BACS Regional Programming Contest M. TFF(数学+暴力)
DescriptionSolution数据范围很小,直接n*m暴力Code#include <bits/stdc++.h>using namespace std;const int mac=2e3+10;int a[mac],b[mac],c[mac],s[mac];int main(int argc, char const *argv[]){ int n; int t,m; scanf ("%d",&t); while (t--){ scanf ("%d原创 2020-11-17 20:13:00 · 137 阅读 · 0 评论 -
2018 BACS Regional Programming Contest E. Diverse Group (组合数)
DescriptionSolution组合数+快速幂即可Codeconst int maxn = 1e7 + 7;const ll mod = 1e9 + 7;ll qpow(ll a, ll n) { a %= mod; ll res = 1; while(n) { if(n&1) res = (res * a) % mod; a = (a * a) % mod; n /= 2; }return res;}ll inv[maxn], s[maxn], sv[原创 2020-11-17 19:46:12 · 147 阅读 · 0 评论 -
2020 CCPC 长春 D. Meaningless Sequence(思维+二进制)
DescriptionExampleinput1000 3output67Solution容易发现ai=cka_i = c^kai=ck(kkk为iii的二进制下1的个数),我们枚举1的位置来判断所有可能值即可统计答案Code#include <bits/stdc++.h>#define pb push_backtypedef long long ll;using namespace std;const int mod = 1e9 + 7;const int ma原创 2020-11-13 15:44:21 · 311 阅读 · 0 评论 -
BZOJ2707 [SDOI2012]走迷宫 【期望DP+高斯消元+tarjan缩点】
DescriptionMorenan被困在了一个迷宫里。迷宫可以视为NNN个点MMM条边的有向图,其中Morenan处于起点SSS,迷宫的终点设为TTT。可惜的是,Morenan非常的脑小,他只会从一个点出发随机沿着一条从该点出发的有向边,到达另一个点。这样,Morenan走的步数可能很长,也可能是无限,更可能到不了终点。若到不了终点,则步数视为无穷大。但你必须想方设法求出Morenan所走步数的期望值。Input第1行4个整数,N,M,S,TN,M,S,TN,M,S,T第[2, M+1]行每行两个原创 2020-06-11 00:23:18 · 884 阅读 · 0 评论 -
牛客算法周周练15 E. 算式子 (筛 + 整除分块)
题目链接Solution显然可以拆成两部分分别计算对于 ∑i=1n⌊aix⌋\sum ^{n}_{i=1}\lfloor \dfrac{a_{i}}{x}\rfloor∑i=1n⌊xai⌋,我们用类似除法分块的思想,枚举x,再枚举ai/xa_i / xai/x,就可以把区间的贡献累加上对于 ∑i=1n⌊xai⌋\sum ^{n}_{i=1}\lfloor \dfrac{x}{a_{i}}\rfloor∑i=1n⌊aix⌋,我们枚举aia_iai,再枚举aia_iai 的倍数利用筛法原创 2020-08-05 19:21:58 · 123 阅读 · 0 评论 -
求乘法逆元方法总结
目录简介扩展欧几里得法IdeaCode快速幂法IdeaCode线性求[1,n]逆元IdeaCode线性求任意n个数的逆元IdeaCode简介若有线性同余方程 ax≡1(mod p)ax\equiv 1\left( mod~p\right)ax≡1(mod p),则称 xxx 为 aaa 在模 ppp 意义下的逆元,记作 a−1a^{-1}a−1扩展欧几里得法Idea原方程 ax≡1(mod p)ax\equiv 1\left( mod~p\right)ax≡1(mod原创 2020-08-04 21:40:21 · 428 阅读 · 1 评论 -
Gym 102091H. As Rich as Crassus (中国剩余定理)
ExamplesInput26 11 195 4 1125 36 716 0 6output56Solution中国剩余定理模板Hint统计答案是时候数据会溢出long long,可以用快速乘避免另:因为x^3会在long long 范围内,所以其实 x 最大不会超过 2212^{21}221故暴力枚举x也可Code#include <bits/stdc++.h>using namespace std;typedef long long ll;ll ex.原创 2020-08-12 19:08:34 · 265 阅读 · 1 评论 -
位运算常见套路(待补充)
x+y=x xor y+((x&y)<<1)x+y=x~xor~y +((x\&y)<< 1)x+y=x xor y+((x&y)<<1)(x and y)+(x or y)== x+y(x~and~y)+(x~or~y)==~x+y(x and y)+(x or y)== x+y原创 2020-11-09 19:57:17 · 143 阅读 · 0 评论 -
ZOJ 3998 Yet Another Data Structure Problem (线段树)
DescriptionSample Input15 51 2 1 2 13 2 41 1 5 23 2 42 1 1 43 1 1Sample Output43216Solution两个tag的线段树 + 欧拉降幂Codell t[maxn << 2], lazy1[maxn << 2], lazy2[maxn << 2];ll a[maxn];ll qpow(ll x,ll n) { ll res = 1; while(n)原创 2020-10-14 17:00:46 · 105 阅读 · 0 评论 -
HDU 2897 邂逅明下 (SG函数打表+规律)
Description当日遇到月,于是有了明。当我遇到了你,便成了侣。那天,日月相会,我见到了你。而且,大地失去了光辉,你我是否成侣?这注定是个凄美的故事。(以上是废话)小t和所有世俗的人们一样,期待那百年难遇的日食。驻足街头看天,看日月渐渐走近,小t的脖子那个酸呀(他坚持这个姿势已经有半个多小时啦)。他低下仰起的头,环顾四周。忽然发现身边竟站着位漂亮的mm。天渐渐暗下,这mm在这街头竟然如此耀眼,她是天使吗?站着小t身边的天使。小t对mm惊呼:“缘分呐~~”。mm却毫不含糊:“是啊,500年一遇哦原创 2020-09-22 21:09:23 · 138 阅读 · 0 评论 -
Codeforces 1407C. Chocolate Bunny (数学 + 交互题)
DescriptionThis is an interactive problem.We hid from you a permutation p of length n, consisting of the elements from 1 to n. You want to guess it. To do that, you can give us 2 different indices i and j, and we will reply with pimodpj (remainder of div原创 2020-09-16 11:46:26 · 558 阅读 · 0 评论 -
Gym 102346L. Less Coin Tosses (数学)
DescriptionSolution根据题目中的分组,大胆猜测答案就是对于给定的n中,Cnm %C_{n}^{m} ~\%Cnm % 2==12 == 12==1 的m个数因为长度为N的01串中有x个1的所有情况下,若情况数为奇数,则就会有一个贡献当 (n & m) == m 时,Cnm %C_{n}^{m} ~\%Cnm % 2==12 == 12==1Codeint main() { ll n;scanf("%lld",&n)原创 2020-08-13 21:00:07 · 300 阅读 · 0 评论 -
Gym 101972J. Even Numbers (数学)
DescriptionYousef loves playing with functions in his free time. Today, he invents the following function:Yousef will give you a list of queries, and you need to find the answers for them. For each query, you are given an integer n, and your task is to原创 2020-08-13 20:51:46 · 195 阅读 · 0 评论 -
Gym 102218K. K-th Missing Digit (Hash / 数论)
DescriptionYou’re given two positive integers A and B, and a string P, representing their product but with a missing digit indicated with an ∗. Find the missing digit.It’s guaranteed that the missing digit isn’t 0.InputThe first line contains three int原创 2020-08-10 20:35:38 · 193 阅读 · 0 评论 -
Codeforces 577B. Modulo Sum (数学 + DP)
DescriptionYou are given a sequence of numbers a 1, a 2, …, a n, and a number m.Check if it is possible to choose a non-empty subsequence a i j such that the sum of numbers in this subsequence is divisible by m.InputThe first line contains two numbers,原创 2020-08-08 21:44:54 · 494 阅读 · 1 评论 -
Codeforces 446C. DZY Loves Fibonacci Numbers (Fibonacci + 线段树)
DescriptionIn mathematical terms, the sequence F n of Fibonacci numbers is defined by the recurrence relationF 1 = 1; F 2 = 1; F n = F n - 1 + F n - 2 (n > 2).DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integer原创 2020-08-07 21:10:16 · 353 阅读 · 0 评论 -
Codeforces 225B. Well-known Numbers (数学)
DescriptionNumbers k-bonacci ( k is integer, k > 1) are a generalization of Fibonacci numbers and are determined as follows:F(k, n) = 0, for integer n, 1 ≤ n < k;F(k, k) = 1;F(k, n) = F(k, n - 1) + F(k, n - 2) + … + F(k, n - k), for integer n, n原创 2020-08-07 20:48:16 · 177 阅读 · 0 评论 -
Codeforces 510D. Fox And Jumping (DP + 裴蜀定理 + 离散化)
DescriptionFox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integers (positive, negative and zero). At the beginning she is standing at the cell 0.There are also n cards, each card has 2 attributes: length l i原创 2020-07-10 19:10:30 · 175 阅读 · 0 评论 -
BZOJ 1441 Min (裴蜀定理)
Description给出n个数(A1…An)现求一组整数序列(X1…Xn)使得S=A1∗X1+...An∗Xn>0S=A1*X1+...An*Xn>0S=A1∗X1+...An∗Xn>0,且S的值最小Input第一行给出数字N,代表有N个数 下面一行给出N个数OutputS的最小值Sample Input24059 -1782Sample Output99Solution裴蜀定理: 对任何整数a,b,ma, b,ma,b,m 和关于未知数xxx和yyy的线性丢番原创 2020-07-10 17:37:41 · 121 阅读 · 0 评论