andre_joy

导航

07 2012 档案

hdu 1160
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1160题意:给出反例,老鼠长的越胖,速度越慢的例子。mark:最长递增子序列。不过本题要求记录这段子序列,不能用传统的nlgn的算法,只能n*n的算法了。代码:#include <stdio.h>#include <string.h>#include <stdlib.h>typedef struct{ int pos; int w,s;}mice;typedef struct{ int pre; int sum;}dpp;mice m[1010];dpp dp[101 阅读全文

posted @ 2012-07-29 23:12 andre_joy 阅读(660) 评论(0) 推荐(0)

hdu 1494
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1494题意:中文……mark:dp[i][j]代表第i个时间段,有j数量的油,油的数量0~14.代码:#include <stdio.h>#include <string.h>#define N 0x3f3f3f3fint dp[2][15];int a[110][2];int min(int a, int b) {return a < b ? a : b;}int main(){ int l,n,min1; int i,j; while(~scanf("%d%d 阅读全文

posted @ 2012-07-27 22:07 andre_joy 阅读(162) 评论(0) 推荐(0)

hdu 1300
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1300题意:买珠宝。每种品种必须加上10个同等级珠宝的价钱,可以将低品种的并入高品种,这样可能可以减少价钱。求最小价钱。mark:dp。刚开始思路是小品种的往大品种上加,直到加不了。然后大部分数据可以过,不过显然是wa的。后来看解题报告用新思路做,数据设小了。。wa了。代码:#include <stdio.h>int min(int a, int b) {return a < b ? a : b;}int main(){ int dp[110], a[110][2]; int t, n 阅读全文

posted @ 2012-07-27 15:15 andre_joy 阅读(192) 评论(0) 推荐(0)

poj 1258
摘要:地址:http://poj.org/problem?id=1258题意:把所有农场连起来的最小费用。mark:最简单的最小生成树。第一次写,代码比较乱~代码:#include <stdio.h>#include <string.h>const int N = 110;const int MAX = 100010;int vis[N],dis[N];int a[N][N];int min(int a, int b) {return a < b ? a : b;}int main(){ int n,ans,min1,f,sum; int i,j,k; while(~s 阅读全文

posted @ 2012-07-26 10:55 andre_joy 阅读(106) 评论(0) 推荐(0)

hdu 1025
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1025题意:上面n个点,下面n个点,然后在这2n个点之间随意连线,一个点只能被连一次,问最多有多少条线不交叉。mark:把上面点排序后,那么就转换成最大升序子序列的问题了。可以看看我上一篇博客~poj 3903代码:#include <stdio.h>#include <string.h>#include <stdlib.h>typedef struct{ int s,e;}city;city c[500010];int len;int d[500010];int c 阅读全文

posted @ 2012-07-25 15:48 andre_joy 阅读(559) 评论(0) 推荐(0)

poj 3903
摘要:地址:http://poj.org/problem?id=3903题意:求最长上升子序列。mark:在网上学习一种O(nlgn)的算法,拿过来试验了一下。http://blog.sina.com.cn/s/blog_76344aef0100scyq.html代码:#include <stdio.h>int len;int a[100010];int d[100010];int find(int m){ int fr = 0, la = len-1, mid; while(fr <= la) { mid = (fr+la)/2; if(d[mid] ... 阅读全文

posted @ 2012-07-25 15:30 andre_joy 阅读(236) 评论(0) 推荐(0)

poj 1185
摘要:地址:http://poj.org/problem?id=1185题意:中文……mark:经典的状态压缩dp。第一次写,在网上看别人解题报告看了好多,百度一下就有很多。 推荐一个解释很详细的解题报告http://apps.hi.baidu.com/share/detail/14572384 wa了好多次。特别是match函数那,有很多a,b为0的时候的临界情况。 ps:别人的代码不一定是正确的,我找了一篇ac代码,然后比对数据,结果发现他的数据不对。囧……代码:#include <stdio.h>#include <string.h>#define N 61int dp 阅读全文

posted @ 2012-07-25 00:08 andre_joy 阅读(152) 评论(0) 推荐(0)

hdu 300题~
摘要:3月15日注册杭电账号,经历4个月的ac路程,有一些辛苦,但是为了以后,为了将来,一切都值得。继续努力吧~just do it! 阅读全文

posted @ 2012-07-23 22:47 andre_joy 阅读(105) 评论(0) 推荐(0)

hdu 1421
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1421题意:中文……mark:dp。关键还是找dp[i][j]。i代表前i个物品,j代表多少对。 wa了两次,真2,写顺手了,求了个最大值。。。代码:#include <stdio.h>#include <stdlib.h>#include <string.h>int a[2010];int dp[2010][2010];int cmp(const void *a, const void *b){ return *(int *)a - *(int *)b;}int m 阅读全文

posted @ 2012-07-23 19:15 andre_joy 阅读(171) 评论(0) 推荐(0)

hdu 2577
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2577题意:求字符串最少输入次数。mark:dp,关键是分组!代码:#include <stdio.h>#include <string.h>int min(int a, int b) {return a < b ? a : b;}int dp[110][2];int main(){ int t,i; char a[110]; scanf("%d", &t); while(t--) { scanf("%s", a); mems 阅读全文

