上一页 1 2 3 4 5 6 7 ··· 12 下一页
摘要: 题目地址: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) 编辑
上一页 1 2 3 4 5 6 7 ··· 12 下一页