上一页 1 2 3 4 5 6 7 8 ··· 12 下一页
摘要: 题意:问n个点中可以组成多少个正方形,n<1000思路:一开始TLE了,是hash的边,后来看网上是hash的点,hash函数是(x*x+y*y)%prime已知正方形的两个点,求另外两个坐标:(x1,y1)、(x2,y2)则: x3=x1+(y1-y2) y3=y1-(x1-x2) x4=x2+(y1-y2) y4=y2-(x1-x2)View Code 1 #include<stdio.h> 2 #include<vector> 3 #include<string.h> 4 #include<iostream> 5 using name 阅读全文
posted @ 2013-05-01 20:21 _sunshine 阅读(241) 评论(0) 推荐(0) 编辑
摘要: 题意:存不存在两片相同的雪花,每片六角形的雪花的每个角的长度给出,可能是顺时针也可能是逆时针给出。最多100 000片雪花。思路:将六角形的sum%prime之后存起来,雪花相同的前提是sum相同,sum相同再一一比较。View Code 1 #include<stdio.h> 2 #include<vector> 3 #include<string.h> 4 #include<iostream> 5 using namespace std; 6 7 const int N=100005; 8 const int prime=90001; 9 1 阅读全文
posted @ 2013-05-01 14:23 _sunshine 阅读(225) 评论(0) 推荐(0) 编辑
摘要: 链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1758题意:输入两个字符串S,T,长度小于100000,求出在S中包含T中的最小的那段,例如:S = "ADOBECODEBANC"T = "ABC"答案是 "BANC".View Code 1 #include<stdio.h> 2 #include<string.h> 3 const int M=10005; 4 const int N=1 阅读全文
posted @ 2013-05-01 13:37 _sunshine 阅读(237) 评论(0) 推荐(0) 编辑
摘要: 参考资料:http://www.notonlysuccess.com/index.php/segment-tree-complete/hdu1166题意:对于n(n≤500000),操作有两种:①任意更改某个点的值②求任意区间的和View Code 1 #include <stdio.h> 2 const int N=50005<<2; 3 int sum[N]; 4 int T,n; 5 ///rt表示当前子树的根(root),也就是当前所在的结点 6 void PushUP(int rt){ 7 sum[rt]=sum[rt<<1]+sum[rt< 阅读全文
posted @ 2013-04-27 19:36 _sunshine 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 链接:http://poj.org/problem?id=2831题意:给出一些边,再对这些边进行修改(只允许边权值减小),问该边修改之后是否可能是最小生成树上的边。思路:用prime算法求最小生成树,边求边计算出从s到t之间最长的边。然后询问时候,看这条边和s到t之间的最长的边比较大小就可以了~一... 阅读全文
posted @ 2013-04-12 21:09 _sunshine 阅读(320) 评论(0) 推荐(0) 编辑
摘要: 树的直径的证明:结论:s-t是树的直径,即树上最长的路。则一共满足从任意一点u出发,搜索到的最远的点一定是s或者t。找到s或者t,从s或者t出发搜索即可找到树的直径。证明:①如果u是s-t路径上的一个点,那么搜到的一共是s或者t了,否则s-t就不是最长路径了。dis(u,T) >dis(u,s) 且dis(u,T)>dis(u,t) 则最长路不是s-t了,与假设矛盾。②如果u不是s-t路径上的点,假如u走到了s-t路径上的一点,那么接下来的路径肯定都在s-t上了,而且终点为s或t,在1中已经证明过了 所以现在又有两种情况了: 1:u走到了s-t路径上的某点,假设为X,最后肯定走到某 阅读全文
posted @ 2013-04-10 21:33 _sunshine 阅读(256) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.nyist.net/JudgeOnline/problem.php?pid=16思路:d(i)=max{0,d(j)矩形j可以嵌套在矩形i中}+1记忆化搜索,否则会超时:View Code 1 #include<stdio.h> 2 #include<string.h> 3 const int N=1005; 4 int a[N],b[N]; 5 bool map[N][N]; 6 int dp[N]; 7 int T,n; 8 int DP(int i){ 9 int &ans=dp[i];10 if(dp[i]!=0) retur 阅读全文
posted @ 2013-04-10 21:02 _sunshine 阅读(607) 评论(0) 推荐(0) 编辑
摘要: 学习资料:http://blog.csdn.net/ggggiqnypgjg/article/details/6645824时间复杂度O(N)模板:View Code 1 void Manacher(int n) 2 { 3 int i; 4 int mx=0;//记录前面回文串最... 阅读全文
posted @ 2013-04-10 20:38 _sunshine 阅读(373) 评论(0) 推荐(0) 编辑
摘要: 题意:求n个非负数中任意2个的异或值的最大值。n数量级为10^5分析:一个非负整数可以看成1个32位的01字符串,n个数可以看成n个字符串,因此可以建立字典树,建好树后,对于任意非负整数x,可以沿着树根往下贪心找到y,使得x异或y最大,复杂度为树的深度。View Code 1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <math.h> 5 using namespace std; 6 #define M 3200010 7 #define N 阅读全文
posted @ 2013-04-02 21:25 _sunshine 阅读(472) 评论(0) 推荐(0) 编辑
摘要: 代码写得很搓,模拟~一层一层的往下走~View Code 1 #include <stdio.h> 2 #include <string.h> 3 #include <queue> 4 #include <iostream> 5 using namespace std; 6 int map[10][10]; 7 int in[10][10]; 8 int move[4][2]={{1,0},{-1,0},{0,1},{0,-1}}; 9 struct node{10 int x,y,z;11 int k;12 };13 bool operator 阅读全文
posted @ 2013-03-28 21:44 _sunshine 阅读(253) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 12 下一页