posted @ 2012-07-23 18:07 andre_joy 阅读(157) 评论(0) 推荐(0)

hdu 2602
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2602题意:背包问题。mark:第一次背包~代码:#include <stdio.h>#include <string.h>int v[1010],c[1010];int dp[1010];int max(int a, int b) {return a > b ? a : b;}int main(){ int t,m,n; int i,j; scanf("%d", &t); while(t-- && scanf("%d% 阅读全文

posted @ 2012-07-23 16:29 andre_joy 阅读(114) 评论(0) 推荐(0)

poj 2492
摘要:地址:http://poj.org/problem?id=2492题意:判断是否有同性恋。。。mark:解题报告主流思想是并查集,我用的bfs。 wa了很多次,都是一些不细心。而且这题居然每组数据后面都有一个空格。。。。代码:#include <stdio.h>#include <queue>#include <string.h>using namespace std;bool a[2010][2010];int b[2010];int f[2010];int m;int pd(){ int fr,la,i,j,p; queue<int> q; 阅读全文

posted @ 2012-07-23 12:28 andre_joy 阅读(228) 评论(0) 推荐(0)

poj 2442
摘要:地址:http://poj.org/problem?id=2442题意:m段序列,每个序列取一个数,求组成序列和最小的n个数。mark:最近刚接手的优先队列。代码:#include <stdio.h>#include <iostream>#include <stdlib.h>#include <queue>using namespace std;int a[2010], b[2010];int cmp(const void *a, const void *b){ return *(int *)a - *(int *)b;}int main(){ 阅读全文

posted @ 2012-07-22 10:13 andre_joy 阅读(117) 评论(0) 推荐(0)

hdu 4301
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=4301题意:分巧克力,注意每块巧克力都不一样。mark:dp,三维的。代码:#include <stdio.h>int dp[1010][2010][2];int main(){ int t,i,j; dp[1][1][0] = dp[1][2][1] = dp[2][1][0] = dp[2][3][0] = dp[2][4][1] = 1; dp[2][2][0] = dp[2][3][1] = 3; dp[2][2][1] = 3; for(i = 3; i <= 1... 阅读全文

posted @ 2012-07-20 09:17 andre_joy 阅读(185) 评论(0) 推荐(0)

hdu 4302
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=4302题意:虫子吃蛋糕,总是吃最近的,如果一样近,按之前顺序吃。mark:wa了无数次啊,,最后终于找到错误了,队列没有清空。。。 第一次用这种queue的库函数写,比较生涩,不过最后ac了,挺高兴的~代码:#include <queue>#include <iostream>#define LL __int64using namespace std;struct cmp{ bool operator()(LL a, LL b) { return a > b; }}... 阅读全文

posted @ 2012-07-19 23:01 andre_joy 阅读(237) 评论(0) 推荐(0)

hdu 1015
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1015题意:找符合题目给定公式字典序最后的字符串。mark:暴力过……代码:#include <stdio.h>#include <string.h>#include <stdlib.h>int n,c[15];char a[15], b[30] = "1ABCDEFGHIJKLMNOPQRSTUVWXYZ";int cmp(const void *a, const void *b){ return *(int *)b - *(int *)a;}v 阅读全文

posted @ 2012-07-18 10:43 andre_joy 阅读(361) 评论(0) 推荐(0)

hdu 1166
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1166题意:中文……mark:线段树。第一次写线段树,目的是减小空间复杂度。代码:#include <stdio.h>#define LL(x) ((x) << 1)#define RR(x) ((x) << 1 | 1)typedef struct{ int le,ri,mi,su;}tree;int a[50010];tree t[150000];int build(int l, int r, int s){ t[s].le = l; t[s].ri = r; t 阅读全文

posted @ 2012-07-13 21:14 andre_joy 阅读(114) 评论(0) 推荐(0)

hdu 1856
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1856题意:找一组的最大人数。mark:并查集,注意最后搜索的细节。虽然wa了很多次,但是ac了还是很爽的。代码:#include <stdio.h>#include <string.h>#include <stdlib.h>int a[200010], b[200010], c[200010][2], d[100010];int j;int cmp(const void *a, const void *b){ return *(int *)a - *(int *)b 阅读全文

posted @ 2012-07-13 17:39 andre_joy 阅读(128) 评论(0) 推荐(0)

hdu 1232
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1232题意:中文……mark:并查集。代码:#include <stdio.h>int s[1010];int find(int a){ if(s[a] == a) return a; return s[a] = find(s[a]);}void merge(int a, int b){ int p = find(a), q = find(b); if(p != q) s[p] = q;}int main(){ int n,m,a,b; int i,sum; w... 阅读全文

posted @ 2012-07-13 13:58 andre_joy 阅读(167) 评论(0) 推荐(0)

hdu 1253
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1253题意:中文……mark:bfs,wa了无数次啊,,细节处理的不好,没注意走不出去的情况。可能有两种,第一种根本无法走到门,第二种门本来就是死路。代码:#include <stdio.h>#include <string.h>int s[130000][3],d[50][50][50],h[50][50][50],a,b,c,t;void bfs(){ int front = 0, rear = 1; int aa,bb,cc,aaa,bbb,ccc,i; int tab[6 阅读全文

