04 2012 档案
新的开始
摘要:调整好心态!迎接新的开始!加油! 阅读全文
posted @ 2012-04-30 21:43 Try86 阅读(111) 评论(0) 推荐(0)
hrbustOJ 1373Leyni, LOLI and Leaders(图论)
摘要:摘自:http://acm.hrbust.edu.cn/hcpc2012/index.php?act=showpost&p=15本题是图论题根据题意,判断一颗树中,某个点是否是另一个点的后裔。根据递归函数的入栈出栈时间戳特点(即子结点的入栈时间戳要晚于自己,而且子节点的出栈时间戳要早于自己)或者括号定理在O(N)内预处理一遍图,即可在O(1)时间完成每次查询。d[x]表示深度优先搜索中x的访问时间戳f[x]表示深度优先搜索中x的结束访问时间戳如果d[u] < d[v] < f[v] < f[u],那么v是u的后裔。 1 #include <cstdio> 阅读全文
posted @ 2012-04-27 17:18 Try86 阅读(162) 评论(0) 推荐(0)
hrbustOJ 1375The Active Leyni(动态规划+矩阵乘法)
摘要:摘自:http://acm.hrbust.edu.cn/hcpc2012/index.php?act=showpost&p=15本题是动态规划+矩阵乘法题定义f[i][0]为走了i步恰好达到S的不同走法定义f[i][1]为走了i步恰好达到A的不同走法定义f[i][2]为走了i步恰好达到B的不同走法定义f[i][3]为走了i步恰好达到C的不同走法状态转义方程为:f[i][0] = f[i – 1][1] + f[i – 1][2] + f[i – 1][3];f[i][1] = f[i – 1][0] + f[i – 1][2] + f[i – 1][3];f[i][2] = f[i – 阅读全文
posted @ 2012-04-27 16:03 Try86 阅读(209) 评论(0) 推荐(0)
pku 2187(最远点对)
摘要:1 /* 2 * 题目要求:求一组点中距离最远的一对的距离 3 * 解法:凸包+枚举 4 */ 5 6 #include <cmath> 7 #include <cstdio> 8 #include <cstdlib> 9 #include <iostream>10 11 using namespace std;12 13 const int N = 50005;14 15 struct point {16 int x;17 int y;18 }p[N], stack[N];19 20 int dis(point A, point B) {21 阅读全文
posted @ 2012-04-27 07:26 Try86 阅读(245) 评论(0) 推荐(0)
pku 3714(最近点对)
摘要:1 /* 2 * 题目要求:求最近点对(一个点在station内,一个点在agent内) 3 */ 4 5 #include <cmath> 6 #include <cstdio> 7 #include <cstdlib> 8 #include <iostream> 9 #include <algorithm>10 11 using namespace std;12 13 const int N = 200005;14 const double INF = 1e20;15 16 struct point {17 int f;18 do 阅读全文
posted @ 2012-04-26 21:43 Try86 阅读(223) 评论(0) 推荐(0)
hdu 1007(最近点对)
摘要:1 /* 2 * 题目要求:求最近点对 3 */ 4 5 #include <cmath> 6 #include <cstdio> 7 #include <cstdlib> 8 #include <iostream> 9 #include <algorithm>10 11 using namespace std;12 13 const int N = 100005;14 const double INF = 1e15;15 16 struct point {17 double x;18 double y;19 }p[N];20 int 阅读全文
posted @ 2012-04-26 20:23 Try86 阅读(251) 评论(0) 推荐(0)
FZU 1382(求三角形的外接圆与内切圆)
摘要:1 /* 2 * 题目要求:求三角形内接圆面积与外接圆面积之比 3 * 内切圆半径:r=2*s/(a+b+c) ; 4 * 外接圆半径为 R=(a*b*c)/(s*4); 5 * 对于一般的三角形,内切圆半径公式如下: 6 * r=sqrt[(p-a)(p-b)(p-c)/p] 7 * 在直角三角形的内切圆中,有这样两个简便公式: 8 * 1、两直角边相加的和减去斜边后除以2,得数是内切圆的半径。 9 * 2、两直角边乘积除以直角三角形周长,得数是内切圆的半径。 10 * 1、r=(a+b-c)/2(注:s是Rt△的面积,a, b是Rt△的2个直角边,c是斜... 阅读全文
posted @ 2012-04-25 22:10 Try86 阅读(429) 评论(0) 推荐(0)
pku 1410(判断线段是否跟矩形相交)
摘要:1 /* 2 * 题目要求:判断线段是否跟矩形相交 3 * 注意:线段完全在矩形内也是相交 4 * 解法:分别判断线段是否跟矩形的四条边相交,再判断线段的两个端点是否都在矩形内 5 */ 6 7 #include <cstdio> 8 #include <cstdlib> 9 #include <iostream>10 11 using namespace std;12 13 struct point {14 double x;15 double y;16 }A, B, C, D, E, F;17 18 double crossProd(point A, p 阅读全文
posted @ 2012-04-25 13:11 Try86 阅读(426) 评论(0) 推荐(0)
hdu 1348(凸包)
摘要:1 /* 2 * 凸包 3 * 注意:给出的点为整点数,不要设某一精度值! 4 */ 5 6 #include <cmath> 7 #include <cstdio> 8 #include <cstdlib> 9 #include <iostream>10 11 using namespace std;12 13 const int N = 1005;14 const double PI = 3.1415927;15 16 struct point {17 double x;18 double y;19 }p[N], stack[N];20 21 阅读全文
posted @ 2012-04-24 22:34 Try86 阅读(938) 评论(0) 推荐(0)
hdu 1785(对向量排序)
摘要:1 /* 2 * 题目要求:对一组向量按与x轴的正向夹角从小到大排序 3 * 解法:借用求凸包的排序规则即可 4 */ 5 6 #include <cmath> 7 #include <cstdio> 8 #include <cstdlib> 9 #include <iostream>10 11 using namespace std;12 13 const int N = 105;14 const double eps = 1e-8;15 16 struct point {17 double x;18 double y;19 }p[N];20 阅读全文
posted @ 2012-04-24 22:07 Try86 阅读(287) 评论(0) 推荐(0)
hdu 2150(判断折线是否相交)
摘要:1 /* 2 * 题目要求:判断给出的一些折线段是否相交 3 * 解法:枚举每条折线段上的每段线段,判断其是否与其它折线段的线段相交 4 */ 5 6 #include <cstdio> 7 #include <cstdlib> 8 #include <iostream> 9 10 using namespace std;11 12 const int N = 35;13 const int M = 105;14 15 int num[N];16 struct point {17 double x;18 double y;19 }p[N][M];20 21 阅读全文
posted @ 2012-04-24 21:34 Try86 阅读(433) 评论(0) 推荐(0)
hdu 2202(凸包+枚举凸包上的点)
摘要:1 /* 2 * 题目要求:求三角形的最大面积 3 * 方法:凸包+枚举凸包上的点 4 */ 5 6 #include <cmath> 7 #include <cstdio> 8 #include <cstdlib> 9 #include <iostream>10 11 using namespace std;12 13 const int N = 50005;14 const double eps = 1e-8;15 16 struct point {17 int x;18 int y;19 }p[N], stack[N];20 21 bool 阅读全文
posted @ 2012-04-24 18:53 Try86 阅读(666) 评论(0) 推荐(0)
pku 2954(pick定理的应用)
摘要:/* * pick定理的应用* pick定律: area = inside + onedge / 2 - 1; */#include <cmath>#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;struct point { int x; int y;}A, B, C;int crossProd(point A, point B, point C) { return (B.x-A.x)*(C.y-A.y) - (B.y-A.y)*(C.x-A.x) 阅读全文
posted @ 2012-04-23 22:05 Try86 阅读(248) 评论(0) 推荐(0)
pku 1687(求面积最大的多边形的编号)
摘要:/** 题目要求:求面积最大的那个面的编号* 方法:分别求每个面的面积,并比较最大的面积 */#include <cmath>#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;const int N = 55;struct point { int x; int y;}p[N], sp[N];double crossProd(point A, point B, point C) { return (B.x-A.x)*(C.y-A.y) - (B.y-A 阅读全文
posted @ 2012-04-23 21:46 Try86 阅读(223) 评论(0) 推荐(0)
hdu 2215(凸包+最小圆覆盖)
摘要:/* 凸包+最小圆覆盖 枚举任意3点找其最小覆盖圆(当为钝角三角形时不是外接圆,而是以其最长边为直径的圆)。 当为外接圆时,半径公式为r=abc/4s;(推导为如下: 由正弦定理,a/sinA=b/sinB=c/sinC=2R,得sinA=a/(2R), 又三角形面积公式S=(bcsinA)/2,所以S=(abc)/(4R),故R=(abc)/(4S).*/#include <cmath>#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;const 阅读全文
posted @ 2012-04-23 21:01 Try86 阅读(1249) 评论(0) 推荐(0)
hdu 1392(求凸包周长)
摘要:/** 题目要求:求凸包的周长 */#include <cmath>#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;const int N = 105;const double eps = 1e-8;struct point { int x; int y;}p[N], stack[N];bool isZero(double x) { return (x > 0 ? x : -x) < eps;}double dis(point A, p 阅读全文
posted @ 2012-04-23 18:46 Try86 阅读(886) 评论(0) 推荐(0)
hdu 2108(判断多边形是凸的,还是凹的)
摘要:/** 利用叉乘判断多边形是凸的,还是凹的* auther:Try86 */#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;struct point { int x; int y;}A, B, C, tA, tB;int crossProd(point A, point B, point C) { return (B.x-A.x)*(C.y-A.y) - (B.y-A.y)*(C.x-A.x);}int main() { int n; while (scanf 阅读全文
posted @ 2012-04-22 21:37 Try86 阅读(407) 评论(0) 推荐(0)
hdu 1756(判断点是否在多边形内)
摘要:/** 题意:判断点在多边形内* 判点在任意多边形内,顶点按顺时针或逆时针给出*/#include <cmath>#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;const int N = 100;const int offset = 1000; //offset为多边形坐标上限const double eps = 1e-8;struct point { double x; double y;}p[N], p1, p2;bool isZero(do 阅读全文
posted @ 2012-04-22 20:44 Try86 阅读(1915) 评论(0) 推荐(0)
hrbust OJ13哥的机器人(利用叉乘判断拐向)
摘要:View Code /** 利用叉乘判断拐向 * auther:Try86*/#include <cstdio>#include <iostream>using namespace std;char str[1000];struct point { int x; int y;}A, B, C;int crossProd(point A, point B, point C) { return (B.x-A.x)*(C.y-A.y) - (B.y-A.y)*(C.x-A.x);}int main() { int n; while (scanf("%d", 阅读全文
posted @ 2012-04-22 11:39 Try86 阅读(186) 评论(0) 推荐(0)
hrbustOJ 石子游戏(巴什博弈)
摘要:View Code /*摘自:ACM百科网 巴什博奕(Bash Game):只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个。最后取光者得胜。显然,如果n=m+1,那么由于一次最多只能取m个,所以,无论先取者拿走多少个,后取者都能够一次拿走剩余的物品,后者取胜。因此我们发现了如何取胜的法则:如果n=(m+1)r+s,(r为任意自然数,s≤m),那么先取者要拿走s个物品,如果后取者拿走k(≤m)个,那么先取者再拿走m+1-k个,结果剩下(m+1)(r-1)个,以后保持这样的取法,那么先取者肯定获胜。总之,要保持给对手留下(m+1)的倍数,就能最后获胜。这个游戏还可以有 阅读全文
posted @ 2012-04-22 11:18 Try86 阅读(143) 评论(0) 推荐(0)
hrbustOJ 围困(判断点是否在三角形内)
摘要:View Code /** 题目要求:判断点是否在三角形内* 可利用叉乘判断拐向来解决 * auther:Try86*/#include <cstdio>#include <iostream>using namespace std;struct point { int x; int y;}A, B, C, D;int crossProd(point A, point B, point C) { return (B.x-A.x)*(C.y-A.y) - (B.y-A.y)*(C.x-A.x);}bool inTrangle() { if (crossProd(D, ... 阅读全文
posted @ 2012-04-22 10:54 Try86 阅读(148) 评论(0) 推荐(0)
hrbustOJ 受到攻击(判断点是否在凸多边形内包括边界)
摘要:View Code /** 题目要求:判断点是否在凸多边形内 * 方法:利用叉乘判断拐向来求解 * auther:Try86 */#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;const int N = 100;struct point { double x; double y;}p[N], doTa;double crossProd(point A, point B, point C){ return (B.x-A.x)*(C.y-A.y) - (B.y- 阅读全文
posted @ 2012-04-22 10:36 Try86 阅读(197) 评论(0) 推荐(0)
hdu 2671(点关于直线对称问题)
摘要:View Code /** 题目所求:在直线上找一点P,使其与其它(A,B)两点组成的距离最短 * 点A跟点B与直线的位置情况四种:* 1.两点在直线的同侧(两点都不在直线上) * 2.两点在直线的异侧(两点都不在直线上) * 3.其中一点在直线上* 4.两点都在直线上* auther:Try86 */#include <cmath>#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;struct point {//点结构 double x; doub 阅读全文
posted @ 2012-04-22 10:03 Try86 阅读(197) 评论(0) 推荐(0)
hdu 1086(判断线段相交)
摘要:View Code /** 题目要求:求一组线段的总的交点数* 判断两线段相交:1快速排斥,2跨立实验 */#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;const int N = 100;struct point {//点结构 double x; double y;};struct segment {//线段结构 point s; point e;}seg[N];double crossProd(point A, point B, point C) { . 阅读全文
posted @ 2012-04-22 08:36 Try86 阅读(194) 评论(0) 推荐(0)
hdu 1115(求密度均匀的多边形的重心)
摘要:View Code /*摘自:KIDxの博客 求多边形重心的题目大致有这么几种: 1、质量集中在顶点上 n个顶点坐标为(xi,yi),质量为mi,则重心 X = ∑( xi×mi ) / ∑mi Y = ∑( yi×mi ) / ∑mi 特殊地,若每个点的质量相同,则 X = ∑xi / n Y = ∑yi / n 2、质量分布均匀 特殊地,质量均匀的三角形重心: X = ( x0 + x1 + x2 ) / 3 Y = ( y0 + y1 + y2 ) / 3 3、质量分布不均匀 只能用函数多重积分来算,不太会 这题的做法: 将n边形分成多个三... 阅读全文
posted @ 2012-04-21 22:14 Try86 阅读(637) 评论(0) 推荐(1)
hdu 2036(计算多边形的面积)
摘要:View Code /** 题目要求:计算多边形面积* 方法:把n多边形分割成n-2个三角形,分别求和,然后相加* 注意:分割的所有三角形有一个公共的顶点,这里选择0点位公共点 * 注:题中给出的点的顺序为逆时针 * auther:Try86 */ /** 叉乘的性质:设两向量P和Q * 1.P ×Q > 0 则Q在P的逆时针方向 * 2.P ×Q < 0 则Q在P的顺时针方向* 3.P ×Q = 0 则Q和P共线,方向可能相同也可能不相同 *//** 实现一 */#include <cmath>#include <cstdio> 阅读全文
posted @ 2012-04-21 21:26 Try86 阅读(157) 评论(0) 推荐(0)
2012全国软件大赛蓝桥杯选拔赛04题
摘要:View Code /* Name: Copyright: Author: Try86 Date: 20/04/12 07:22 Description: *//**题目描述: *某电视台举办了低碳生活大奖赛。题目的计分规则相当奇怪:*每位选手需要回答10个问题(其编号为1到10),越后面越有难度。*答对的,当前分数翻倍;答错了则扣掉与题号相同的分数(选手必须回答问题,不回答按错误处理)。*每位选手都有一个起步的分数为10分。*某获胜选手最终得分刚好是100分,如果不让你看比赛过程,你能推断出他(她)哪个题目答对了,哪个题目答错了吗?*如果把答对的记为1,答错的记为0,则10个题... 阅读全文
posted @ 2012-04-20 07:25 Try86 阅读(167) 评论(0) 推荐(0)
pku 2253(floyd变形)
摘要:View Code /* Name: floyd Copyright: Author: Date: 19/04/12 22:39 Description: 求所有连接1跟2的路径中,最大边权中的最小值 */#include <cmath>#include <cstdio>#include <iostream>using namespace std;const int N = 205;double dis[N][N];struct point { double x; double y;}p[N];double max(double a, double b) { 阅读全文
posted @ 2012-04-19 22:46 Try86 阅读(131) 评论(0) 推荐(0)
pku 3268(SPFA)
摘要:View Code /* Name: bellmanFord算法的改进-->SPFA算法 Copyright: Author: Date: 18/04/12 22:29 Description: 从x点正向求最短路及反向求最短路,累加最短时间,取最短时间的最大者 */#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>using namespace std;const int N = 1005;const int M = 100000;const i 阅读全文
posted @ 2012-04-19 07:02 Try86 阅读(134) 评论(0) 推荐(0)
pku 1797利用kruskal算法的过程
摘要:View Code /* Name: 利用kruskal算法的过程 Copyright: Author: Try86 Date: 18/04/12 20:58 Description: 求所有从起点到终点的路径上的最小边权的最大值 */#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;const int N = 1005;const int M = 1000005;int p[N], n, m;struct edge { int u; int v; int w; 阅读全文
posted @ 2012-04-18 21:05 Try86 阅读(153) 评论(0) 推荐(0)
pku 2263利用kruskal的过程+hash+二分
摘要:View Code /* Name: 利用kruskal的过程+hash+二分 Copyright: (处理字符串我写复杂了!) Author: Try86 Date: 18/04/12 20:26 Description: 求连接两点的路径上的最小边权的最大值 */#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>using namespace std;const int L = 35;const int S = 331;//hash表大小 const 阅读全文
posted @ 2012-04-18 20:39 Try86 阅读(162) 评论(0) 推荐(0)
hdu 1217最短路(bellmanFord)
摘要:View Code /* Name: 最短路(bellmanFord) Copyright: Author: Try86 Date: 18/04/12 13:50 Description: 判断是否从某一种货币出发经过一系列的转换后回到自身时,货币币值增加 */#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>using namespace std;const int N = 35;const int M = 1000;double d[N];char 阅读全文
posted @ 2012-04-18 17:32 Try86 阅读(181) 评论(0) 推荐(0)
hdu 1106(字符串处理+排序)
摘要:View Code /* Name: 字符串处理+排序 Copyright: Author: Try86 Date: 17/04/12 07:12 Description: */#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>using namespace std;const int N = 505;int num[N];int cmp(const void *a, const void *b) { return *(int *)a - *(int * 阅读全文
posted @ 2012-04-17 19:49 Try86 阅读(146) 评论(0) 推荐(0)
pku 1094(拓扑排序,多次拓扑)
摘要:View Code /* Name: 拓扑排序,多次拓扑 Copyright: Author: Try86 Date: 16/04/12 21:36 Description: */#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>using namespace std;const int N = 27;bool ch[N];char ans[N]; //存拓扑序 int inDeg[N]; //入度数 struct node { int v; node 阅读全文
posted @ 2012-04-16 22:06 Try86 阅读(147) 评论(0) 推荐(0)
hdu 1076(日期相关)
摘要:View Code /* Name: 日期相关 Copyright: Author: Try86 Date: 15/04/12 23:32 Description: */#include <cstdio>#include <iostream>using namespace std;bool isLeap(int year) { if (year%400==0 || year%4==0&&year%100!=0) return true; return false;} int main() { int t; scanf ("%d", & 阅读全文
posted @ 2012-04-16 07:34 Try86 阅读(240) 评论(0) 推荐(0)
hdu 1056(简单数学)
摘要:View Code /* Name: 简单数学 Copyright: Author: Try86 Date: 15/04/12 22:45 Description: */#include <cstdio>#include <iostream>using namespace std;int main() { double len; while (scanf("%lf", &len), len!=0.00) { double sum = 0; int i; for (i=2; sum<len; ++i) sum += 1.0/i;... 阅读全文
posted @ 2012-04-15 22:47 Try86 阅读(201) 评论(0) 推荐(0)
hdu 2647(拓扑排序,判断有向图是否存在回路及自环,并统计每个顶点的前驱点数)
摘要:View Code /* Name: 拓扑排序,判断有向图是否存在回路及自环,并统计每个顶点的前驱点数 Copyright: Author: Try86 Date: 15/04/12 22:25 Description: */#include <queue>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>using namespace std;const int N = 10005;int sum, flag;int counts[N];s 阅读全文
posted @ 2012-04-15 22:38 Try86 阅读(754) 评论(0) 推荐(0)
hdu 3342(利用拓扑排序过程判断有向图是否有回路及自环)
摘要:View Code /* Name: 利用拓扑排序过程判断有向图是否有回路及自环 Copyright: Author: Try86 Date: 15/04/12 21:15 Description: */#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>using namespace std;const int N = 105;int color[N], flag;struct node { int v; node *next; node(int vv, 阅读全文
posted @ 2012-04-15 21:31 Try86 阅读(332) 评论(0) 推荐(0)
hrbustOJ 最小生成树问题(kruskal)
摘要:View Code /* Name: 最小生成树(kruskal) Copyright: Author: Try86 Date: 15/04/12 08:01 Description: */#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;const int N = 10005;const int M = 50005;int p[N], sum;struct edge { int u; int v; int w;}e[M];int cmp(const void 阅读全文
posted @ 2012-04-15 08:10 Try86 阅读(200) 评论(0) 推荐(0)
hrbustOJ 欧拉路径(判断无向图是否连通+统计顶点的度数)
摘要:/* Name: 判断无向图是否连通+统计顶点的度数 Copyright: Author: Try86 Date: 14/04/12 23:02 Description: 邻接链表存图 */#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>using namespace std;const int N = 105;int deg[N]; //统计顶点的度数 bool map[N][N], color[N];struct node { int v; nod 阅读全文
posted @ 2012-04-15 07:36 Try86 阅读(535) 评论(0) 推荐(0)
pku 1659(判断可图化Havel-Hakiwi定理的应用)
摘要:/* Name: Havel-Hakiwi定理的应用 Copyright: Author: Try86 Date: 13/04/12 23:16 Description: */#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>using namespace std;int map[15][15], flag;struct node { int deg; //顶点度数 int ver; //顶点编号 }d[15];int cmp(const void *a 阅读全文
posted @ 2012-04-14 07:42 Try86 阅读(230) 评论(0) 推荐(0)
hdu 1196(位运算)
摘要:/* Name: 位运算应用 Copyright: Author: Try_86 Date: 12/04/12 22:24 Description: */#include <cstdio>#include <iostream>using namespace std;int main() { int a; while (scanf("%d", &a), a) printf ("%d\n", a&(a^(a-1))); return 0;} 阅读全文
posted @ 2012-04-12 22:27 Try86 阅读(154) 评论(0) 推荐(0)
hdu 2112(最短路+hash+二分)
摘要:/* Name: 最短路(dijkstra邻接矩阵)+hash判重并统计顶点数+二分查找返回顶点位置 Copyright: Author: Try_86 Date: 12/04/12 20:57 Description: 注意:起始点和终点不在给出的路线中的情况!!! */#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>using namespace std;const int S = 163; const int N = 155;const int 阅读全文
posted @ 2012-04-12 21:15 Try86 阅读(197) 评论(0) 推荐(0)
hdu 2544 最短路(dijkstra邻接矩阵)
摘要:/* Name: 最短路(dijkstra邻接矩阵) Copyright: Author: Try_86 Date: 12/04/12 18:09 Description: */#include <cstdio>#include <cstring>#include <iostream>using namespace std;const int N = 105; const int MAX = 1000000000;//定义无穷大 bool vis[N];int map[N][N], dis[N];void init(int vs) {//初始化 for (i 阅读全文
posted @ 2012-04-12 18:21 Try86 阅读(192) 评论(0) 推荐(0)
hdu 2066(最短路bellmanFord)
摘要:/* Name: 最短路(bellmanFord) Copyright: Author: Try_86 Date: 12/04/12 12:42 Description: 对每个起始点运行一次bellmanFord,求最短路 */#include <cstdio>#include <iostream>using namespace std;const int N = 1005;const int M = 500500;const int MAX = 1000000000;int dis[N], ss[N], ds[N];struct edge { int u; int. 阅读全文
posted @ 2012-04-12 12:47 Try86 阅读(255) 评论(0) 推荐(0)
hdu 3790(最短路BellmanFord)
摘要:984MS,真险!Bellman_Frod效率不高啊!/* Name: 最短路(bellmanFord) Copyright: Author: Try_86 Date: 11/04/12 21:16 Description: */#include <cstdio>#include <iostream>using namespace std;const int N = 1005;const int M = 200005;const int MAX = 1000000000;int dis[N], cs[N];struct edge { int u; int v; ... 阅读全文
posted @ 2012-04-11 21:19 Try86 阅读(284) 评论(0) 推荐(0)
hdu 2680(最短路bellmanFord)
摘要:843MS,差点就超时!/* Name: 最短路(bellmanFord) Copyright: Author: Try_86 Date: 11/04/12 20:39 Description: 建反向图,求终点到各点的最短路 */#include <cstdio>#include <iostream>using namespace std;const int N = 1005;const int M = 40005;const int MAX = 1000000000;int dis[N];struct edge { int u; int v; int w;}... 阅读全文
posted @ 2012-04-11 20:45 Try86 阅读(194) 评论(0) 推荐(0)
hdu 2544 最短路(Bellman_Ford)
摘要:/* Name: 最短路(Bellman_Ford) Copyright: Author: Try_86 Date: 11/04/12 19:56 Description: */#include <cstdio>#include <iostream>using namespace std;const int N = 205;const int M = 20005;const int MAX = 1000000000;int dis[N];struct edge { int u; int v; int w;}e[M];void init(int vs, int s... 阅读全文
posted @ 2012-04-11 20:04 Try86 阅读(196) 评论(0) 推荐(0)
hdu 1874(最短路Bellman_Ford)
摘要:/* Name: 最短路(bellmanFord) Copyright: Author: Try_86 Date: 11/04/12 19:03 Description: 求一对顶点间的最短路 注意:建立反向边时两端点的顺序 */#include <cstdio>#include <climits>#include <iostream>using namespace std;const int N = 205;const int M = 2005;const int MAX = 100000000;int dis[N]; struct edge {//边结点 阅读全文
posted @ 2012-04-11 19:40 Try86 阅读(280) 评论(0) 推荐(0)
hdu 1860(字符串处理)
摘要:/* Author: Try_86 Date: 11/04/12 18:28 Description: 字符串处理 */#include <cstdio>#include <cstring>#include <iostream>using namespace std;char pat[6], str[81];struct node { char c; int num;}s[5];void solve() { int lenP = strlen(pat); int lenS = strlen(str); for (int i=0; i<5; ++i) s 阅读全文
posted @ 2012-04-11 18:30 Try86 阅读(220) 评论(0) 推荐(0)
hdu 1859(计算几何)
摘要:/* Name: 计算几何 Author: Try_86 Date: 11/04/12 18:07 Description: 求x,y的最大最小值即可 */#include <cstdio>#include <climits>#include <iostream>using namespace std;int main() { int x, y, minx, miny, maxx, maxy; while (scanf("%d%d", &x, &y), x!=0 || y!=0){ minx = INT_MAX; miny 阅读全文
posted @ 2012-04-11 18:10 Try86 阅读(187) 评论(0) 推荐(0)
hdu 1316(java大数)
摘要:/** java大数*/import java.util.Scanner;import java.math.BigInteger;public class hdu1316{ public static void main(String args[]) { BigInteger []fib = new BigInteger[500]; fib[1] = BigInteger.ONE; fib[2] = new BigInteger("2"); for (int i=3; i<500; ++i) { ... 阅读全文
posted @ 2012-04-11 17:46 Try86 阅读(174) 评论(0) 推荐(0)
hdu 1201(日期计算)
摘要:/* Name: 日期计算 Author: Try_86 Date: 10/04/12 21:42*/#include <cstdio>#include <iostream>using namespace std;int days[13] = {0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};bool isLeap(int year) {//判断闰年 if ((year%400==0) || (year%4==0&&year%100!=0)) return true; return fa 阅读全文
posted @ 2012-04-10 21:45 Try86 阅读(326) 评论(0) 推荐(0)
hdu 1212(数学)
摘要:/* Name: 数学题 Author: Try_86 Date: 10/04/12 20:56*/#include <cstdio>#include <cstring>#include <iostream>using namespace std;int b;char a[1005];int solve() { int ans = 0; for (int i=0; a[i]; ++i) ans = (ans * 10 + a[i] - '0') % b; return ans; }int main() { while (scanf(" 阅读全文
posted @ 2012-04-10 20:58 Try86 阅读(153) 评论(0) 推荐(0)
hdu 1232(并查集)
摘要:/* Name: 并查集 Author: Try_86 Date: 10/04/12 20:11*/#include <cstdio>#include <iostream>using namespace std;const int M = 1000;int p[M], sum;void init(int n) { for (int i=1; i<=n; ++i) p[i] = i; return ;}int find(int x) { if (p[x] != x) p[x] = find(p[x]); return p[x];}void join(int x, . 阅读全文
posted @ 2012-04-10 20:12 Try86 阅读(181) 评论(0) 推荐(0)
hdu 1301(最小生成树kruskal)
摘要:/* Name: 最小生成树(kruskal) Author: Try_86 Date: 10/04/12 19:51*/#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;const int M = 700;int p[27], sum;struct edge { int a; int b; int w;}e[M];int cmp(const void *a, const void *b) { return (*(edge *)a).w - (*(edge *) 阅读全文
posted @ 2012-04-10 19:53 Try86 阅读(240) 评论(0) 推荐(0)
hdu 1162(最小生成树kruskal)
摘要:/* Name: 最小生成树(kruskal) Author: Date: 10/04/12 19:17*/#include <math.h>#include <cstdio>#include <iostream>using namespace std;const int M = 5050;int p[101], sum;struct edge { int a; int b; double dis;}e[M];struct point { double x; double y;}po[101];int cmp(const void *a, const v.. 阅读全文
posted @ 2012-04-10 19:20 Try86 阅读(228) 评论(0) 推荐(0)
hdu 1875(最小生成树kruskal)
摘要:/* Name: 最小生成树(kruskal) Author: Try_86 Date: 10/04/12 18:51 Description: 不符合题意所述的距离不加进边集中,然后套用kruskal就可以了 */#include <cmath>#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;const int M = 5050;int p[M], sum;struct edge { int a; int b; double dis;}e[M]; 阅读全文
posted @ 2012-04-10 18:55 Try86 阅读(289) 评论(0) 推荐(0)
hdu 1863(最小生成树kruskal)
摘要:/* Name: hdu1863畅通工程 Author: Try86 Date: 10/04/12 12:43 Description: 最小生成树(kruskal) */#include <cstdio>#include <iostream>using namespace std;const int M = 5050;int p[M], sum; //sum统计顶点个数 struct edge { int a; int b; int w;}e[M];int cmp(const void *a, const void *b) { return (*(edge ... 阅读全文
posted @ 2012-04-10 12:47 Try86 阅读(910) 评论(0) 推荐(0)
hdu 1879(最小生成树kruskal)
摘要:/** 最小生成树,(kruskal) * 本题要点:当两点之间已有路时,把这两点的路长设为0,然后就是套用kruskal了 */#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;const int M = 5050;int p[M];struct edge {//边节点 int a; int b; int w;}e[M];int cmp(const void *a, const void *b) {//按权值从小到大排序 return (*(edge *)a) 阅读全文
posted @ 2012-04-09 22:57 Try86 阅读(569) 评论(0) 推荐(0)
hdu 1233(最小生成树kruskal)
摘要:/** 最小生成树练手题,采用kruskal求解 */#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>using namespace std;const int M = 5050;int p[M];struct edge {//边节点 int a; int b; int w;}e[M];int cmp(const void *a, const void *b) {//按权值从小到大排序 return (*(edge *)a).w - (*(edge * 阅读全文
posted @ 2012-04-09 22:15 Try86 阅读(200) 评论(0) 推荐(0)
hdu 1496(hash)
摘要:/** hash+数学,很好的题 * 对整数求hash,采用除余法,及线性探测解决冲突 * 注意:devc++中不能定义全局变量count,它和库函数中的函数名同名了 */#include <cstdio>#include <cstring>#include <iostream>using namespace std;const int M = 175447;int counts[M];int result[M];int temp[101];int hashInt(int s) { int k = s % M; if (k < 0) k += M; w 阅读全文
posted @ 2012-04-09 21:05 Try86 阅读(249) 评论(0) 推荐(0)
hdu 1425(hash)
摘要:/** hash*/#include <cstdio>#include <climits>#include <cstring>#include <iostream>using namespace std;const int M = 1000001;bool hash[M];void init() { for (int i=0; i<M; ++i) hash[i] = false; return ; }int main() { int n, m, maxm; while (scanf("%d%d", &n, &am 阅读全文
posted @ 2012-04-09 19:54 Try86 阅读(221) 评论(0) 推荐(0)
hdu 1800(hash)
摘要:/** 分析:题意要求找字符串个数最多的一个* 方法:很多,hash就是其中一种 * 注意两点:1.去掉前导0; 2.每组测试数据后,要释放内存 * 第一点解析:例如数据01,001,0001, 00001不去前导0的话,hash以后映射到不同的表位置 *//* Author: Try86 Date: 09/04/12 18:01*/#include <cstdio>#include <cstring>#include <iostream>using namespace std;const int M = 5471; //hash表大小struct node 阅读全文
posted @ 2012-04-09 18:37 Try86 阅读(560) 评论(0) 推荐(0)
hdu 1075(hash)
摘要://字符串hash练手题,采用拉链式解决冲突 #include <cstdio>#include <cstring>#include <iostream>using namespace std;const int M = 43853;//hash表大小 struct node {//节点 char str1[11]; char str2[11]; node *next; };struct hashTable {//hash表 node *link;}hash[M];char text[3005];char str1[11], str2[11], ch[11] 阅读全文
posted @ 2012-04-09 17:49 Try86 阅读(166) 评论(0) 推荐(0)
hdu 1124(数论)
摘要://数论,n!末尾0的个数/*摘自:KIDxの博客N! = 1 * 2 * 3 * (2*2) * 5 * (2*3) * 7... 产生10的原因是有2,5的因子,显然在N!中2的个数大于5的个数,所以只需求出5的个数即可 求 N! (1*2*3*4*5*...*N)里有多少个5其实可以转化成: N!中:是5的倍数的数+是5^2的倍数的数+5^3..... 如50!: 含有10个5的倍数的数:5,15,20,25,30,35,40,45,50 【50/5=10】 含有2个5^2的倍数的数:25,50【50/(5^2)=2】 可见N!中一共有12个5相乘,那么尾0也必有12个 */#inclu 阅读全文
posted @ 2012-04-06 21:00 Try86 阅读(169) 评论(0) 推荐(0)
hdu 1062(字符串处理)
摘要://字符串处理#include <cstdio>#include <cstring>#include <iostream>using namespace std;char text[1005];void solve() { int l = strlen(text); int i, j, k; for (i=0; i<l; ) { if (text[i] != ' ') { for (j=i; text[j]!=' ' && j<l; ++j); for (k=j-1; k>=i; --k) p 阅读全文
posted @ 2012-04-06 20:45 Try86 阅读(163) 评论(0) 推荐(0)
hdu 1250(java大数)
摘要://java大数import java.util.Scanner;import java.math.BigInteger;public class hdu1250{ public static void main(String args[]) { Scanner cin = new Scanner(System.in); int n; while (cin.hasNextInt()) { n = cin.nextInt(); if (n <= 4) { ... 阅读全文
posted @ 2012-04-05 22:00 Try86 阅读(220) 评论(0) 推荐(0)
hdu 1259(模拟)
摘要://模拟#include <cstdio>#include <iostream>using namespace std;void swap(char &a, char &b) { char temp = a; a = b; b = temp;}int main() { int t, i; scanf ("%d", &t); while (t--) { int n, x, y; char s[9] = {"#ZJUTACM"}; scanf ("%d", &n); for (i=0 阅读全文
posted @ 2012-04-05 21:40 Try86 阅读(157) 评论(0) 推荐(0)
hdu 1261(组合数+java大数)
摘要:设多重集的个数n = n1 + n2 + ... + nk;则该多重集的排列个数为:n!/(n1!n2!...nk!).//组合数+java大数import java.util.Scanner;import java.math.BigInteger;public class hdu1261{ public static void main(String args[]) { Scanner cin = new Scanner(System.in); BigInteger f1, f2; int []s = new int[26]; int n, sum; n = cin.nextIn... 阅读全文
posted @ 2012-04-05 21:04 Try86 阅读(402) 评论(0) 推荐(0)
hdu 1249(递推)
摘要://递推,f(i) = f(i-1) + 6 * (i-1); f[1] = 2, i>=2;#include <cstdio>#include <iostream>using namespace std;int f[10001];int main() { int i; f[1] = 2; for (i=2; i<10001; ++i) f[i] = f[i-1] + 6 * (i - 1); int t; scanf ("%d", &t); while (t--) { int n; scanf ("%d", 阅读全文
posted @ 2012-04-05 18:30 Try86 阅读(258) 评论(0) 推荐(0)
二进制逆序(分治思想)
摘要:实现自Matrix67!//二进制逆序//分治思想//程序读入一个32位整数并输出它的二进制倒序后所表示的数#include <stdio.h>int main() { int n; while (scanf("%d", &n) != EOF) { n = (n & 0x55555555) << 1 | (n & 0xAAAAAAAA) >> 1; n = (n & 0x33333333) << 2 | (n & 0xCCCCCCCC) >> 2; n = (n & 阅读全文
posted @ 2012-04-05 12:53 Try86 阅读(396) 评论(0) 推荐(0)
位运算的应用续
摘要://用异或运算交换两个整数#include <stdio.h>int main() { int a, b; while (scanf("%d%d", &a, &b) != EOF) { a = a ^ b; b = a ^ b; a = a ^ b; printf ("%d %d\n", a, b); } return 0;}//用位运算来取绝对值#include <stdio.h>int main() { int n; while (scanf("%d", &n) != EOF) { 阅读全文
posted @ 2012-04-05 12:25 Try86 阅读(160) 评论(0) 推荐(0)
高低位交换
摘要:实现自Matrix67!//定义:32位的整数的前16位为高位,后16位为低位//高低位交换#include <stdio.h>int main() { int n; while (scanf("%d", &n) != EOF) { int s, s1, s2; s1 = ((1 << 16) - 1) & n; s2 = s1 ^ n; s = (s1 << 16) | (s2 >> 16); printf ("%d\n", s); } return 0;}//定义:32位的整数的前16位 阅读全文
posted @ 2012-04-05 12:18 Try86 阅读(444) 评论(0) 推荐(0)
计算二进制中的1的个数
摘要:实现自Matrix67!//计算二进制中的1的个数//分治思想#include <stdio.h>int main() { int n; while (scanf("%d", &n) != EOF) { n = (n & 0x55555555) + ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); n = (n & 0x0F0F0F0F) + ((n >> 4) & 0x0F0 阅读全文
posted @ 2012-04-05 12:13 Try86 阅读(204) 评论(0) 推荐(0)
二进制中的1有奇数个还是偶数个
摘要:实现自Matrix67!//二进制中的1有奇数个还是偶数个//实现一#include <stdio.h>int main() { int n; while (scanf("%d", &n) != EOF) { int c = 0; while (n) { c += n & 1; n >>= 1; } if (c & 1) printf ("奇数个\n"); else printf ("偶数个\n"); } return 0;}//实现二//分治思想#inc... 阅读全文
posted @ 2012-04-05 12:12 Try86 阅读(565) 评论(0) 推荐(0)
二分查找32位整数的前导0个数
摘要:参考自Matrix67!//二分查找32位整数的前导0个数//二分查找思想#include <stdio.h>int main() { unsigned int n; while (scanf("%u", &n) != EOF) { if (n == 0) printf ("32\n"); else { int s = 1; if ((n >> 16) == 0) {s += 16; n <<= 16;} if ((n >> 24) == 0) {s += 8; n <<= 8;} .. 阅读全文
posted @ 2012-04-05 12:10 Try86 阅读(646) 评论(0) 推荐(0)
位运算的简单应用(C实现)
摘要:详细理论请参考Matrix67!//去掉最后一位,相当于除于2#include <stdio.h>int main() { int n; while (scanf("%d", &n) != EOF) { printf ("%d\n", n>>1); } return 0;}//在最后加一个0,相当于乘于2#include <stdio.h>int main() { int n; while (scanf("%d", &n) != EOF) { printf ("%d\n&q 阅读全文
posted @ 2012-04-05 07:39 Try86 阅读(209) 评论(0) 推荐(0)
hdu 1222(数论)
摘要://数论,判断两数是否互质#include <cstdio>#include <iostream>using namespace std;int gcd(int a, int b) { return b ? gcd(b, a%b) : a;}int main() { int t; scanf ("%d", &t); while (t--) { int n, m; scanf ("%d%d", &m, &n); if (gcd(n, m) == 1) printf ("NO\n"); el 阅读全文
posted @ 2012-04-04 20:52 Try86 阅读(133) 评论(0) 推荐(0)
hdu 1219(字符串处理)
摘要://简单字符串处理#include <cstdio>#include <cstring>#include <iostream>using namespace std;char text[100005];int s[26];int main() { while (gets(text)) { int l = strlen(text); int i; for (i=0; i<26; ++i) s[i] = 0; for (i=0; i<l; ++i) ++s[text[i]-'a']; for (i=0; i<26; ++i... 阅读全文
posted @ 2012-04-04 20:13 Try86 阅读(220) 评论(0) 推荐(0)
hdu 1220(数学)
摘要://数学,没化简,直接用#include <cstdio>#include <iostream>using namespace std;int main() { int n; while (scanf("%d", &n) != EOF) { int s = n * n * n; int ans = (s-4)*4 + 6*(n-2)*(s-5) + 3*(n-2)*(n-2)*(s-6) + (n-2)*(n-2)*(n-2)*(s-7)/2; printf ("%d\n", ans); } return 0;} 阅读全文
posted @ 2012-04-04 20:04 Try86 阅读(162) 评论(0) 推荐(0)
hdu 1060(数学)
摘要://数学//参考______________白白の屋/*m=n^n,两边分别对10取对数得 log10(m)=n*log10(n),得m=10^(n*log10(n)),由于10的任何整数次幂首位一定为1,所以m的首位只和n*log10(n)的小数部分有关*/#include <cmath>#include <cstdio>#include <iostream>using namespace std;int main() { int t; scanf ("%d", &t); while (t--) { int n; scanf ( 阅读全文
posted @ 2012-04-04 16:58 Try86 阅读(207) 评论(0) 推荐(0)
hdu 1041(规律+打表+java大数)
摘要:串中出现01时,在下一步后就会出现连续的两个0规律:i为偶数时:f[i] = f[i-1] * 2 + 1; i为奇数时:f[i] = f[i-1] * 2 - 1。//规律+打表+java大数import java.util.Scanner;import java.math.BigInteger;public class CT{ public static void main(String args[]) { Scanner cin = new Scanner(System.in); BigInteger []f = new BigInteger[10... 阅读全文
posted @ 2012-04-04 14:59 Try86 阅读(238) 评论(0) 推荐(0)
hdu 1042(java大数)
摘要://java大数import java.util.Scanner;import java.math.BigInteger;public class NF{ public static void main(String args[]) { int n; Scanner cin = new Scanner(System.in); BigInteger sum; while (cin.hasNextInt()) { n = cin.nextInt(); sum = new B... 阅读全文
posted @ 2012-04-04 13:51 Try86 阅读(198) 评论(0) 推荐(0)
hdu 1020(模拟)
摘要://模拟#include <cstdio>#include <cstring>#include <iostream>using namespace std;char str[10001];void solve() { int l = strlen(str); int c = 1; char ch = str[0]; for (int i=1; i<l; ++i) { if (ch == str[i]) ++c; else { if (c > 1) printf ("%d%c", c, ch); el... 阅读全文
posted @ 2012-04-04 11:43 Try86 阅读(144) 评论(0) 推荐(0)
hdu 1019(gcd & lcm)
摘要://数论,gcd & lcm相关//该题有只有一个数据的测试组#include <cstdio>#include <iostream>int gcd(int a, int b) { return b ? gcd(b, a%b) : a;}int lcm(int a, int b) { return a / gcd(a, b) * b;}int main() { int t; scanf ("%d", &t); while (t--) { int n, a, b, i; scanf ("%d%d", &n, 阅读全文
posted @ 2012-04-04 11:34 Try86 阅读(128) 评论(0) 推荐(0)
hdu 1018(数学)
摘要:编辑器加载中/*由斯特林[striling]公式可得: lnN!=NlnN-N+0.5ln(2N*pi) log10(N!)=lnN!/ln(10) 一个数字的位数,由对数来求。log10() // 求以10为底的对数log() // 以e为底的对数*///数学题#include <cmath>#include <cstdio>#include <iostream>using namespace std;const double PI = 3.14159265;int main() { int t; scanf ("%d", &t 阅读全文
posted @ 2012-04-04 11:01 Try86 阅读(140) 评论(0) 推荐(0)
hdu 1014(数学)
摘要://数学题#include <cstdio>#include <iostream>using namespace std;int gcd(int a, int b) { return b ? gcd(b, a%b) : a;}int main() { int n, m; while (scanf("%d%d", &n, &m) != EOF) { printf ("%10d%10d", n, m); if (gcd(n, m) == 1) printf (" Good Choice\n\n"); 阅读全文
posted @ 2012-04-04 10:14 Try86 阅读(156) 评论(0) 推荐(0)
hdu 1013(数学)
摘要://数学题,循环周期为9#include <cstdio>#include <cstring>#include <iostream>using namespace std;char n[1005];int main() { while (scanf("%s", &n), strcmp(n, "0")!=0) { int sum = 0; int l =strlen(n); for (int i=0; i<l; ++i) { sum += n[i] - '0'; sum %= 9; } .. 阅读全文
posted @ 2012-04-04 09:58 Try86 阅读(129) 评论(0) 推荐(0)
hdu 1013(模拟)
摘要://模拟,注意题中没有给出数据的大小#include <cstdio>#include <cstring>#include <iostream>using namespace std;char n[1005];int solve() { int sum = 0; int l = strlen(n); for (int i=0; i<l; ++i) sum += n[i] - '0'; if (sum > 9) { int s, m; s = m = sum; sum = 0; while (s > 9) { ... 阅读全文
posted @ 2012-04-04 09:44 Try86 阅读(132) 评论(0) 推荐(0)
hdu 1012(简单数学题)
摘要://简单数学题#include <cstdio>#include <iostream>using namespace std;int main() { int i; double s, sum; printf ("n e\n"); printf ("- -----------\n"); printf ("0 1\n"); printf ("1 2\n"); printf ("2 2.5\n"); printf ("3 2.666666667\n"); 阅读全文
posted @ 2012-04-04 09:09 Try86 阅读(167) 评论(0) 推荐(0)
hdu 1009(贪心)
摘要://贪心,比例从大往后贪#include <cstdio>#include <cstdlib>#include <iostream>using namespace std;struct node { double j; double f; double c;}s[100000];int cmp(const void *a, const void *b) { node *c = (node *)a; node *d = (node *)b; if (c->c > d->c) return -1; return 1;}int main() { 阅读全文
posted @ 2012-04-04 08:50 Try86 阅读(156) 评论(0) 推荐(0)
hdu 1008(简单数学)
摘要://简单数学题#include <cstdio>#include <iostream>using namespace std;int main() { int n; while (scanf("%d", &n), n) { int time = 0; int one, two; one = 0; for (int i=0; i<n; ++i) { scanf ("%d", &two); if (one < two) time += (two - one) * 6; ... 阅读全文
posted @ 2012-04-04 08:20 Try86 阅读(186) 评论(0) 推荐(0)
hdu 1005(规律)
摘要://循环节#include <cstdio>#include <iostream>using namespace std;int f[49];int main() { int i; f[1] = f[2] = 1; int a, b, n; while (scanf("%d%d%d", &a, &b, &n), a+b+n) { for (i=3; i<49; ++i) f[i] = (a * f[i-1] + b * f[i-2]) % 7; printf ("%d\n", f[n%48]); } 阅读全文
posted @ 2012-04-03 22:21 Try86 阅读(147) 评论(0) 推荐(0)
hdu 1004(hash)
摘要://hash#include <cstdio>#include <cstring>#include <iostream>using namespace std;const int M = 1361;struct node {//节点 char str[16]; int count; node *next;}s[M];int maxs;char ans[16];void init() {//初始化 for (int i=0; i<M; ++i) { s[i].next = NULL; s[i].count = 0; }}unsigned ... 阅读全文
posted @ 2012-04-03 21:23 Try86 阅读(205) 评论(0) 推荐(0)
hdu 1004(排序+统计)
摘要://排序+统计#include <cstdio>#include <cstring>#include <iostream>using namespace std;char str[1000][16];int cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b);}int solve(int n) { char temp[16]; int i, c, maxs, mi; qsort(str, n, sizeof(str[0]), cmp); strcpy(temp, st 阅读全文
posted @ 2012-04-03 20:40 Try86 阅读(157) 评论(0) 推荐(0)
hdu 1002(java大数)
摘要:import java.math.BigInteger;import java.util.Scanner;public class Main{ public static void main(String args[]) { Scanner reader = new Scanner(System.in); int t, cas; cas = 0; t = reader.nextInt(); while ((t--) != 0) { BigInteger a, b, c; ... 阅读全文
posted @ 2012-04-03 20:05 Try86 阅读(267) 评论(0) 推荐(0)
hdu 1001(分治求解)
摘要:#include <cstdio>#include <iostream>using namespace std;int solve(int l, int r) { if (l == r) return l; return solve(l, ((l+r)>>1)) + solve(((l+r)>>1)+1, r);}int main() { int n; while (scanf("%d", &n) != EOF) { int ans = solve(1, n); printf ("%d\n\n", 阅读全文
posted @ 2012-04-03 19:28 Try86 阅读(204) 评论(0) 推荐(0)