
数论及数学
文章平均质量分 75
围巾的ACM
啊啊什么时候也能成为一个大牛啊
展开
-
51nod 1419 最小公倍数挑战(数学)
思路:首先很容易就知道对于n=1,2,3的时候要特判,然后其实就是找三个尽量大的互质的数就是了 n为奇数的时候,由相邻数字一定互质和相邻奇数一定互质可以知道,最优答案肯定是n*(n-1)*(n-2)那么接下来我们只要讨论n为偶数的时候了,首先n和n-1是互质的,但n和n-2是不互质的,所以一个可以考虑的解是n*(n-1)*(n-3),那么n和n-3一定互质吗,答案是不一定的,当n%3==0原创 2017-01-24 15:13:00 · 543 阅读 · 0 评论 -
HDU 4803 Poor Warehouse Keeper(打表找规律)
思路:这个题一眼看上去没什么思路...先把小数据的用BFS打出来了然后直接看出规律来了....#includeusing namespace std;int main(){ int x,y; while(scanf("%d%d",&x,&y)!=EOF) { if(x>y) { printf("-1\n"); continue; } if原创 2016-08-06 21:19:38 · 256 阅读 · 0 评论 -
Codeforces Round #272 (Div. 2) C Dreamoon and Sums(数学)
思路:将式子分母移过去其实就是x = m(kb+1),m是x%b的值,显然m的取值范围是1到b-1,然后先求出m,然后枚举k即可#includeusing namespace std;#define LL long longLL ans = 0;const LL mod = 1e9+7;int main(){ LL a,b; scanf("%lld%lld",&原创 2016-08-27 13:49:10 · 989 阅读 · 0 评论 -
hdu5734 Acperience(数学)
思路:把给的式子展开,然后推推就好了....#includeusing namespace std;typedef long long LL;LL gcd(LL a,LL b){ return a%b==0?b:gcd(b,a%b);}int main(){ int T,n,t; scanf("%d",&T); while(T--)原创 2016-07-21 19:33:55 · 804 阅读 · 0 评论 -
hdu5793 A Boring Question(推公式or迷之找规律)
思路:比赛时候是迷之手玩了很多个样例然后大胆猜测了一发公式...正解:A Boring Question\sum_{0\leq k_{1},k_{2},\cdots k_{m}\leq n}\prod_{1\leq j∑0≤k1,k2,⋯km≤n∏1≤jm(kjkj+1) =\sum_{0\leq k_{1}\l原创 2016-08-04 20:53:03 · 950 阅读 · 0 评论 -
poj2109 Power of Cryptography
思路:看到这个数据范围以为要上高精度了...结果...#include#includedouble n, p;int main(){ while(scanf("%lf%lf", &n, &p) != EOF){ printf("%.0f\n", pow(p, 1/n)); }}DescriptionCurrent原创 2016-07-31 17:41:08 · 314 阅读 · 0 评论 -
poj2891 Strange Way to Express Integers(中国剩余定理)
题意:给出k个模方程组:x mod ai = ri。求x的最小正值。如果不存在这样的x,那么输出-1.思路:中国剩余定理有一个条件是m1,m2...mn必须两两互质,如果不互质怎么办呢?套模板!#include#includeusing namespace std;typedef long long LL;typedef pair PLL;LL a[100000], b[原创 2016-07-31 17:30:58 · 286 阅读 · 0 评论 -
poj1006 Biorhythms(中国剩余定理)
思路:中国剩余定理的裸题#includetypedef long long LL;const int N = 100000 + 5;void ex_gcd(LL a, LL b, LL &x, LL &y, LL &d){ if (!b) {d = a, x = 1, y = 0;} else{ ex_gcd(b, a % b, y, x, d);原创 2016-07-31 17:27:24 · 288 阅读 · 0 评论 -
UVALive 6618 Skycity(数学)
思路:一开始写二分边数一直WA到无法自理...对于给定的圆,和他相切的正多边形的边数越多,正多边形的周长越小。但是因为对每个边长有最小的长度限制,我们可以直接算出来。利用边长的最小限制,我们能求出对应的内角,从而可以找到大于等于该内角度数的边数最小的正多边形。(摘自网上)#include #include #include #include #include using na原创 2016-07-30 23:23:44 · 390 阅读 · 0 评论 -
UVALive 6613 Collision(物理解方程)
思路:设走过的时间为t,那么就有在x方向上走过的路程x+t*vx,y方向上y+t*vy,然后代入圆的方程就可以解出两个根了,判断是不是有反弹也是同理的#include#include#include#includeusing namespace std;int main(){ double Rm,R,r,x,y,vx,vy; while(scanf("%lf%l原创 2016-07-30 23:13:54 · 366 阅读 · 0 评论 -
hdu5753 Permutation Bo(数学)
思路:根据期望的线性性,我们可以分开考虑每个位置对答案的贡献。可以发现当ii不在两边的时候和两端有六种大小关系,其中有两种是对答案有贡献的。那么对答案的贡献就是\frac{c_i}{3}3ci。在两端的话有两种大小关系,其中有一种对答案有贡献。那么对答案的贡献就是\frac{c_i}{2}2ci。复杂度是O(n)O原创 2016-07-26 20:34:27 · 492 阅读 · 0 评论 -
hdu5761 Rower Bo(物理题or瞎猜)
思路:比赛的时候看到样例答案就是8/7,然后猜了几发公式...正解:首先这个题微分方程强解显然是可以的,但是可以发现如果设参比较巧妙就能得到很方便的做法。先分解v_1v1,设船到原点的距离是rr,容易列出方程\frac{ dr}{ dt}=v_2\cos \theta-v_1dtdr=v2cosθ−v1\fra原创 2016-07-26 20:32:01 · 757 阅读 · 0 评论 -
hdu 5762 Teacher Bo(鸽巢原理)
思路:虽然有10^5个点,可是两两曼哈顿距离不会超过2*10^5,所以根据鸽巢原理有复杂度为不会超过2*10^5#includeusing namespace std;#define LL long longconst int maxn = 1e5+7;struct point{ int x, y;}p[maxn];int vis[2*maxn];int Dis原创 2016-07-26 20:28:40 · 469 阅读 · 0 评论 -
Codeforces Round #360 (Div. 2) D. Remainders Game(数学)
思路:满足lcm(c1,c2,c3,...,cn)%k==0就“yes"#includeusing namespace std;#define LL long longLL gcd(LL a,LL b){ if(b==0) return a; return gcd(b,a%b);}LL lcm(LL a,LL b){ return a*b/gcd(a,b);}原创 2016-07-01 16:42:15 · 476 阅读 · 0 评论 -
Codeforces Round #364 (Div. 2) D As Fast As Possible(数学)
思路:如果时间最小 那么最后一定是每个人都同时到达终点,设所有人 走路时间都为t1 搭车时间都为t2,那么车子每次回头去载人的时间就是t3=t2*(v2-v1)/(v2+v1)可以列出(num-1)*( t2 + t3 )*v1+t2*v2=L,t2*v2+t1*v1=L,然后解方程就可以了#includeusing namespace std;double l,v1,v2原创 2016-07-24 20:19:27 · 784 阅读 · 0 评论 -
Codeforces Round #364 (Div. 2) B Cells Not Under Attack(数学)
思路:每放一个棋子影响的就是它所在的行和列嘛,那么标记一下哪一些行和列没有被标记的乘起来就是答案了#includeusing namespace std;#define LL long longconst int maxn = 100000+500;int vis1[maxn],vis2[maxn];int main(){ int n,q; scanf("%d原创 2016-07-24 20:15:30 · 355 阅读 · 0 评论 -
hdu5729 Rigid Frameworks(连通二分图计数dp)
思路:首先这个题你要先知道其实它是求连通的二分图的个数,这个要自己画图慢慢验证....反正我这个智障画了一晚上才搞懂....有n*m个格子,可以不划,向左划,向右划三种选择,那么就有3^(n*m)种可能,然后我们减去不合法的二分图的种数,首先假设我们在n个点固定一个点,这样做可以避免算重,然后在剩下的n-1个点中选择i-1个点,在m个点中选出j个点,那么它们的组合就有C(n-1,i-1)*C(m,原创 2016-07-22 20:26:17 · 735 阅读 · 0 评论 -
HDU 4808 Drunk(数学)
思路:这个题居然高数老师说过...它的公式其实就是x*f(x)的积分/f(x)的积分,f(x)=(r^2-x^2)^(n-1)/2,然后推推就出来了#includeusing namespace std;const int maxn = 2*1e5+7;#define LL long long#define pi acos(-1.0)double si[maxn];voi原创 2016-08-06 21:22:18 · 740 阅读 · 0 评论 -
HDU 4810 Wall Painting(异或数学)
思路:异或的题一般要拆成二进制来看,对于每一位来说有奇数个1的时候才会是1,然后对于每一位算一个组合累加起来就可以了#includeusing namespace std;const int mod = 1e6+3;const int maxn = 1005;int a[maxn],ans[maxn],C[maxn][maxn];int n;#define LL long原创 2016-08-06 21:24:23 · 594 阅读 · 0 评论 -
hdu5478 Can you find it(数学)
思路:通过n=1的时候枚举a求出b,然后通过n=2的时候验证是否成立#includeusing namespace std;#define LL long longLL C,k1,b1,k2;LL qpow(LL x,LL n,LL mod){ LL ans=1; while(n>0) { if(n&1) ans=(ans原创 2016-09-10 08:49:10 · 462 阅读 · 0 评论 -
POJ 3191 The Moronic Cowmpouter (-2进制转换)
思路:这题还是蛮有意思的,-2进制的转换,和2进制其实是差不多的,唯一注意的是如果除-2得出来的余数是负数的话要把它转为正数,同时商+1即可了#include#include#includeusing namespace std;const int maxn = 100000+7;char ans[maxn];int main(){ int n,p=0; scanf(原创 2017-01-23 20:26:31 · 546 阅读 · 1 评论 -
URAL1939 First Seal(公式题)
题意:你坐的车长l,高h,恒定速度v 在走,前面有一道大门,在高H,以速度x恒速下落,你可以选择继续恒速或者以a的减速度继续走,问你是否可以无论选择怎么方式走,门都不会夹到或者碰到你的车思路:如果你以a的减速度走,那么一个关键点就是刚好减速到0的时候恰恰在门的前端点,如果你以恒定速度走,那么一个关键点就是恰好你车全部过了门的右侧,那么就可以列出一条等式,令s1#include#i原创 2017-01-12 19:37:57 · 401 阅读 · 0 评论 -
Codeforces Round #379 (Div. 2) F Anton and School(数学)
思路:转自别人的题解:分析:只要知道a[i]+a[j]=a[i]|a[j]+a[i]&a[j]就好做了,我们令sum=∑ni=1a[i],然后我们会得到c[i]=∑nj=1(a[i]+a[j])−b[i]=n∗a[i]+sum−b[i]即b[i]+c[i]=n∗a[i]+sum然后就可以求出a数组啦,最后我们还要检查一下a数组是否能够使得b,c数组成立。#includeusing原创 2016-11-18 22:00:01 · 1016 阅读 · 0 评论 -
Codeforces Round #382 (Div. 2) D Taxes(数论)
题意:你有n块钱,有两个方式给钱,一种是给n的最大因子,另外一种是把n拆成大于等于2个数,给这些数的最大因子和,求最小的给钱数思路:由哥德巴赫猜想可知,任意一个>2的偶数可以写成两个质数的和,任意一个>7的奇数可以写成3个质数的和,那么把2,3,4,5,6,7的情况写出来,然后判是否素数,然后分情况讨论即可,有一个特别的是如果是>7的奇数要先判n-2是否为素数,如果是的话那么就是2,否则就是3原创 2016-11-29 15:34:17 · 312 阅读 · 0 评论 -
hdu3910 Liang Guo Sha(期望)
思路:将Alice的期望写出来化简之后有E(x)=(pa*(a+b+2c)-b-c)pb-b*pa-c*pa+b 因为Alice与B是否出杀无关,即第一项pb那里的系数为0,所以可以推导出pa*(a+b+2c)-b-c=0,pa为Alice出杀的概率,解出来代会原式即可#includeusing namespace std;int main(){ int a,b,c; wh原创 2016-09-29 09:43:55 · 516 阅读 · 0 评论 -
hdu5894 hannnnah_j’s Biological Test(数学)
题意:n个凳子m个人,每个人至少隔k,问有多少种方案数mod 1e9+7思路:考虑先固定一个人,那么就有剩下m-1个人和n-1张凳子,因为每人之间至少隔k个,那么抽出m*k张凳子,剩下n-1-m*k张凳子分配给m-1个人,那么就是C(n-1-m*k,m-1),因为有n个人,所以乘个n,因为这里的人是没有区别的,所以需要除以m来去掉同样的方案数#includeusing names原创 2016-09-25 21:23:55 · 524 阅读 · 0 评论 -
51nod 1629 B君的圆锥(数学)
思路:把公式推一下就可以了#includeusing namespace std;#define LL long long#define pi acos(-1.0)int main(){ LL s; scanf("%lld",&s); printf("%.6lf\n",1.0*s*sqrt(s/(72*pi)));}B君要用一个表面积原创 2016-09-04 09:01:20 · 406 阅读 · 0 评论 -
2016年湖南省第十二届大学生计算机程序设计竞赛 A 2016(数学)
思路:(a*b)%2016实际上就是(a%2016*b%2016)%2016..根据这个性质枚举余数...开两个数组标记下当余数为i时有多少种选择,然后就可以了#includeusing namespace std;#define LL long longint cnta[2100],cntb[2100];int main(){ int n,m; while(sc原创 2016-09-03 21:51:56 · 873 阅读 · 0 评论 -
hdu5826 physics(物理推公式)
思路:这个题我的推导过程是vt^2-vo^2=2as, s=vt,c=av然后代一下就出来了...并没有积分..不过效果是一样的#include#include#includeusing namespace std;const int N = 100005;struct node{ double v, x, d;}que[N];bool cmp(node a,原创 2016-08-11 21:33:35 · 531 阅读 · 0 评论 -
Codeforces Round #368 (Div. 2) C Pythagorean Triples(构造勾股数)
思路:只需要百度一下勾股数...就有构造方法了...不多说#includeusing namespace std;#define LL long longint main(){ LL n; scanf("%lld",&n); if(n==1 || n==2) { puts("-1"); return 0; } if(n&1) { n原创 2016-08-23 20:45:13 · 411 阅读 · 0 评论 -
CSU 1806 Toll(数学+最短路)
思路:学习了一波辛普森公式求积分 点击打开链接,然后就是套最短路模板就可以了....坑点:是有向图,看成了无向图WA了好多次#includeusing namespace std;#define inf 1e9#define eps 1e-8int n,m,T;struct Node{ int v,c,d; Node(){}; Node(int vv,int cc原创 2016-09-13 17:17:44 · 548 阅读 · 0 评论 -
HDU 5451 Best Solver(数学)
思路:显然无理数是不能取模的,考虑An=(5+2sqrt(6))^n+(5-2sqrt(6))^n显然是一个整数,那么因为0(5+2sqrt(6))^n+(5-2sqrt(6))^n-1其实就是5+2sqrt(6)的整数部分,就是结果了,然后就是求An的递推式了#includeusing namespace std;#define LL long longconst int ma原创 2016-09-01 21:16:00 · 679 阅读 · 0 评论 -
hdu5810 Balls and Boxes(数学)
思路:妈呀数学智障并不知道怎么推...全靠意识...E[V]=E[m∑i=1m(Xi−X¯)2]=E[(Xi−X¯)2]=E[Xi2−2XiX¯+X¯2]= E[X_i^2] - 2\bar XE[X_i] + E[\bar X^2] = E[X_i^2] - 2\bar X^2原创 2016-08-10 00:14:35 · 627 阅读 · 0 评论 -
hdu5874 Friends and Enemies(脑洞题)
思路:这个题目题意坑的不行。。最后强行猜了一波。。正确的题解: nn个点的图, 要求有尽量多的边, 并且不存在三元环. 这个边数就是mm的下界.对于一个nn个结点的没有三元环的图, 边数最大的就是完全二分图. 于是答案就是\lfloor \frac{n}{2} \rfloor \cdot \lceil\frac{n}{2} \rceil⌊2n⌋⋅⌈2原创 2016-09-11 20:56:34 · 1017 阅读 · 0 评论 -
hdu5873 Football Games(数学)
思路:这里是有一个定理的,当s1+s2+....si >= i(i-1) (1#includeusing namespace std;const int maxn = 20000+6;int n,a[maxn];int main(){ int T; while(scanf("%d",&T)!=EOF) { while(T--) { int res =原创 2016-09-11 17:33:53 · 704 阅读 · 0 评论 -
hdu5476 Explore Track of Point(数学)
思路:一道纯平面几何题....显然AM是成立的,然后猜测剩下的是与AB,AC相切的圆的劣弧...就做完了...#includeusing namespace std;double dis(double x1,double y1,double x2,double y2){ return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}int原创 2016-09-10 08:51:02 · 412 阅读 · 0 评论 -
hdu5738 Eureka(数学)
题意:统计平面内有多少个点共线,有重点思路:显然没有重点的时候是个水题,这里统计共线我是用了斜率存进map里面,由于直接除会是double很容易挂,所以直接map,int>这样来处理就可以解决了,然后算一下重点的贡献和不重点的贡献就可以了#includeusing namespace std;const int maxn = 1005;const int mod = 1e9+原创 2016-07-22 17:16:55 · 994 阅读 · 0 评论 -
Educational Codeforces Round 13 C Joty and Chocolate(数学)
思路:有1到n n个数,如果k%a==0,那么给p元,如果k%b==0,那么给q元,如果k%a==0||k%b==0,那么给p元或者q元,问你最多给多少,显然猜一下k%lcm(a,b)=0给max(p,q)就好了#includeusing namespace std;#define LL long longLL gcd(LL a,LL b){ if(b==0) retur原创 2016-06-25 14:59:24 · 931 阅读 · 0 评论 -
Educational Codeforces Round 13 Iterated Linear Function(数学)
思路:推一下公式可以知道其实就是a^n*x+a^(n-1)*b+a^(n-2)*b+....b,就是一个等比数列求和嘛,注意特判1,可是因为范围太大,所以就要用到模乘法以及逆元。 a^(mod) % mod = a a^(mod-1) % mod = 1 a^(mod-2) * a %mod = 1 所原创 2016-06-25 14:44:34 · 584 阅读 · 0 评论 -
CodeForces 567C Geometric Progression
题意:从一个长度为n的序列中,选出3个数,要求l1思路:开两个map分别维护这个数前面和后面的每类数的个数,然后瞎搞搞#includeusing namespace std;const int maxn = 200000+100;#define LL long longmapmark1;mapmark2;LL a[maxn];int main(){ int原创 2016-04-29 20:33:37 · 719 阅读 · 0 评论