posted @ 2012-07-13 11:48 andre_joy 阅读(196) 评论(0) 推荐(0)

hdu 1372
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1372题意:按照国际象棋规则马最少几步从开始点走到终点。mark:bfs,仔细。代码:#include <stdio.h>#include <string.h>int a[100][2],d[8][8];char p[5],q[5];void bfs(){ int front = 0,rear = 1,m,n; d[p[0]-'a'][p[1]-'0'-1] = 0; a[0][0] = p[0]-'a'; a[0][1] = p[ 阅读全文

posted @ 2012-07-12 22:40 andre_joy 阅读(290) 评论(0) 推荐(0)

hdu 2717
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2717题意:三种走法+1,-1,*2,最少几步到指定点。mark:wa了好多次。bfs算法,注意临界条件。代码:#include <stdio.h>#include <string.h>int a[100010],d[100010],n,k;void bfs(){ int front = 0,rear = 1,nn; a[0] = n; d[n] = 0; while(front != rear) { nn = a[front++]; if(nn... 阅读全文

posted @ 2012-07-12 22:08 andre_joy 阅读(198) 评论(0) 推荐(0)

POJ 1579
摘要:地址:http://poj.org/problem?id=1579题意:按照题目要求递归。mark:直接递归肯定是TLE的。记忆化深度搜索。代码:#include <stdio.h>int s[21][21][21];int w(int a, int b, int c){ if(a <= 0 || b <= 0 || c <= 0) return 1; if(a > 20 || b > 20 || c > 20) return s[20][20][20] = w(20, 20, 20); if(s[a][b][c]) return s[a][b] 阅读全文

posted @ 2012-07-12 18:50 andre_joy 阅读(168) 评论(0) 推荐(0)

hdu 1241
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1241题意:跟2952一样,只不过多加了四个方向。mark:多加了四个方向之后,遍历的时候不用打表了,可以直接枚举。代码:#include <stdio.h>char a[110][110];int m,n;void ss(int x, int y){ int i,j,xx,yy; a[x][y] = '1'; for(i = -1; i < 2; i++) for(j = -1; j < 2; j++) { xx = x+i; ... 阅读全文

posted @ 2012-07-12 18:25 andre_joy 阅读(233) 评论(0) 推荐(0)

hdu 2952
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2952题意:找分开的#最多的片数mark:dfs.同1312一样。代码:#include <stdio.h>char a[110][110];int h,w;void ss(int x, int y){ int tab[4][2] = {0,1,0,-1,-1,0,1,0}; int i,xx,yy; a[x][y] = '1'; for(i = 0; i < 4; i++) { xx = x+tab[i][0]; yy = y+tab[i][1... 阅读全文

posted @ 2012-07-12 18:04 andre_joy 阅读(159) 评论(0) 推荐(0)

hdu 1312
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1312题意:找可以到达的黑格子。mark:dfs..代码:#include <stdio.h>char a[25][25];int sum;void ss(int w, int h, int x, int y){ if(y > 0 && a[x][y-1] == '.') { a[x][y-1] = '1'; sum++; ss(w, h, x, y-1); } if(x < h-1 && a[x+1][y] == 阅读全文

posted @ 2012-07-12 17:48 andre_joy 阅读(136) 评论(0) 推荐(0)

UVa 10071
摘要:地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1012题意:给定t时刻速度v,求2t时刻位移。mark:化简位移公式。代码:#include <stdio.h>int main(){ int a,b; while(~scanf("%d%d", &a, &b)) printf("%d\n", 2*a*b); return 0;} 阅读全文

posted @ 2012-07-12 16:31 andre_joy 阅读(101) 评论(0) 推荐(0)

UVa 10055
摘要:地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=996题意:给军官和敌人的士兵数,求两个人士兵数的差值。mark:UVa第一题,wa了5次。。学到两点! 1.unsigned [0,2^32-1],signed [-2^31, 2^31-1]。 2.vice versa 翻译为 反之亦然。代码:#include <stdio.h>int main(){ long long a,b; while(scanf(&qu 阅读全文

posted @ 2012-07-12 15:53 andre_joy 阅读(167) 评论(1) 推荐(0)

hdu 2189
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2189题意:中文……mark:母函数求解。参见http://baike.baidu.com/view/2415279.htm代码:#include <stdio.h>#include <string.h>int a[35] = {2, 3, 5}, b[2][151];int pd(int m){ int i; for(i = 0; a[i]*a[i] <= m; i++) if(m%a[i] == 0) return 0; return 1;}int main(){ .. 阅读全文

posted @ 2012-07-12 00:02 andre_joy 阅读(182) 评论(0) 推荐(0)

hdu 2117
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2117题意:找1/n小数点后第m位数字。mark:wa了一次。。没考虑n = 1的情况。。。代码:#include <stdio.h>int main(){ int n,m; int i,re; while(~scanf("%d%d", &n, &m)) { if(n == 1) {printf("0\n");continue;} re = 10; for(i = 1; i < m; i++) re = (re%n)... 阅读全文

