随笔分类 -  数学/算术几何

摘要:假设删除第k位,把整数A表示成如下形式:A = a * 10^(k+1) + b * 10 ^k + c;则: B = a * 10^k + c;N = A + B = (11*a+b)*10^k + 2*c;显然:11*a+b = N / (10^k)2*c = N % (10^k)但是c有可能产生进位,产生的影响为:11*a+b+1 = N/(10^k)【b+1最多为10,不会影响到11*a的值】2*c = N % (10^k) + 10^k;把这两种情况分别考虑一下。注意一下细节:1.a和b不能同时为零2.b的取值范围是0~9,如果b的值等于10,一定是产生进位的情况#include # 阅读全文
posted @ 2013-10-31 19:40 冰鸮 阅读(233) 评论(0) 推荐(0)
摘要:与其说这是个博弈,倒不如说是个搜索。这题思路不错,感觉很难把情况考虑周全。在地图外围填充一圈0,两次BFS,第一次从-1点出发,把从-1到达的0点以及包围0的那一圈石头标记出来。如下图:6 71 1 1 1 1 1 11 0 0 0 0 0 11 0 3 5 1 1 11 0 -1 4 0 1 11 0 1 0 0 1 11 1 1 1 1 1 1第二次BFS,从外围(0,0)点出发,找出外面与标记石头的交界层:6 71 1 1 1 1 1 11 0 0 0 0 0 11 0 3 5 1 1... 阅读全文
posted @ 2013-09-25 10:48 冰鸮 阅读(286) 评论(0) 推荐(0)
摘要:《训练指南》p.108#include #include #include using namespace std;const int MOD = 1000007;const int MAXN = 500;int C[MAXN][MAXN];void init(){ memset( C, 0, sizeof(C) ); C[0][0] = 1; for ( int i = 0; i < MAXN; ++i ) { C[i][0] = C[i][i] = 1; for ( int j = 1; j < i; ++j ) C[i][... 阅读全文
posted @ 2013-09-11 21:42 冰鸮 阅读(187) 评论(0) 推荐(0)
摘要:参考了:http://www.cnblogs.com/zhsl/archive/2013/08/10/3250755.htmlhttp://blog.csdn.net/chaobaimingtian/article/details/9852761题意:一个有n个节点的树,每个节点存有一份独一无二的信息,要求用最小的步数,把每个节点的信息共享给所有的节点。一个节点把自己所包含的所有信息传递给相邻的一个节点为一步。题目不是求最小的步数,而是问最小的步数下,信息传递的方法有多少种。分析:最小步数:所有节点把信息传给同一个节点,再由这个节点传给其他节点。因此最小步数为树边数的2倍,即2*(n-1)。我 阅读全文
posted @ 2013-09-10 18:39 冰鸮 阅读(616) 评论(0) 推荐(0)
摘要:《训练指南》p.125设f[n] = gcd(1, n) + gcd(2, n) + …… + gcd(n - 1, n);则所求答案为S[n] = f[2]+f[3]+……+f[n];求出f[n]即可递推求得S[n]:S[n] = S[n - 1] + f[n];所有gcd(x, n)的值都是n的约数,按照约数进行分类,令g(n, i)表示满足gcd(x, n) = i && x #include #include #include #define LL long long intusing namespace std;const int MAXN = 4000100;LL 阅读全文
posted @ 2013-09-05 21:47 冰鸮 阅读(207) 评论(0) 推荐(0)
摘要:构造矩阵.见《训练指南》p156...#include #include #include #define LL long long intusing namespace std;const int MAXN = 20;LL mod;struct Matrix{ LL a[MAXN][MAXN]; int r, c; friend Matrix operator*( Matrix &a, Matrix &b ); friend Matrix operator^( Matrix a, LL k );};Matrix operator*( Matrix &a, Matrix 阅读全文
posted @ 2013-09-05 09:15 冰鸮 阅读(258) 评论(0) 推荐(0)
摘要:pick定理:一个计算点阵中顶点在格点上的多边形面积公式:S=a+b÷2-1,其中a表示多边形内部的点数,b表示多边形边界上的点数,s表示多边形的面积。思路:http://blog.csdn.net/magicnumber/article/details/6192242#include #include #include #include #define LL long long intusing namespace std;const int MAXN = 1000100;const LL dx[] = { 0, -1, -1, -1, 0, 1, 1, 1 };const LL 阅读全文
posted @ 2013-08-13 10:57 冰鸮 阅读(243) 评论(0) 推荐(0)
摘要:解法参考:http://blog.csdn.net/a601025382s/article/details/9840125#include #include #include #include using namespace std;#define LL long long intconst int MAXN = 1000010;const LL MOD = (1e9) + 7;int n;LL a[MAXN];LL b[MAXN];void ExGcd( LL a, LL b, LL& d, LL& x, LL& y ){ if ( !b ) { d = a, x = 阅读全文
posted @ 2013-08-09 17:11 冰鸮 阅读(273) 评论(0) 推荐(0)
摘要:显然正着倒着看仍然是数字的只有7个数:0,1,2,5,6,8,9所以就是用这7个数组合成不同的数。将n转换成7进制,对应位输出即可。#include #include #include #include using namespace std;const char num[] = "0125986";const int MAXN = 1010;const int BASE = 7;char str[MAXN];int a[MAXN];int b[MAXN];int ans[MAXN];int cnt, len;bool check(){ for ( int i = 0; i 阅读全文
posted @ 2013-08-09 16:27 冰鸮 阅读(310) 评论(0) 推荐(0)
摘要:没有任何变换(III变U和删UU操作)之前,I 的个数一定是2^x个(也就是2的整数次幂)若仅考虑III变U,那么设U的个数为k,I 的个数变为2^x-3*k再加上删除UU操作,假设我们删除了2*n个U,设实际U的个数为cntU, 则k=cntU+2*n设 I 的实际个数为cntI,cntI = 2^x - 3*(cntU+2*n), n有解的情况为:( 2^x - 3*cntU - cntI ) % 6 == 0只要找到一个x满足这个条件即可,不过要注意( 2^x - 3*cntU - cntI )>=0,因为 -6%6 = 0,之前没有判断这里,WA的很惨…… 1 #include 阅读全文
posted @ 2013-08-08 19:01 冰鸮 阅读(609) 评论(0) 推荐(0)
摘要:官方题解:题意转化一下就是:给出一列数a[1]...a[n],求长度最长的一段连续的数,使得这些数的和能被M整除。分析:设这列数前i项和为s[i],则一段连续的数的和 a[i]+a[i+1]+...+a[j-1]+a[j]=s[j]-s[i-1],所以这段连续的数的和能被m整除的条件就是 (s[j]-s[i-1]) % m == 0,即 s[j]%m-s[i-1]%m == 0,因此,只需要每一个余数找使s[i]%m等于该余数的最小的i,和s[j]%m等于该余数的最大的j,相减即为最长的连续的数的长度。i 要从1开始,不然会WA。#include #include #include #incl 阅读全文
posted @ 2013-08-07 21:32 冰鸮 阅读(219) 评论(0) 推荐(0)
摘要:题意:给一些n,求出最小的只包含0,1的n的倍数设两数a, b满足: a #include #include #include using namespace std;const int MAXN = 20010;struct node{ int val; int pre;};int n;int ans[MAXN];node D[MAXN];void solved(){ memset( D, -1, sizeof(D) ); queue Q; Q.push(1); D[1].val = 1; D[1].pre = -1; while ( !Q.e... 阅读全文
posted @ 2013-08-07 20:25 冰鸮 阅读(392) 评论(0) 推荐(0)
摘要:当火车处在换基站的临界点时,它到某两基站的距离相等。因此换基站的位置一定在某两个基站的中垂线上,我们预处理出任意两基站之间的中垂线,对于每次询问,求询问线段与所有中垂线的交点。检验这些交点是否满足条件(详见代码),如果满足,那么它是一个交换点。#include #include #include #include using namespace std;const int MAXN = 60;const double eps = 1e-7;struct Point{ double x, y; Point( double x = 0, double y = 0 ):x(x), y(y... 阅读全文
posted @ 2013-08-06 20:23 冰鸮 阅读(330) 评论(0) 推荐(0)
摘要:参照了nocow上的解法,照搬过来……易知一个数X在数列中在另一个数Y前,当且仅当X前缀小于Y或前缀相等X短,那么我们分布考虑,比如对于数48561:5位上:10000~48560;4位上:1000~4856;3位上:100~485;2位上:10~48;1位上:1~4.这样我们就得到了1..N中48561的位置,可以用这个来判错.接下来的方法类似,为了使得我们的N满足要求,我们必须去找比48561大且前缀比其小的数,同样有:6位上:100000~485609; //注意红色部分比原数减少了1,之前没注意这里一直WA…………---------------------以上nocow上给出的题解-- 阅读全文
posted @ 2013-08-06 10:45 冰鸮 阅读(428) 评论(0) 推荐(0)
摘要:扩展欧几里得的应用……见算法竞赛入门经典p.179注意两点:1.解不等式的时候除负数变号2.各种特殊情况的判断( a=0 && b=0 && c=0 ) ( a=0 && b=0 && c!=0 ) ( a=0 && b!=0 )( a!=0 && b=0 )能加深对扩展欧几里得的理解,不错的一题 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 #define LL long long int 8 9 using namespac 阅读全文
posted @ 2013-07-27 11:54 冰鸮 阅读(229) 评论(0) 推荐(0)
摘要:相当于从n-1个位置里面找k-1个位置放隔板 1 #include 2 #include 3 #include 4 #include 5 6 #define LL long long int 7 8 using namespace std; 9 10 int main()11 {12 double n, k;13 int T;14 scanf( "%d", &T );15 while ( T-- )16 {17 scanf( "%lf%lf", &n, &k );18 if ( n - k < k - 1 ) ... 阅读全文
posted @ 2013-07-26 11:43 冰鸮 阅读(201) 评论(0) 推荐(0)
摘要:留着当个模板用,在BNU上AC,在LA上RE……可能是java的提交方式不同???数和运算符各开一个栈。表达式从左到右扫一遍,将数存成大数,遇到数压在 数的栈,运算符压在 运算符的栈,每当遇到右括号时,弹出 数的栈 的栈顶头两个元素,弹出 运算符的栈 顶的头一个元素,进行运算,将运算结果压回 数的栈 中。最后输出栈顶元素。运算过程中把不符合情况的判掉。我写的第二个java的题,竟然1A……这世界太不可思议了= =import java.util.*;import java.math.BigInteger;public class Main { static Scanner in=new ... 阅读全文
posted @ 2013-07-23 23:13 冰鸮 阅读(339) 评论(0) 推荐(0)
摘要:把所有的点都映射到XOZ这个平面的第一象限内,则这个三维问题可以转化二维问题:求一条直线,使所有点在这条直线的下方,直线与X轴和Z轴围成的三角形旋转形成的圆锥体积最小。这样转化之后可以看出直线的临界条件应当是经过其中一点。三分圆锥半径R,因为要覆盖所有的点,让点(R, 0)与所有点连线,直线与Z轴交点即为H,H取其中最大的那个。 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 #define EPS 1e-9 8 9 using namespace std;10 11 const int MAXN = 1001... 阅读全文
posted @ 2013-07-20 17:37 冰鸮 阅读(423) 评论(1) 推荐(0)
摘要:推公式 1 #include <cstdio> 2 #include <cmath> 3 4 double Cal( double a, double b, double c ) 5 { 6 return a + b - c; 7 } 8 9 int main()10 {11 int T;12 scanf( "%d", &T );13 while ( T-- )14 {15 double m[3], n[3], r;16 scanf( "%lf", &r );17 for ( int i = 0; i ... 阅读全文
posted @ 2013-06-17 16:40 冰鸮 阅读(423) 评论(0) 推荐(0)
摘要:因为两段圆弧在同一个圆上,所以该圆是矩形的外接圆,由此可通过圆心角解得两段圆弧长,设矩形的长为x,宽为y,列出方程可解得:x = 400.0 / ( 2.0 + ( 2.0 * atan( b / a ) * sqrt( a*a + b*b ) ) / a )y = x * b / a; 1 #include <cstdio> 2 #include <cmath> 3 #include <algorithm> 4 5 using namespace std; 6 7 int main() 8 { 9 int cas = 0;10 double a, b;11 阅读全文
posted @ 2013-06-16 14:00 冰鸮 阅读(264) 评论(0) 推荐(0)