09 2013 档案

摘要:题目地址:http://poj.org/problem?id=3984利用图论中深搜的思想,存在边就是x,y -> x+1,y 还有x,y -> x,y+1 然后仍然是访问未访问的而且不是墙壁的地方。 这样保证不走已经搜索过,走不通的路。唯一一种需要重复访问已经访问的结点的情况是已经无路可走了,只能返回,这样就在栈中将路径取出来,把自己现在的那个先pop掉,然后实现回溯。最后用向量实现栈的自底输出。代码:IDUserProblemResultMemoryTimeLanguageCode LengthSubmit Time12143517814jingqi3984Accepted72 阅读全文
posted @ 2013-09-25 18:03 814jingqi 阅读(596) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://poj.org/problem?id=1905思路:列出方程 2*R*x=L‘ 2*R*sin(x)=L 两式相除即得 x/sin(x) = 1+n*c 前提x!=0 就是 n*c>0 答案就是 L/2* (1/sin(x)-1/tan(x)) 三角函数化简为 L/2*tan(x/2) x 在0~ PI/2 于是关于x是单增的, 反函数也是单增的,x/sin(x) 也是单增的一开始的思路是先用 二分把x/sin(x) = 1+n*c 里面的x解出来,然后带进L/2*tan(x/2) 计算 虽然样例过了,但是还是wa... 阅读全文
posted @ 2013-09-25 15:15 814jingqi 阅读(117) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://poj.org/problem?id=3122还是找到了单调函数--分给m人对最大尺寸f(m) 是m的不增函数,那么具体给定m是,二分f(m)使用>=f+1 l=mid 而不是>来保证尽可能取得大细节: 应该直接二分答案,而不是算出比较精确的半径平方,最后*PI输出,会产生误差,然后PI用arccos(-1),否则也会wa代码:#include #include #include using namespace std; //const double PI=3.1415926535; //这样写就wa了 是精度不够? const double PI=acos 阅读全文
posted @ 2013-09-25 02:19 814jingqi 阅读(156) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3366思路: 题目就是要求函数(h*D-H*x)/(D-x)+x 的最大值,其中 x>=0 x #include using namespace std; int main() { int T; cin>>T; long double H,h,D; while(T--) { cin>>H>>h>>D; long double ans=D*H-D*h; ans=sqrt(ans); ans... 阅读全文
posted @ 2013-09-24 23:43 814jingqi 阅读(235) 评论(0) 推荐(0) 编辑
摘要:题目地址:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1645思路: 图论模型化,种类数就是点,对数就是边, 要求始终不存在子图使点数等于边数,就是不允许有环,使用并查集即可。代码:#include #include #define N 100001 using namespace std; int p[N+5]; int find(int x) { return p[x]==x?x:p[x]=find(p[x 阅读全文
posted @ 2013-09-24 21:43 814jingqi 阅读(145) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4717第一次写三分,这个解法是学解题报告的,感谢原作者。首先对每对点对,他们的距离关于时间t是二次函数,现在就是求c[n][2] 个二次函数,每个点取最大值构成的函数的极值。 由于每个子函数都是先减后增,或者对称轴小于0,直接单增,他们的max一定也保持着这个性质 (具体证明和n个下凸函数max还是下凸函数很像?)然后取100次精度就够了代码:#include #include #include using namespace std; int x[300],y[300],vx[300],vy[3. 阅读全文
posted @ 2013-09-23 23:30 814jingqi 阅读(118) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://poj.org/problem?id=3258题目思路: 首先,如果只减少一部,那么一定要干掉最短的那段距离(一旦不消灭,最小的还是它,并没有达到使最小值取最大的理想情况)。 但是如果有很多边取到最小,具体去除哪一个点就有点麻烦了。如果两个最小距离连着,去除公共点最好。 如果没有连着,四个点分别考虑紧邻的,取最小的。 如果多于两条线段取最小随便去,如果仅有一条取最小仍是去紧邻较小的点。 很麻烦就是了。基于这样的思想,每次去掉一个顶点后,再取出最小边,同样处理(借助优先权队列) 。不知这样的贪心是不是对的...有一个二分答案的做法,现学的.一般的二分查找是 while(. 阅读全文
posted @ 2013-09-22 02:20 814jingqi 阅读(172) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4712首先,算汉明距离就是二进制异或以后的1的个数,统计1的个数用x&=x-1很快很神奇。用if(x&1) {count++; x>>=1;} 在位数比较多的时候会慢一些。然后就是看题解学到的神奇的“随机”! 来取到“任意的两个” 1w次wa,但是10w次就不会,20组testcase ,不会超时;真的ac了,很神奇代码:#include #include #include #include #include using namespace std; int a[1000 阅读全文
posted @ 2013-09-21 20:28 814jingqi 阅读(127) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3432题目思路: 其实就是找那个只出现了1次的字符串。 但是如果用数组或者map记录出现的次数,10w的数量会导致超时,学到一种神奇的方式--直接用异或处理先看代码:#include #include #include using namespace std; string s; char sock[9]; char ans[9]; int main() { int n; cin>>n; while(cin>>n) { g... 阅读全文
posted @ 2013-09-20 23:21 814jingqi 阅读(132) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4113思路:这个就是三维数组的地址和下标之间的对应。 然后涉及到一定的变换 ,我们有一个p【a】 记录在若干次对换之后实际对应的是哪个数。 同时,为了能用find函数找回坐标,我们还要记录反函数(写作pp【a】)然后这个value超过的xyz是不要输出的。代码:#include #include #include #include using namespace std; int p[1010]; int q[1010]; int r[1010]; int ... 阅读全文
posted @ 2013-09-20 21:58 814jingqi 阅读(136) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4708首先来学习一个ac的代码:作者http://blog.csdn.net/xingyeyongheng#include #include #include #include #include #include #include #include #define INF 99999999 using namespace std; const int MAX=10; int s[MAX][MAX]; int main(){ int n; while(scanf("%d",& 阅读全文
posted @ 2013-09-20 00:13 814jingqi 阅读(121) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4715首先打素数表,然后分三类 x=0,>0, #include #include using namespace std; #define N 10000000 bool p[N+1]; void pre() { int d=sqrt(N); for(int i=2;i>n; for(int i=0;i0) { for(start=2;start<=10000000-x;start++) { ... 阅读全文
posted @ 2013-09-19 16:45 814jingqi 阅读(169) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4627[a,b]=ab/(a,b) a,b和一定时,越接近乘积越大,在接近的同时,尽量保持公因子最少。 如果n为2*k+1 那么 取a=2k,b=2k+1 最佳。 如果n为偶数=2k,就要进一步分k的奇偶性了。 n=4k 时 显然2k+2k会很小 2k-1,2k+1 就满足了 (2k-1,2k+1)=(2,2k+1)=1 。 如果n=4k+2 ,逐一实验2k+1,2k+1。 2k 2k+2. 2k-1,2k+3 。发现2k-1,2k+3是最佳的,而且他们已经互素了,再增大差距结果不会优于这组。 .. 阅读全文
posted @ 2013-09-19 15:00 814jingqi 阅读(125) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4707题目给出一颗树,要求求出深度大于D的结点的个数。有两种方法,改写dfs,给一个参数放层数(额,其实这里不需要转化为有根树,多于了)代码:#include #include #include #include using namespace std; #define maxn 100005 vector G[maxn]; int p[maxn]; int lev[maxn]; //vector leaf; void dfs(int u,int fa,int level) // 无根树... 阅读全文
posted @ 2013-09-18 00:17 814jingqi 阅读(100) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3789首先 题目要求只对m个国家排序,然后输出的顺序是给的国家编号的顺序~~!! 不一定是升序` wa了n次在这里然后用sort死做代码:#include #include #include #include using namespace std; struct nation { long double gold; long double all; long double area; int id; int rate1; int rate... 阅读全文
posted @ 2013-09-17 14:56 814jingqi 阅读(371) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4706用一个三维数组来存贮要表示的矩阵,先画几个特例找规律,记住这个N是倒的...代码:#include #include using namespace std; char p[11][11][11]; int main() { for(int i=1;i #include #include using namespace std; int a[100][100]; bool vis[100][100]; void init() { memset(vis,0,size... 阅读全文
posted @ 2013-09-16 23:37 814jingqi 阅读(119) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4741题目大意 给你4个点 确定两条异面直线,求他们之间的距离和公垂线段的垂足。这里从twj1993那学的用直线参数方程+偏导数的方法,甚至可以解决n维坐标下的问题。设第一条直线的参数方程是x=x1+(x3-x1)*t1 , y=...,z=..... 第二条直线的参数方程同理可设(t2为参数)。然后两点之间的距离就可以表示为t1,t2的二元函数,令偏导为0就可以了。为了方便起见,变量用x,y代替。然后求函数系数的时候发现x,y是对称的,只需要把x改成y,z加上去就可以了最后,很关键的一点,dou. 阅读全文
posted @ 2013-09-16 22:13 814jingqi 阅读(179) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4737或运算 a|b>=a, a|b>=b 而且还可能 a|b > max(a,b);所以枚举a[i] 开头的字符串时 一旦出现大于m 就可以break理论上是o(n*n) 加上一些优化 。 优化成什么样要看数据了 如果数据***钻 100000 个 0 ,m=1 那肯定会超时,不过还好数据不***钻 就这样水过去了不过还是收获一点心得--敢于写暴力啊代码:#include #include #include #include using namespace std; int a[1000 阅读全文
posted @ 2013-09-14 19:32 814jingqi 阅读(107) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1677首先要求最大生成树,来保证图的连通性(基于贪心的思想--尽量炸代价小的路,能炸得更多) 然后在资金足够的情况下,一一去炸代价小的路,直到钱不够当前最便宜的路了,break掉代码:#include #include #include #include #include using namespace std; int p[50005]; struct edge { int id; int x; int y; int w; }... 阅读全文
posted @ 2013-09-13 00:09 814jingqi 阅读(125) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1230第i位表示的实际大小是前i 个素数的乘积那么多,(第0位表示1) 进位规则是这一位减去p[i] (例如第0位减去p[0]==2) 高以为加1 ,由于更加难进位了,所以加法先相加,然后一次进位扫描就能保证每一位在范围内。 输入输出有点麻烦,是这个题的考点吧代码:#include #include #include #include #include using namespace std; int p[101]; vector prime; int na[25]; int nb[25];... 阅读全文
posted @ 2013-09-12 20:48 814jingqi 阅读(97) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4722考虑怎样的数可以成为good number ,如果不给范围,取一个n位数 (最高位-1)*10*10....最后一位由前面的和决定。 首先不考虑0基于这样的思想 比如不超过54321的good number 有多少 ,1~4位有9+9*10+9*10*10(等比求和) 5位就是4*10*10*10+ 第一位是5 剩下的部分mod10==5,而且不超过4321这样就可以设计递归了。然后就是递归函数设计中 应该是long long的始终不要丢失精度 , 第二个参数递归下降时 不忘+10 再去mo. 阅读全文
posted @ 2013-09-12 01:12 814jingqi 阅读(97) 评论(0) 推荐(0) 编辑
摘要:题目地址 :http://acm.hdu.edu.cn/showproblem.php?pid=4720题目是给三个点 ,要求求出最小的能覆盖这三个点的圆,然后判断第四个点在不在这个圆内。如果这个是一个钝角三角形,那么圆心就是最长边的中点,如果是锐角三角形,圆心就是外接圆圆心。 然后用点到圆心的距离和半径的关系判断是不是在圆内。求外接圆时 用到向量点积为0,还有Crammer法则解方程代码:#include #include using namespace std; double calcdet(double p[2][2] ) //计算行列式的值 { double... 阅读全文
posted @ 2013-09-11 18:27 814jingqi 阅读(156) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4496将题目要查询的数倒过来求,先加一条边,保存cc(连通分支数) 然后再加一条边....当合并两个等价类的时候连通分支减1代码:#include #include #include #include using namespace std; int p[10000]; int u[100000]; int v[100000]; int ans[100000]; int find(int x) { return p[x]==x?x:p[x]=find(p[x]); } int main() ... 阅读全文
posted @ 2013-09-09 23:00 814jingqi 阅读(148) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1233模板题,kruskal求最小生成树。 并查集是个好东西啊 就是注意一点 输入边的信息时,角标应该是从0开始的代码:#include #include #include using namespace std; struct edge { int u; int v; int w; }; int p[100]; edge e[5000]; bool cmp(edge a,edge b) { return a.w>n) { if(n==0) b... 阅读全文
posted @ 2013-09-09 21:00 814jingqi 阅读(135) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1232直接求连通分支数,有重边不影响dfs代码:#include #include #include #include using namespace std; vector G[1000]; int maxn; bool vis[1000]; void dfs(int u) { vis[u]=1; int d=G[u].size(); for(int i=0;i>n>>m) { if(n==0) break; memset(vis,0,siz... 阅读全文
posted @ 2013-09-09 17:02 814jingqi 阅读(156) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4709可以证明,三角形是最小的。直接计算三角形面积,取最小的的,Impossible的情况特判就行。计算三角形面积用向量叉积。代码:#include #include #include #include #include using namespace std; struct point { double x; double y; }; double area(point A,point B,point C) { double abx=B.x-A.x; doubl... 阅读全文
posted @ 2013-09-09 14:21 814jingqi 阅读(141) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3786题目思路: 我们用p[i]=j 来表示 i 的孩子是j (因为一个parent只有一个孩子,但是一个孩子有两个parent不好形成对应)然后初始化为-1,这样如果遇到父母不清楚的(‘-’) 还是-1,一遇到就break掉,把count还原为0; 如果是家族树上存在的两个结点,那么一定可以通过这样知道他们相隔的代数,于是就可以知道相应的称谓 一堆if-else 比较考基本功代码:#include #include #include using namespace std; int p[26];. 阅读全文
posted @ 2013-09-08 23:00 814jingqi 阅读(125) 评论(0) 推荐(0) 编辑
摘要:http://www.hhanger.com/ 上面很多srm题解报告啊http://eastsun.iteye.com/blog/225235一个做project euler 的孩纸~10-26 math over 后 好好搞呀~ 阅读全文
posted @ 2013-09-08 22:53 814jingqi 阅读(116) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4706以前做过的题目: i从0到n-1时,如果一个一个加会很慢,注意到如果mod a的序列 和mod b的序列都处在上升中,那么差距是一样的,这样跳的step就可以大一些~注意下就是如果a,b都是1的话 ,跳步还是没有变动,直接特判为0就行。 还有step*(i%a-i%b)可能会超int 其中一个要用long long 存放代码:#include #include using namespace std; int min(int a,int b) { if(a>T; while(T--... 阅读全文
posted @ 2013-09-08 18:15 814jingqi 阅读(105) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://poj.org/problem?id=1833直接调用stl里面的next_permutation 只要调用了,不管返回什么,都取了下一个排序。 神奇的是,用c++ac,用g++交tle,跪了 ...代码:#include #include #include using namespace std; int p[1024]; int main() { int n,k,m; cin>>m; while(cin>>n>>k) { for(int i=0;i<n;i++) scanf("%d",&p[i]) 阅读全文
posted @ 2013-09-07 21:41 814jingqi 阅读(107) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1878判断图上是否有欧拉回路,首先要求是连通图,然后每个顶点的度数必须都为偶数(如果存在两个顶点度数为奇数则是存在欧拉通路)用dfs求连通分支的个数代码:#include #include #include #include using namespace std; vector G[1000]; bool vis[1000]; void dfs(int u) { vis[u]=1; int d=G[u].size(); for(int i=0;i>n>>m) { ... 阅读全文
posted @ 2013-09-05 23:08 814jingqi 阅读(173) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://poj.org/problem?id=3844思路: a[i]+a[i+1]+...+a[j]=s[j]-s[i]; 于是整除等价于 s[i]===s[j] (mod d); 然后统计出现了多少次 c[n][2]就可以了 。 值得注意的是,有可能50000* (50000-1)/2 要用long long每次进入一个新case 后把p 清零,sum【i】表示前i个数的和, 0= #include #include using namespace std; int sum[50005]; int p[1000000]; int main() { int T; ci... 阅读全文
posted @ 2013-09-04 11:10 814jingqi 阅读(161) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://poj.org/problem?id=3842 或者:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2610思路就是暴力求出每一种可能的情况,进行全排列(next_permutation可以去重)然后对每一种排列考虑前面的子串。为了防止一个情况被考虑两次,设置一个占位符b[10000000] 每次新输入数,记得将b清空,然后先转化成int数组,每次翻译成一个int时快一些。这个代码在Uva 阅读全文
posted @ 2013-09-04 01:36 814jingqi 阅读(225) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4639题目思路: 首先我们取出所有he这样的东西,考察连续的k个“he"串,通过找规律+数学归纳法容易证明有f【k】种方式,其中f为Fibonacci数列, 那么再统计这个串中有多少个这样的块就可以了,他们乘起来。代码:#include #include using namespace std;; int p[10000]; void pre() { p[1]=1; p[2]=2; for(int i=3;i>T; string s; int index=0; ... 阅读全文
posted @ 2013-09-03 22:26 814jingqi 阅读(166) 评论(0) 推荐(0) 编辑
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4642题解思路: 很容易得到,谁先把所有的硬币翻成反面朝上,谁就害得对方没办法继续下去,自己就获胜了,假设进行了K局,使得第一次全部的硬币都反面朝上了。事实上,k在比赛的一开始就确定好了,因为每次操作都会改变最右下角的那个1,0的奇偶性,那么最后一个数一开始是1,k必然是奇数,Alice获胜,一开始是0,k必然是偶数,Bob获胜。 嗯嗯,就这一点巧,感谢ChoiceZ的神YY~代码:#include #include #include using namespace std; int main(.. 阅读全文
posted @ 2013-09-03 22:03 814jingqi 阅读(160) 评论(0) 推荐(0) 编辑