posted @ 2012-07-11 22:30 andre_joy 阅读(100) 评论(0) 推荐(0)

hdu 1390
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1390题意:求n转换成2进制后1的位置。mark:代码:#include <stdio.h>int main(){ int d,n,i,f; scanf("%d", &d); while(d-- && scanf("%d", &n)) { i = f = 0; while(n) { if(n & 1) { if(f) printf(" "); ... 阅读全文

posted @ 2012-07-11 17:56 andre_joy 阅读(89) 评论(0) 推荐(0)

hdu 1042
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1042题意:求n!,注意:0 <= n <= 10000,n = 10000时,长度为35660位。mark:用数组的方式存放。代码:#include <stdio.h>#define MOD 10000int a[10010];int main(){ int n,f,s; int i,j; while(~scanf("%d", &n)) { if(n < 2) {printf("1\n");continue;} a[0] = 阅读全文

posted @ 2012-07-11 17:26 andre_joy 阅读(114) 评论(0) 推荐(0)

hdu 1517
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1517题意:从1开始,每个人选择乘2~9中的一个数,谁先大于等于n谁赢。mark:博弈问题。用逆推的思想。比如n = 1000。那么[999,112]是必败区间,再退一步[111,56]是必胜区间,以此类推……代码:#include <stdio.h>int main(){ long long n,p; int i; while(~scanf("%I64d", &n)) { if(n == 1) { puts("Stan wins... 阅读全文

posted @ 2012-07-11 15:36 andre_joy 阅读(123) 评论(0) 推荐(0)

hdu 1849
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1849题意:中文……mark:跟1850一样,还是Nim游戏,参见http://baike.baidu.com/view/1101962.htm代码:#include <stdio.h>int main(){ int m,n,a; while(scanf("%d", &m), m) { n = 0; while(m-- && scanf("%d", &a)) n ^= a; puts(n ? "Rabbit W 阅读全文

posted @ 2012-07-11 14:49 andre_joy 阅读(206) 评论(0) 推荐(0)

hdu 1846
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1846题意:中文……mark:简单博弈。代码:#include <stdio.h>int main(){ int c,m,n; scanf("%d", &c); while(c-- && scanf("%d%d", &m, &n)) puts(m%(n+1) ? "first" : "second"); return 0;} 阅读全文

posted @ 2012-07-11 13:07 andre_joy 阅读(94) 评论(0) 推荐(0)

hdu 1850
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1850题意:中文……mark:Nim游戏,参见http://baike.baidu.com/view/1101962.htm代码:#include <stdio.h>int main(){ int m,a[110]; int i,n,sum; while(scanf("%d", &m), m) { for(i = n = 0; i < m; i++) { scanf("%d", a+i); n ^= a[i]... 阅读全文

posted @ 2012-07-11 12:43 andre_joy 阅读(107) 评论(0) 推荐(0)

USACO barn1
摘要:题意:有很多隔间,部分隔间被奶牛占领,要修墙,连在一起的算一面墙,给定墙的最大面数,问怎么修,才能使其包括所有被奶牛占有的地方都能被包围并且墙的总占地最小。mark:wa了一次,写到最后糊涂了一下。。仔细就好。代码:/*ID: andre_j2LANG: CTASK: barn1*/#include <stdio.h>#include <stdlib.h>int cmp(const void *a, const void *b){ return *(int *)a - *(int *)b;}main(){ freopen("barn1.in", &q 阅读全文

posted @ 2012-07-11 11:08 andre_joy 阅读(132) 评论(0) 推荐(0)

hdu 1847
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1847题意:中文……mark:wa了一次,题目看错了,以为是只能按照1,2,4……的顺序来取牌。 数据比较小,博弈问题,在纸上找到规律了,直接暴力破解了。代码:#include <stdio.h>int dp[1001] = {0, 1, 1, 0} ;int main (){ int i, j, n ; for (i = 4; i <= 1000; i++) for (j = 1; j <= i; j<<=1) if (dp[i-j] == 0) ... 阅读全文

posted @ 2012-07-11 00:13 andre_joy 阅读(102) 评论(0) 推荐(0)

hdu 1069
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1069题意:给定若干个木块长宽高,长宽高可以自己调整,求堆积起来最高的高度。mark:枚举所有木块长宽高可能情况,简单dp。代码:#include <stdio.h>#include <stdlib.h>typedef struct{ int x,y,z;}block;int cmp1(const void *a, const void *b){ block *p = (block *)a, *q = (block *)b; if(p->x != q->x) retu 阅读全文

posted @ 2012-07-10 23:40 andre_joy 阅读(159) 评论(0) 推荐(0)

hdu 1087
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1087题意:只能走比当前旗子大的旗子,不能回头,求走过最大的旗子的和。mark:简单dp。代码:#include <stdio.h>#include <string.h>int main(){ int n,a[1010],dp[1010][2]; int i,j,max; while(scanf("%d", &n), n) { memset(dp, 0, sizeof(dp)); for(i = 0; i < n; i++) sc... 阅读全文

posted @ 2012-07-10 22:56 andre_joy 阅读(469) 评论(0) 推荐(0)

