随笔分类 -  HDOJ

上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 24 下一页

发布一些HDOJ的做题情况以及代码。
[恢]hdu 2077
摘要:2011-12-16 23:24:42地址:http://acm.hdu.edu.cn/showproblem.php?pid=2077题意:中文。mark:递推。dp[i][0]表示i个盘子从两边杆移到两边杆的次数,dp[i][1]表示i个盘子从两边杆移到中间杆的次数。有dp[i][0] = 3*dp[i-1][0] + 2,dp[i][1] = dp[i-1][0]+dp[i-1][1]+1。然后答案应该是dp[n-1][1]*2+2。数据大约是3^20,没超过int。代码:# include <stdio.h>int dp[25][2] = {0, 0, 2, 1} ;int 阅读全文

posted @ 2012-01-06 17:43 Seraph2012 阅读(199) 评论(0) 推荐(0)

[恢]hdu 2187
摘要:2011-12-16 22:36:47地址:http://acm.hdu.edu.cn/showproblem.php?pid=2187题意:中文,不说了。mark:1wa,莫名其妙地多拍了一个return0在循环里,2B了。代码:# include <stdio.h># include <stdlib.h>typedef struct node{ int p, m ;}node ;node a[1010] ;int cmp(const void *a, const void *b){ node* p = (node*)a, *q = (node*)b ; return 阅读全文

posted @ 2012-01-06 17:42 Seraph2012 阅读(158) 评论(0) 推荐(0)

[恢]hdu 1050
摘要:2011-12-16 23:03:04地址:http://acm.hdu.edu.cn/showproblem.php?pid=1050题意:一个过道,旁边有如图所示分布的办公室。有n张桌子,分别要从s[i]搬到t[i],每张桌子要搬10min,同一段过道内同一个时间只能有一张桌子存在。问最少需要的分钟数。mark:其实就是最大重叠数。wa了一次,注意同一个点出来的两张桌子,如果一个往左,一个往右,不可以同时进行。代码:# include <stdio.h># include <stdlib.h>typedef struct node{ int a, b ;}node 阅读全文

posted @ 2012-01-06 17:42 Seraph2012 阅读(188) 评论(0) 推荐(0)

[恢]hdu 1009
摘要:2011-12-16 14:17:21地址:http://acm.hdu.edu.cn/showproblem.php?pid=1009题意:老鼠拿了m克猫食换豆子。n个屋子,每个屋子有豆子j,猫食f。可以只换一部分。问最多能得到多少豆子。mark:简单贪心。代码:# include <stdio.h># include <stdlib.h>typedef struct node{ int j, f ;}node ;node a[1010] ;int cmp(const void *pp, const void *qq){ node *p = (node*)pp, *q 阅读全文

posted @ 2012-01-06 17:41 Seraph2012 阅读(164) 评论(0) 推荐(0)

[恢]hdu 1248
摘要:2011-12-16 13:29:06地址:http://acm.hdu.edu.cn/showproblem.php?pid=1248题意:中文,不解释。mark:首先,mod50后多出来的部分肯定是要浪费的。然后50的倍数部分,只有n < 150和n == 250才会无法付清,其余的都可以不浪费超过50。代码:# include <stdio.h>int main (){ int n, sum ; scanf ("%d", &n) ; while (~scanf ("%d", &n)) { sum = n%50 ; 阅读全文

posted @ 2012-01-06 17:40 Seraph2012 阅读(116) 评论(0) 推荐(0)

[恢]hdu 1282
摘要:2011-12-16 13:59:48地址:http://acm.hdu.edu.cn/showproblem.php?pid=1282题意:中文,不解释。代码:# include <stdio.h>int reverse(int n){ int ans = 0 ; while (n) { ans = ans * 10 + n%10 ; n /= 10 ; } return ans ;}int calc(int n){ int cnt = 0 ; while(n!=reverse(n)) { n = n+... 阅读全文

posted @ 2012-01-06 17:40 Seraph2012 阅读(189) 评论(0) 推荐(0)

