IT民工
加油!
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1016素数环,回溯法/*Accepted 1016 203MS 248K 1111 B C++ Yu*/#include<stdio.h>#include<string.h>int A[25], p[40], vis[25], n;void isprime(){ int i, j; for(i = 2; i < 40; i ++) p[i] = 1; p[1] = 0; for(i = 2; i * i < 40; i ++) {... 阅读全文
posted @ 2011-11-25 13:10 找回失去的 阅读(187) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=2255这道题是输入二叉树的先序遍历、中序遍历,然后要求我们输出它的后序遍历,参考了白书上的二叉树重建的函数,先找到根结点,然后分别通过递归构造左右子树的后序遍历,然后将根节点放到输出字符串的最后。/*Accepted 160K 0MS C++ 563B 2012-07-31 12:16:15*/#include<stdio.h>#include<string.h>const int MAXN = 1 << 5;char s1[MAXN], s2[MAXN], ans[MAXN];void build(in 阅读全文
posted @ 2011-11-25 12:13 找回失去的 阅读(182) 评论(0) 推荐(1)
摘要: 最长公共子序列,值得注意的是这道题不能用scanf读字符串。#include<stdio.h>#include<string.h>#define MAXD 1005char s1[MAXD], s2[MAXD];int dp[MAXD][MAXD];int max( int a, int b){ return a > b ? a : b;}void solve(){ int len1 = strlen(s1 + 1); int len2 = strlen(s2 + 1); memset( dp, 0, sizeof dp); for( int i = 1; i & 阅读全文
posted @ 2011-11-24 23:54 找回失去的 阅读(162) 评论(0) 推荐(0)
摘要: 这是一道关于回文字符串的题,但是加上了镜像,我用了两个函数分别判断一个字符串是不是回文和镜像,然后用两个flag,最后根据题目的要求来输出结果。#include<stdio.h>#include<string.h>#include<ctype.h>char *ch = "A 3 HIL JM O 2TUVWXY5";char *num = "1SE Z 8 ";bool is_pal( char *s){ int len = strlen(s); for( int i = 0; i < len; i ++) if 阅读全文
posted @ 2011-11-24 12:47 找回失去的 阅读(320) 评论(0) 推荐(0)
摘要: 一个排序好的数组中位于中间的数到其他的数的总和总是最小的,所以根据这个就可以写了。#include<cstdio>#include<stdlib.h>#include<algorithm>#define MAXD 505using namespace std;int a[MAXD];int main(){ int cas, r; scanf( "%d", &cas); while( cas --) { scanf( "%d", &r); for( int i = 0; i < r; i ++) s 阅读全文
posted @ 2011-11-23 00:17 找回失去的 阅读(182) 评论(0) 推荐(1)
摘要: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1203这是道贪心题,要求最少的救生圈的个数。先将每个人要求的救生圈范围 a 、b按照b的升序、b相等的时候按照a的降序排序。将第一个的b作为第一个判断点,直到第i个人的a大于之前的b,再将b换成第i个b,依此类推!#include<iostream>#include<stdlib.h>using namespace std;typedef struct d{ int a; int b;}B;B t[10005];int cmp( const void *_p, const 阅读全文
posted @ 2011-11-21 14:16 找回失去的 阅读(199) 评论(0) 推荐(0)
摘要: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1208亏我还想用并查集去做,这道题用数组模拟链表就行,数组下标为编号,一个一个接下去就行,在接的同时计数。这题有点恶心的是必须把数组开到101000以上,要不就会RE,这也是考查的一个方面吧!#include<iostream>#include<string.h>using namespace std;const int N = 101005;int next[N];int main(){ int n, m; int a, b; while( cin >> n 阅读全文
posted @ 2011-11-21 14:11 找回失去的 阅读(369) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=1321这是手册上的深搜题,首先我们要将棋盘的位置标记,因为行和列都不同,所以必须用两个数组分别来存点的横坐标和纵坐标,然后开始一个棋子一个棋子地摆上去,计算有几种摆法。#include<iostream>#include<string.h>using namespace std;const int N = 8*8 + 10;int x[N], y[N];bool visx[N], visy[N];int n, k, m;long long cnt;char ch[N];void dfs( int a, int ans 阅读全文
posted @ 2011-11-19 23:24 找回失去的 阅读(198) 评论(0) 推荐(0)
摘要: 继续跟着白书做,这道题是要找每个国家的人的数量,然后按国家的字典序输出,很水的一道题,但是因为少了个getchar()浪费了不少时间。#include<stdio.h>#include<string.h>#include<stdlib.h>char ct[2005][80], s[80];int cmp( const void *_p, const void *_q){ char *p = (char *)_p; char *q = (char *)_q; return strcmp( p, q);}int main(){ int N; scanf( &qu 阅读全文
posted @ 2011-11-18 11:52 找回失去的 阅读(872) 评论(0) 推荐(1)
摘要: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1150这是道BFS的题,打油师要用容量为A和B的油桶打出C升的油,有六种操作方式,我们从前一种状态到后一种状态的变化是有规律的,广搜所有的操作方式,对每种状态都标记,直到找到需要的C升油。搞了好久才把队列和广搜搞明白一点,纠结ING!#include<iostream>#include<string.h>#define N 105using namespace std;int vis[N][N], qa[64*N], qb[64*N], d[64*N];int A, B, 阅读全文
posted @ 2011-11-17 23:20 找回失去的 阅读(254) 评论(0) 推荐(0)