hdu
luckycoding
luckycoding只会失败!绝对不允许放弃!
展开
-
hdu 1166 敌兵布阵
题意:求区间和连接点击打开链接#include #include __int64 tree[50005];int MaxVal;void update ( int idx, __int64 val ){ while ( idx <= MaxVal ) { tree[idx] += val; idx += ( idx & - idx ); }}__i原创 2012-06-01 15:05:17 · 281 阅读 · 0 评论 -
hdu1787-GCD Again
http://acm.hdu.edu.cn/showproblem.php?pid=1787#include#include#include#includeusing namespace std ;#define INT __int64int enlerfun( int n ){ int tempnum = 1 ; int i ; for( i = 2 ; i *原创 2013-06-08 13:29:36 · 1044 阅读 · 0 评论 -
hdu1286-找新朋友
http://acm.hdu.edu.cn/showproblem.php?pid=1286本来可以直接用普通的欧拉函数,但是,这个那样非常容易TLE,所以用素数筛法+欧拉函数;#include#include#include#includeusing namespace std ;#define maxn 100005int prime[ maxn + 1 ] ;int原创 2013-06-07 22:00:11 · 1124 阅读 · 0 评论 -
hdu2824-The Euler function
http://acm.hdu.edu.cn/showproblem.php?pid=2824why?搞不懂为什么用素数筛法+欧拉函数就是过不了,只能使用简单点的了#include#include#includeusing namespace std; #define maxn 3000010#define INT __int64 int Prime[ maxn + 1 ]原创 2013-06-07 22:43:21 · 1094 阅读 · 0 评论 -
hdu1128-Self Numbers
http://acm.hdu.edu.cn/showproblem.php?pid=1128题意为找出从1开始的所有自私数,自私数满足,对于所有数据本身加上各个数位上和不会等于的数,就称为自私数#include#include#include using namespace std ;#define MAX 1000005int num[ MAX ] ;int jud原创 2013-06-14 18:55:36 · 792 阅读 · 0 评论 -
hdu1061-Rightmost Digit(附快速幂简单原理)
http://acm.hdu.edu.cn/showproblem.php?pid=10611.快速幂实现a^N求3^999(a=3,N=999):3 ^ 999 = 3 * 3 * 3 * … * 3,直接乘要做998次乘法。快速幂方法实质使用了二分法进行时间优化: tmp+ = tmp-* a-;3 ^ 1 = 3* 13 ^ 2 = (3原创 2013-06-09 15:46:05 · 838 阅读 · 0 评论 -
hdu1174-爆头
http://acm.hdu.edu.cn/showproblem.php?pid=1174之前没搞懂,想得太复杂了,从网上查了很多代码,但是很混乱,各种方法都有,不过,最终还是理清楚了 ;其中,就被高数中点向法,还有其他几种解法造成的误解最大;数学叉积公式 ,点B到直线AC的距离 就是 |AB X AC|/|AC| ‘X’是叉乘 ’ || ‘表示模 ;其次,这题需要注意的原创 2013-06-09 22:28:08 · 911 阅读 · 0 评论 -
hdu2060-Snooker
http://acm.hdu.edu.cn/showproblem.php?pid=2060题意为,给你场上剩下的球数m , 和 a ,b 两名队员目前得分,现在假设a将所有的球m都打入洞中,然后让你输出是否最终a的得分会超过b; 总共有15个红球,和6个有颜色的球,每个红球的得分为1 ,6个有颜色的球分别为2 , 3, 4 ,5, 6, 7 ;原创 2013-06-09 18:16:25 · 1378 阅读 · 0 评论 -
hdu1568-Fibonacci
http://acm.hdu.edu.cn/showproblem.php?pid=1568用到了斐波那契数列的通项公式。先看对数的性质,loga(b^c)=c*loga(b),loga(b*c)=loga(b)+loga(c);假设给出一个数10234432,那么log10(10234432)=log10(1.0234432*10^7)=log10(1.0234432)+7;原创 2013-06-08 16:09:33 · 781 阅读 · 0 评论 -
hdu4556-Stern-Brocot Tree
http://acm.hdu.edu.cn/showproblem.php?pid=4556#include#include#includeusing namespace std ;#define maxn 1000005#define INT __int64INT ans[ maxn + 1] ;void enlerfun(){ memset( ans , 0 , si原创 2013-06-08 14:41:23 · 834 阅读 · 0 评论 -
hdu3117-Fibonacci Numbers
http://acm.hdu.edu.cn/showproblem.php?pid=3117后四位存在周期15000,所以就打表打出了后四位的值。前四位按照Fibonacci的通项公式取前四位即可#include#include#include#includeusing namespace std;int fi[ 100 ] = { 0 , 1 , 1 } ;int L原创 2013-06-08 18:57:45 · 759 阅读 · 0 评论 -
hdu3501-Calculation 2
http://acm.hdu.edu.cn/showproblem.php?pid=3501这题参考了别人的代码,才知道原来当数据较大时求解前n 项的欧拉函数和,可以直接利用 n * enlerfun( n) / 2求解,而此题要求的是非互质的,同样可以使用这个性质#include#include#includeusing namespace std ;#define MOD原创 2013-06-08 14:07:57 · 772 阅读 · 0 评论 -
hdu1081-To The Max
http://acm.hdu.edu.cn/showproblem.php?pid=1081DP,最大矩阵和,首先将横坐标的数值,分别求和存储在二维数组中,然后使用三个for循环,第一二层分别表示第I 横层 ,和第j 横层,然后做差,就求出了纵坐标的和,当sum〉0就由k 向右累加;#include#include#includeusing namespace std ;int原创 2013-06-09 14:36:25 · 741 阅读 · 0 评论 -
hdu 4408 Minimum Spanning Tree
题目连接:点击打开链接解法:利用kruskal算法 把图划分成森林, 同一点有相同最小的权值到别的点, 通过determinant计算树的课数。总结:模板 + 自己不太懂 = 记录 + 重新学代码君:#include #include #include #define LL long longusing namespace std;const int MAX = 105原创 2012-11-12 16:41:11 · 1642 阅读 · 0 评论 -
hdu1290
http://acm.hdu.edu.cn/showproblem.php?pid=1290 这道题主要是平面划分空间的递推公式。貌似初中好像学过。。。都忘了,晕还上网看了 推导公式、 (1)n条直线,最多可以把平面分为多少个区域。当有n-1条直线时,平面最多被分成了f(n-1)个区域。则第n条直线要是切成的区域数最多,就必须与每条直线相交且不能有同一交点。 这样就原创 2012-06-09 22:54:44 · 402 阅读 · 0 评论 -
HDU 1443 约瑟夫问题
Problem DescriptionThe Joseph\\\\\\\'s problem is notoriously known. For those who are not familiar with the original problem: from among n people, numbered 1, 2, . . ., n, standing in circle every原创 2012-06-04 00:38:23 · 556 阅读 · 0 评论 -
hdu1250-Hat's Fibonacci
http://acm.hdu.edu.cn/showproblem.php?pid=1250二维大数处理#include#include#include#includeusing namespace std ;#define maxm 10005#define maxn 305 int fi[ maxm ][ maxn ] ;void Add(){ memset(原创 2013-06-08 16:51:34 · 823 阅读 · 0 评论