[恢]hdu 1222
摘要:2011-12-16 13:12:53地址:http://acm.hdu.edu.cn/showproblem.php?pid=1222题意:有n个洞围成1圈,标号为0-n-1。狼从0开始搜索洞,下一次搜索是从上一次往后数m个。给n和m,问是否有安全洞,狼是搜不到的。mark:其实就是问gcd(m,n) 是否不为1。代码:# include <stdio.h>int gcd(int a, int b){return a%b?gcd(b,a%b):b;}int main (){ int T, n, m ; scanf ("%d", &T) ; while 阅读全文

posted @ 2012-01-06 17:39 Seraph2012 阅读(129) 评论(0) 推荐(0)

[恢]hdu 2104
摘要:2011-12-16 13:17:13地址:http://acm.hdu.edu.cn/showproblem.php?pid=2104题意:丢手绢,其实和1222一样。代码:# include <stdio.h>int gcd(int a, int b){return a%b?gcd(b,a%b):b;}int main (){ int n, m ; while (~scanf ("%d%d", &n, &m)) { if (n==-1&&m==-1) break ; puts (gcd(n,m) == 1 ? "YE 阅读全文

posted @ 2012-01-06 17:39 Seraph2012 阅读(126) 评论(0) 推荐(0)

[恢]hdu 2153
摘要:2011-12-16 12:50:14地址:http://acm.hdu.edu.cn/showproblem.php?pid=2153题意:中文,模拟。。。代码:# include <stdio.h># include <String.h>int dp[15][15] ;void gao(int n){ int i, tab[4][2] = {0, 1, 1, 0, 0 , -1, -1, 0} ; int d = 0, x, y ; memset (dp, 0, sizeof(dp)) ; dp[1][1] = 1 ; x = 1, y = 2 ; fo... 阅读全文

posted @ 2012-01-06 17:38 Seraph2012 阅读(222) 评论(0) 推荐(0)

[恢]hdu 1200
摘要:2011-12-16 13:07:53地址:http://acm.hdu.edu.cn/showproblem.php?pid=1200题意:把一串字符竖着写成n列,得到一张表。现在横着把表的每行拼成一个字符串,其中奇数行(从0开始)反着拼。给你这个字符串求原来的加密前的字符串。代码:# include <stdio.h>char str[210] ;char dp[110][20] ;int main (){ int i, j, cnt ; int n, d, x, y ; while (~scanf ("%d%*c", &n) && 阅读全文

posted @ 2012-01-06 17:38 Seraph2012 阅读(171) 评论(0) 推荐(0)

[恢]hdu 1266
摘要:2011-12-16 12:34:22地址:http://acm.hdu.edu.cn/showproblem.php?pid=1266题意:把数字反过来输出,如果末尾有0,保持在末尾。代码:# include <stdio.h># include <math.h>void reverse(int n){ if (n == 0) return ; printf ("%d", n%10) ; reverse(n/10) ;}void output(int n){ int zero = 0 ; if (n == 0){ puts ("0&quo 阅读全文

posted @ 2012-01-06 17:37 Seraph2012 阅读(170) 评论(0) 推荐(0)

[恢]hdu 1128
摘要:2011-12-16 12:20:57地址:http://acm.hdu.edu.cn/showproblem.php?pid=1128题意:d(n)被定义为n各位数码和+n。输出[1,1000000]内不存在i使得d(i)==n的所有n。mark:直接搜,开个100w的数组。代码:# include <stdio.h>int dp[1000010] ;int d(int n){ int sum = 0, nn = n ; while (nn) { sum += nn%10 ; nn /= 10 ; } return n + sum ;... 阅读全文

posted @ 2012-01-06 17:36 Seraph2012 阅读(141) 评论(0) 推荐(0)

[恢]hdu 2080
摘要:2011-12-16 12:27:38地址:http://acm.hdu.edu.cn/showproblem.php?pid=2080题意:中文,水。代码:# include <stdio.h># include <math.h>int main (){ int T ; double x1,y1,x2,y2,s1,s2,a1,a2, a ; scanf ("%d", &T) ; while (T--) { scanf ("%lf%lf%lf%lf", &x1, &y1, &x2, &y2) 阅读全文

