白书 4.1.2 模运算的世界 P291】的更多相关文章

1.逆元 这里有个注意事项要说,就是当要求 (a-b)%m 的时候要注意不能直接 (a%m-b%m)%m 原因是得出的值有可能是负数,所以 (a%m-b%m+m)%m 才是正确的. //x,y是引用 int exgcd(int a,int b,int &x,int &y){ //d是最后要返回的 int d=a; ){ //递归时,y和x也要换 d=exgcd(b,a%b,y,x); //根据x求y y-=(a/b)*x; }else{ x=;y=; } return d; } //求逆元…
题目大意:起重机有n节,题目给出要调节的k节,每节调节成x度,求最后底部的起重机的坐标(最顶上的起点为(0,0)). 分析:一开始我看白书,看不懂他那个向量旋转的坐标是怎么来的,翻了很多博客,才发现,是自己数学基础的遗漏(都怪自己高中没好好学T.T),向量旋转涉及到复数的概念和表达. 首先复数表达式z=x+i*y=|z|*(cosx+i*sinx)(i²=-1),假设两个个复数分别为 z1=x1+y1*i=r1*(cos(p1)+i*sin(p1)) z2=x2+y2*i=r2*(cos(p2)…
一.mysql中的优化 where语句的优化 1.尽量避免在 where 子句中对字段进行表达式操作select id from uinfo_jifen where jifen/60 > 10000;优化后:Select id from uinfo_jifen where jifen>600000; 2.应尽量避免在where子句中对字段进行函数操作,这将导致mysql放弃使用索引 select uid from imid where datediff(create_time,'2011-11…
题目:An Easy Problem! 题意:求给出数的最小进制. 思路:暴力WA: discuss中的idea: 给出数ABCD,若存在n 满足 (A* n^3 +B*n^2+C*n^1+D*n^0)%(n-1) == 0 则((A* n^3)%(n-1) +(B*n^2)%(n-1)+(C*n^1)%(n-1)+D%(n-1))%(n-1) == 0             (A+B+C+D)%(n-1) == 0 NB! 是时候深入的看下数论了: 模运算法则: 模运算与基本四则运算有些相似…
取模运算 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10931   Accepted: 6618 Description 编写一个C函数mod(int n, int m),实现取模运算% Input 输入包含多行数据 每行数据是两个整数a, b (1 <= a, b <= 32767) 数据以EOF结束 Output 于输入的每一行输出a%b Sample Input 5 3 100 2 Sample Output…
在数学里,"模运算"也叫"求余运算",用mod来表示模运算. 对于 a mod b 可以表示为 a = q(商)*b(模数) + r(余数),其中q表示商,b表示模数且 b != 0,那么余数 r 满足 0 <= |r| < |b|. 如果a和b都是自然数,那么r肯定大于等于0且小于b的整数,如果a和b有一个是负数,那么r就不唯一.例如: (-3) % 2 : -3 = (-2)*2 + 1,余数是1:-3 = (-1)*2 - 1 ,余数是-1 (-9…
白书P61 - 点集配对问题 状压DP #include <iostream> #include <cstdio> #include <cstring> using namespace std; #define INF 0x3f3f3f3f struct Point { double x,y,z; }p[+]; int n; <<)+]; //dp[j]表示j对应状态(0为未配对,1为配对了)的最小距离和 double dist(int i,int j) {…
白书P60 - 硬币问题 完全背包.DP #include <iostream> #include <cstdio> #include <cstring> using namespace std; #define INF 0x3f3f3f3f #define N 1010 int n,s; int w[N]; //w表示n种硬币的面值 int dp1[N]; //dp1[j]表示刚好凑足j的最少硬币数 int dp2[N]; //dp2[j]表示刚好凑足j的最多硬币数…
1.POJ 1150 The Last Non-zero Digit #质因数分解+模运算分治# 先贴两份题解: http://www.hankcs.com/program/algorithm/poj-1150-the-last-non-zero-digit.html http://www.cppblog.com/abilitytao/archive/2009/10/31/99907.html 下面是自己看完题解(划掉)之后的理解: 题目要求出组合数Anm=n!/(n-m)!(说实话一开始不知道…
白书的一道水题.话说好久没认真做难题了.今天出了排名,所有队伍里倒数第一啊! 代码没什么可说的了. #include <algorithm> #include <cstring> #include <ctype.h> #include <cstdlib> #include <cstdio> #include <vector> #include <string> #include <queue> #include…