USACO milk
摘要:题意:计算从农夫手中购买需要的牛奶的最小价格。mark:简单排序即可。代码:/*ID: andre_j2LANG: CTASK: milk*/#include <stdio.h>#include <stdlib.h>typedef struct{ int p,a;}farmer;int cmp(const void *c, const void *b){ farmer *f1 = (farmer *)c, *f2 = (farmer *)b; if(f1->p != f2->p) return f1->p - f2->p; return f2-& 阅读全文

posted @ 2012-07-10 21:51 andre_joy 阅读(100) 评论(0) 推荐(0)

USACO dualpal
摘要:题意:寻找n个在2~10进制里面转换后至少有两次是回文数字的严格大于S的数字。mark:仔细一点就ok了。代码:/*ID: andre_j2LANG: CTASK: dualpal*/#include <stdio.h>#include <string.h>int dd(char a[]){ int i,j; j = strlen(a)-1; for(i = 0; i < j; i++,j--) if(a[i] != a[j]) return 0; return 1;}int pd(int n){ int m,i,j,f; char a[20]... 阅读全文

posted @ 2012-07-09 22:59 andre_joy 阅读(97) 评论(0) 推荐(0)

USACO palsquare
摘要:题意:找1~300对应的平方数再转换成对应的进制后是回文数字的数。mark:扫描一遍,转换一遍,满足要求的输出。代码:/*ID: andre_j2LANG: CTASK: palsquare*/#include <stdio.h>#include <string.h>int pd(char a[]){ int n,i,j; n = strlen(a); for(i = 0, j = n-1; i < j; i++, j--) if(a[i] != a[j]) return 0; return 1;}void fout(char a[]){ int i... 阅读全文

posted @ 2012-07-09 22:30 andre_joy 阅读(95) 评论(0) 推荐(0)

USACO namesum
摘要:题意:将数字转换成对应的字母。mark:把字典里面的数全部存在数组里面,然后每输入一次搜索一遍,看是否存在该数。代码:/*ID: andre_j2LANG: CTASK: namenum*/#include <stdio.h>#include <string.h>char a[5010][15],b[5010][15];main () { FILE *fdict = fopen("dict.txt", "r"); FILE *fin = fopen("namenum.in", "r"); F 阅读全文

posted @ 2012-07-09 15:24 andre_joy 阅读(126) 评论(0) 推荐(0)

USACO transform
摘要:题意:将转换前字符串经过题目给出的7种方式转换成转换后的字符串。注意5是前三种跟第四种结合。mark:模拟一下就ok了~代码:/*ID: andre_j2LANG: CTASK: transform*/#include <stdio.h>#include <string.h>int i,j;int pp(char a[][15], char b[][15], int n){ int i; for(i = 0; i < n; i++) if(strcmp(a[i], b[i])) return 0; return 1;}void zh1(char a[][15],. 阅读全文

posted @ 2012-07-09 10:50 andre_joy 阅读(141) 评论(0) 推荐(0)

hdu 2151
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2151题意:中文……mark:递推。dp[i][j]代表第i时刻在第k棵树的方法数。dp[i][j] = dp[i-1][j-1] + dp[i-1][j+1]。代码:#include <stdio.h>#include <string.h>int dp[110][110];int main(){ int n,p,m,t; int i,j; while(~scanf("%d%d%d%d", &n, &p, &m, &t)) { 阅读全文

posted @ 2012-07-08 23:46 andre_joy 阅读(128) 评论(0) 推荐(0)

hdu 2108
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2108题意:给定一个多边形的每一个顶点坐标,判断它是否为凸多边形。mark:判断每两个向量的转向。wa了2次,tle了1次。把文件输入输出部分一起交了……代码:#include <stdio.h>int main(){ int n,x1,x2,x3,y1,y2,y3,f,x0,y0,x4,y4; while(scanf("%d", &n), n) { if(n < 3) { while(n--) scanf... 阅读全文

posted @ 2012-07-08 18:26 andre_joy 阅读(143) 评论(0) 推荐(0)

hdu 1391
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1391题意:按图输出图上数字。mark:模仿图形里面数字变换特性。代码:#include <stdio.h>int a[5010][2];int main(){ int n,x,y,m; int i; a[0][0] = 0; a[1][1] = 1; i = m = 2; while(i < 5001) { a[i++][0] = m++; a[i--][0] = m++; a[i++][1] = m++; ... 阅读全文

posted @ 2012-07-05 23:48 andre_joy 阅读(118) 评论(0) 推荐(0)

hdu 1035
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1035题意:看小人是否能走出迷宫。mark:wa了一次,又是循环跳出条件出问题了……代码:#include <stdio.h>#include <string.h>int main(){ char a[15][15]; int m,n,s,sum,b[15][15]; int i,j,k; while(scanf("%d%d", &m, &n), m+n) { scanf("%d", &s); for(i = 0; 阅读全文

posted @ 2012-07-05 13:09 andre_joy 阅读(140) 评论(0) 推荐(0)