posted @ 2012-01-06 17:36 Seraph2012 阅读(157) 评论(0) 推荐(0)

[恢]hdu 2105
摘要:2011-12-16 12:01:00地址:http://acm.hdu.edu.cn/showproblem.php?pid=2105题意:给3个点的坐标代表一个三角形,求三角形的重心(三条中线的交点)。mark:计算几何果断在mathematica的帮助下很给力!代码:# include <stdio.h>typedef struct POINT{ double x, y ;}POINT ;typedef struct LINE{ double a, b, c ; //ax+by+c == 0}LINE ;POINT tri[3] ;POINT Middle(POINT p1, 阅读全文

posted @ 2012-01-06 17:35 Seraph2012 阅读(211) 评论(0) 推荐(1)

[恢]hdu 2132
摘要:2011-12-16 12:11:14地址:http://acm.hdu.edu.cn/showproblem.php?pid=2132题意:求sum[i],定义为:当i是3的倍数时,sum[i] = sum[i-1]+i*i*i,否则sum[i] = sum[i-1] + i。mark:直接打表。TLE了2次,就是不打表直接算的后果。代码:# include <stdio.h>long long dp[100010] ;int main (){ long long n, i ; for (i = 1 ; i<= 100000 ; i++) { if (i%3=... 阅读全文

posted @ 2012-01-06 17:35 Seraph2012 阅读(179) 评论(2) 推荐(1)

[恢]hdu 1205
摘要:2011-12-16 11:37:45地址:http://acm.hdu.edu.cn/showproblem.php?pid=1205题意:中文,不解释。mark:注意用long long。代码:# include <stdio.h>int main (){ int T, n, i ; long long num, sum, max ; scanf ("%d", &T) ; while (T--) { scanf ("%d", &n) ; max = -1 ; sum = 0 ; for (i = 0 ; ... 阅读全文

posted @ 2012-01-06 17:34 Seraph2012 阅读(163) 评论(0) 推荐(0)

[恢]hdu 1196
摘要:2011-12-16 11:32:45地址:http://acm.hdu.edu.cn/showproblem.php?pid=1196题意:从最低位保留第一个不为0的二进制1。mark:位运算,n&-n代码:# include <stdio.h>int main (){ int n ; while (~scanf ("%d", &n) && n) { printf ("%d\n", n&-n) ; }} 阅读全文

posted @ 2012-01-06 17:33 Seraph2012 阅读(149) 评论(0) 推荐(0)

[恢]hdu 2178
摘要:2011-12-16 11:24:52地址:http://acm.hdu.edu.cn/showproblem.php?pid=2178题意:中文。mark:二分查找的应用。因为二分的最大次数是log2(n)。所以查询n次最大能查到的数是2^n-1。代码:# include <stdio.h>int main (){ int n; scanf ("%d", &n) ; while (~scanf ("%d", &n)) printf ("%d\n", (1<<n) - 1) ; return 0 阅读全文

posted @ 2012-01-06 17:32 Seraph2012 阅读(158) 评论(0) 推荐(0)

[恢]hdu 1164
摘要:2011-12-16 11:30:41地址:http://acm.hdu.edu.cn/showproblem.php?pid=1164题意:分解素因子。。。代码:# include <stdio.h>int main (){ int i, n, flag ; while (~scanf ("%d", &n)) { flag = 0 ; for (i = 2 ; i< n ; i++) { if (n == 1) break ; while (n % i == 0) {... 阅读全文

posted @ 2012-01-06 17:32 Seraph2012 阅读(200) 评论(0) 推荐(0)

[恢]hdu 1157
摘要:2011-12-16 11:13:43地址:http://acm.hdu.edu.cn/showproblem.php?pid=1157题意:给n个数字(n是奇数)找中位数。mark:wa了一次,被题目坑了。他是多组数据输入的。。。代码:# include <stdio.h># include <stdlib.h>int a[10010] ;int cmp(const void *a, const void *b){ return *(int*)a - *(int*)b ;}int main (){ int i, n ; while (~scanf ("%d& 阅读全文

posted @ 2012-01-06 17:31 Seraph2012 阅读(194) 评论(0) 推荐(0)

上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 24 下一页