USACO milk2
摘要:题意:n个农夫给n只羊喂奶,分别给出他们的起始时间和结束时间,求重叠的和没有重叠的最长时间。mark:wa了一次。变量max1忘记每次遇到不重叠的时候需要重新初始化了。。代码:/*ID: andre_j2LANG: CTASK: milk2*/#include <stdio.h>#include <stdlib.h>typedef struct{ int st,en;}fa;int cmp(const void *a, const void *b){ fa *p = (fa *)a, *q = (fa *)b; if(p->st != q->st) retu 阅读全文

posted @ 2012-07-05 01:40 andre_joy 阅读(284) 评论(0) 推荐(0)

hdu 1785
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1785题意:按原点到给定点的向量与x轴正方向夹角大小排序,夹角越小,实际越大。mark:wa了两次。。。题目说的是与x轴正方向的夹角。。代码:#include <stdio.h>#include <stdlib.h>typedef struct{ double x,y;}stu;int cmp(const void *a, const void *b){ stu *p = (stu *)a, *q = (stu *)b; double m; m = p->y*q->x 阅读全文

posted @ 2012-07-04 23:17 andre_joy 阅读(135) 评论(0) 推荐(0)

hdu 1396
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1396题意:等边三角形每一条边被分成n份后,总共有多少个等边三角形。mark:wa了一次,把问题想简单了……没考虑反着的大三角形,应该分奇偶考虑。代码:#include <stdio.h>int main(){ int i,m,a[501] = {0,0}, b[501] = {0,1}; m = 1; for(i = 2; i < 501; i++) { m += i; b[i] = b[i-1] + m; a[i] = a[i-2] ... 阅读全文

posted @ 2012-07-04 22:50 andre_joy 阅读(239) 评论(0) 推荐(0)

hdu 1859
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1859题意:中文……mark:就是找x,y中出现过的最大最小数。循环跳出条件需要注意~代码:#include <stdio.h>int main(){ int x1,x2,y1,y2,x,y; x1 = y1 = 232; x2 = y2 = -232; while(scanf("%d%d", &x, &y)) { if(!x && !y) { if(x1 == 232) break; printf("... 阅读全文

posted @ 2012-07-04 20:51 andre_joy 阅读(101) 评论(0) 推荐(0)

hdu 1716
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1716题意:中文……mark:只有四位数,直接暴力破了。。代码:#include <stdio.h>#include <stdlib.h>int cmp(const void *a, const void *b){ return *(int *)a - *(int *)b;}int main(){ int a[4],sum,p1,p2; int i,j,k,s,f; f = 0; while(scanf("%d%d%d%d", a, a+1, a+2, a+3 阅读全文

posted @ 2012-07-04 20:30 andre_joy 阅读(198) 评论(0) 推荐(0)

hdu 1256
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1256题意:中文……mark:写的中间就发现用自定义函数会少很多代码。。代码:#include <stdio.h>int main(){ int n,m,p,s; int i,j,k; char a; scanf("%d%*c", &n); k = 0; while(n-- && scanf("%c %d%*c", &a, &m)) { if(k++) puts(""); s = m/6+1; 阅读全文

posted @ 2012-07-04 20:04 andre_joy 阅读(140) 评论(0) 推荐(0)

hdu 1088
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1088题意:按要求输出html文件。mark:pe了无数次,主要是临界问题的考虑,还有是要考虑'\t'。代码:#include <stdio.h>int zh(char a){ if(a == '<') return 1; if(a == ' ' || a == '\n' || a == '\t') return 2; return 3;}int main(){// freopen("in1.tx 阅读全文

posted @ 2012-07-04 14:50 andre_joy 阅读(241) 评论(0) 推荐(0)

hdu 1197
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1197题意:求一个数转换成10,12,16进制后各个位上的数的和是否相等。mark:模拟进制转换。代码:#include <stdio.h>int zh(int a, int n){ int sum = 0; while(a) { sum += a%n; a /= n; } return sum;}int main(){ int m; for(m = 2992; m < 10000; m++) if(zh(m, 10) ... 阅读全文

posted @ 2012-07-03 23:34 andre_joy 阅读(115) 评论(0) 推荐(0)

hdu 1194
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1194题意:赌球,用比分的和与比分的差的绝对值赌博。mark:注意比分都是整数。代码:#include <stdio.h>int main(){ int t,m,n; scanf("%d", &t); while(t-- && scanf("%d%d", &m, &n)) if(m < n || (m+n) & 1) puts("impossible"); else printf 阅读全文

posted @ 2012-07-03 23:21 andre_joy 阅读(104) 评论(0) 推荐(0)

hdu 1143
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1143题意:3*n的矩形用2*1的砖堆法。mark:wa了,两次。。一次数组只开到30了,一次循环跳出条件写错了。。囧……递推就ok了。 我是画图一步一步推出来的。首先肯定是2个2个增加的。首先考虑不交叉的f(n) = 3*f(n-2),再考虑交叉的,会发现规律,2*(f(n-4)+f(n-6)+……) ps:后来看大牛的代码,发现公式化简了可以降低复杂度,虽然这题n最大才30。f(n) = 4*f(n-2)-f(n-4)代码:#include <stdio.h>int main(){ .. 阅读全文

posted @ 2012-07-03 22:21 andre_joy 阅读(103) 评论(0) 推荐(0)

hdu 1098
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1098题意:给定k,求满足任何x都能使f(x)能被65整除的a的值。mark:本题要用欧拉定理,一开始完全不会啊。。。欧拉定理证明http://baike.baidu.com/view/48903.htm 从65着手。65=13*5,所以要f(x)被65整除,那么f(x)一定整除13和5。 先考虑13。f(x)=13*x^5 + 5*x^13 + k*a*x,13*x^5显然是13的倍数。所以只用考虑5*x^13+k*a*x = x*(5*x^12+k*a)。 1.当x能被13整除的时候... 阅读全文

posted @ 2012-07-03 21:38 andre_joy 阅读(82) 评论(0) 推荐(0)

hdu 1039
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1039题意:判断密码是否可行。满足三个条件:1.至少一个元音字母。2.连续三个字母不能同时为元音或辅音。3.连续两个字母不能相同,但是不包括"ee"和"oo"。mark:无。代码:#include <stdio.h>#include <string.h>int yy(char a){ if(a == 'a' || a == 'e' || a == 'i' || a == 'o' 阅读全文

posted @ 2012-07-03 18:41 andre_joy 阅读(308) 评论(0) 推荐(0)

hdu 1037
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1037题意:货物的高度能否通过给定高度的障碍物。mark:无代码:#include <stdio.h>int main(){ int a[3],i; while(~scanf("%d%d%d", a, a+1, a+2)) { for(i = 0; i < 3; i++) if(a[i] <= 168) break; if(i == 3) puts("NO CRASH"); else printf("CRASH %d\n" 阅读全文

posted @ 2012-07-03 18:06 andre_joy 阅读(124) 评论(0) 推荐(0)

hdu 2368
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2368题意:判断一个正方形的pizza能否放在一个圆形的桌子上,使得pizza没有地方不接触桌子。mark:正方形对角线/2跟圆半径比较。代码:#include <stdio.h>#include <math.h>int main(){ int r,w,l,i; double d; i = 1; while(scanf("%d", &r), r) { scanf("%d%d", &w, &l); d = sqrt(w 阅读全文

posted @ 2012-07-03 17:56 andre_joy 阅读(99) 评论(0) 推荐(0)

hdu 2147
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2147题意:从右上角开始出发,可以向左,坐下,下三个方向走一步,求谁最后没路可走。mark:wa了一次,把问题想简单了(一开始以为只用判断是不是三的倍数。) 简单博弈。思路可以是递推,a(i,j)代表kiki在第i行第j列的时候的胜负。则a(i,j) = !a(i-1,j) || !a(i,j-1) || !a(i-1,j-1).代码:#include <stdio.h>int main(){ int m,n; while(scanf("%d%d", &n, &a 阅读全文

posted @ 2012-07-03 17:46 andre_joy 阅读(105) 评论(0) 推荐(0)

hdu 2212
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2212题意:中文……mark:打表,只有四个数。。。代码:#include <stdio.h>int main(){ printf("1\n2\n145\n40585\n"); return 0;} 阅读全文

posted @ 2012-07-03 17:18 andre_joy 阅读(71) 评论(0) 推荐(0)

hdu 1407
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1407题意:中文……mark:懒得写一些判断了,直接循环了。代码:#include <stdio.h>int main(){ int n,i,j,k,f; while(~scanf("%d", &n)) { f = 0; for(i = 1; i < 100; i++) { for(j = i; j < 100; j++) { for(k = j; k < 100; k+... 阅读全文

posted @ 2012-07-03 01:20 andre_joy 阅读(81) 评论(0) 推荐(0)

hdu 1337
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1337题意:狱警玩游戏,第一次转换1,2,……,n的锁的开关状态,第二次转换2,4,……,第三次3,6,……依次类推到第n次。求最后有多少锁是开着的。mark:模拟就ok了。代码:#include <stdio.h>#include <string.h>int main(){ int t,n,a[110]; int i,j,sum; scanf("%d", &t); while(t-- && scanf("%d", 阅读全文

posted @ 2012-07-03 01:05 andre_joy 阅读(246) 评论(0) 推荐(0)

hdu 1412
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1412题意:中文……mark:先排序,再一起扫描一遍。代码:#include <stdio.h>#include <stdlib.h>int cmp(const void *a, const void *b){ return *(int *)a - *(int *)b;}int a[10010],b[10010],c[20010];int main(){ int n,m; int i,j,k; while(~scanf("%d%d", &n, & 阅读全文

posted @ 2012-07-01 21:15 andre_joy 阅读(140) 评论(0) 推荐(0)

hdu 1017
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1017题意:给定n,m,求满足(a^2+b^2+m)/(a*b)仍是整数的(a,b)的组数。mark:n的值比较小,扫描一遍,也就100*100.代码:#include <stdio.h>int main(){ int t,n,m,sum; int i,j,a,b; scanf("%d", &t); for(i = 0; i < t; i++) { if(i) puts(""); j = 1; while(~scanf("%d% 阅读全文

posted @ 2012-07-01 19:43 andre_joy 阅读(181) 评论(0) 推荐(0)

hdu 1249
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1249题意:中文……mark:此题重在理解推导公式,f(n)=f(n-1)+6*(n-1),化简为:f(n)=3*n*(n-1)+2。 一个三角形的时候,再加一个三角形,每一条变会与第一个三角形的两条边相交,这样增加2个小三角形,即两个面。f(2)=3*2+f(1),再加一个三角形,每一条边会与前两个三角形的四条边相交,形成四个小三角形,f(3)=3*4+f(2),依次类推,即f(n)=3*2*(n-1)+f(n-1)。代码:#include <stdio.h>int main(){ int 阅读全文

posted @ 2012-07-01 18:04 andre_joy 阅读(241) 评论(0) 推荐(0)

hdu 1014
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1014题意:通过题目给出的递推公式能否得到0-mod-1之间的所有数。mark:wa了一次,把问题想简单了,一位只是一个数能被另一个数整除……其实是判断两个数是否互素。代码:#include <stdio.h>int gcd(int a, int b){return a%b?gcd(b,a%b):b;}int main(){ int m,n; while(~scanf("%d%d", &m, &n)) { printf("%10d%10d &qu 阅读全文

posted @ 2012-07-01 17:25 andre_joy 阅读(85) 评论(0) 推荐(0)

hdu rank1000
摘要:今天245题进入hdoj 1000名内。再接再厉! 阅读全文

posted @ 2012-07-01 15:39 andre_joy 阅读(84) 评论(0) 推荐(0)

hdu 1070
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1070题意:主角要买牛奶,对牛奶的要求是生产日期5天内引用,每天喝200ml,少于200ml的扔掉,商场牛奶均是当天生产。 选取满足要求的单价最小的牛奶,当单价一样,选择容量多的。mark:wa了两次,都是精度问题,在整数问题里面最好不要用浮点数运算。(一般都是除法比较。)代码:#include <stdio.h>#include <string.h>int main(){ char m[100],d[100]; int t,n,a,b,c,aa,bb,cc; scanf(&qu 阅读全文

posted @ 2012-07-01 15:38 andre_joy 阅读(421) 评论(0) 推荐(0)

hdu 2200
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2200题意:中文……mark:直接公式化简可得(2^(n-1))*(n-2)+1,要是不会化简,可以用递推做f(n)=2*f(n-1)+2^(n-1)-1代码:#include<stdio.h>int main(){ long long n; while (~scanf ("%I64d", &n)) printf ("%I64d\n", (1LL << (n-1)) * (n-2) + 1); return 0;} 阅读全文

posted @ 2012-07-01 15:01 andre_joy 阅读(74) 评论(0) 推荐(0)

hdu 1228
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1228题意:中文……mark:仔细。。代码:#include <stdio.h>#include <string.h>int tr(char a[]){ if(!strcmp(a, "zero")) return 0; if(!strcmp(a, "one")) return 1; if(!strcmp(a, "two")) return 2; if(!strcmp(a, "three")) retu 阅读全文

posted @ 2012-07-01 14:27 andre_joy 阅读(224) 评论(0) 推荐(0)

hdu 1425
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1425题意:中文……mark:qsor()简单水过。不过效率不是很高,985ms,可以用别的排序方法加快效率。代码:#include <stdio.h>#include <stdlib.h>int cmp(const void *a, const void *b){ return *(int *)b - *(int *)a;}int a[1000010];int main(){ int m,n,i; while(~scanf("%d%d", &n, & 阅读全文

posted @ 2012-07-01 14:04 andre_joy 阅读(280) 评论(0) 推荐(0)

hdu 2526
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2526题意:中文……下一行字符根据上一行对应三个字符来决定。mark:无。代码:#include <stdio.h>#include <string.h>char a[2][510],b[8][4];int f[8];int tr(char c[]){ int i; for(i = 0; i < 8; i++) if(!strcmp(c, b[i])) return f[i];}int main(){ char c[4]; int t,m,le; int i,... 阅读全文

posted @ 2012-07-01 13:57 andre_joy 阅读(170) 评论(0) 推荐(0)

hdu 1408
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1408题意:中文……mark:wa了一次。。主要是精度问题,要判断好究竟滴多少次。代码:#include <stdio.h>int main(){ double v,d; int i,sum,m; while(~scanf("%lf%lf", &v, &d)) { sum = 0; if((int(v/d))*10 == (int)(v/d*10)) m = (int)(v/d); else m = (int)(v/d) + 1; ... 阅读全文

posted @ 2012-07-01 01:19 andre_joy 阅读(81) 评论(0) 推荐(0)

hdu 2522
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2522题意:中文……mark:真是2死了,wa了5次。开始是因为数组开小了,因为余数是在n*10的范围内的,所以数组要开10^6。后来是因为给a[]初始化的时候,n应该先转换成正数,结果一直wa。。。此题是模仿除法运算,每一步输出一个结果。代码:#include <stdio.h>int a[1000010];int main(){ int t,n,m; scanf("%d", &t); while(t-- && scanf("%d&qu 阅读全文

posted @ 2012-07-01 00:46 andre_joy 阅读(152) 评论(0) 推荐(0)