IT民工
加油!
摘要: http://poj.org/problem?id=1915这道题还是求骑士从一个点移动到另一个点距离的问题,不同的是棋盘的规格是由我们输入的,最大有300*300,数组要开足够大,我把2243的代码修改了下就AC了...好好理解下BFS#include<iostream>#include<string.h>using namespace std;int x1, y1, x2, y2;int dist[305][305], qx[90005], qy[90005];int dx[] = { -1, -2, -2, -1, 1, 2, 2, 1};int dy[] = { 阅读全文
posted @ 2011-11-14 23:36 找回失去的 阅读(216) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=2243我是在看staginner大牛的博客的时候看到这道题的,因为看到了BFS,所以就拿来做了,但是发现好像之前没写过BFS这玩意,所以就基本照着搬了一遍他的代码,自己写了一下,理解了下队列和广搜。题目要我们找到从一个点到另一个点的骑士移动的步数,按照staginner的做法是记录在找到终点之前的所有点到起点的步数。#include<iostream>#include<string.h>#include<stdio.h>using namespace std;char a[5], b[5];int x1, 阅读全文
posted @ 2011-11-14 22:43 找回失去的 阅读(202) 评论(0) 推荐(0)
摘要: #include<iostream>#include<string.h>#define N 105using namespace std;int n, m;int c[N];int topo[N], t;int tt[N][N];void dfs( int u){ int v; c[u] = 1; for( v = 1; v <= n; v ++) if( tt[u][v] && !c[v] ) dfs( v); topo[ -- t] = u;}int main(){ int a, b, i; while( cin >>... 阅读全文
posted @ 2011-11-12 15:41 找回失去的 阅读(187) 评论(0) 推荐(0)
摘要: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1196这道题也是搜索题,还是dfs,我们只需对最后一行进行搜索,然后找到能爬到的最高高度即可,每走一步我们就计算一次现在处于的高度h,然后与maxh比较。因为开始少写了一句memset而WA了一遍...#include<stdio.h>#include<string.h>#define N 105int dx[] = { 0, 0, 1, -1};int dy[] = { 1, -1, 0, 0};int map[N][N], vis[N][N];int n, m;int 阅读全文
posted @ 2011-11-10 10:45 找回失去的 阅读(264) 评论(0) 推荐(0)
摘要: 这道题是一道搜索题,要我们找有多少块不同的油田,@与其相邻的八个方向的@属于同一片油田,我选择用dfs来做。#include<stdio.h>#include<string.h>#define N 105int map[N][N], vis[N][N];char str[N];int dx[] = { -1, 1, 0, 0, -1, -1, 1, 1};int dy[] = { 0, 0, -1, 1, -1, 1, -1, 1};void dfs( int x, int y){ int newx, newy; for( int i = 0; i < 8; i 阅读全文
posted @ 2011-11-10 09:50 找回失去的 阅读(201) 评论(0) 推荐(0)
摘要: 这道题是基础背包问题,我们手里有n块钱,然后求n块钱能买到的最大葡萄个数,价格为j的一串葡萄有除开j本身外其所有约数之和个葡萄。先将每串葡萄的个数求出来,再用状态转移方程,dp[i] = max( dp[i], dp[n - j] +w[j])即可,i从n到0。#include<stdio.h>#include<string.h>#define N 26using namespace std;int w[N];int dp[N];int max( int a, int b){ return a > b ? a : b;}int f( int n){ int sum 阅读全文
posted @ 2011-11-10 09:17 找回失去的 阅读(200) 评论(0) 推荐(0)
摘要: #include<iostream>using namespace std;int dp[7500];int coin[5] = { 1, 5, 10, 25, 50};int main(){ dp[0] = 1; for( int i = 0; i < 5; i ++) { for( int j = 1; j < 7500; j ++) { if( j >= coin[i] ) dp[j] += dp[ j - coin[i] ]; } } int cents; ... 阅读全文
posted @ 2011-11-07 10:28 找回失去的 阅读(513) 评论(1) 推荐(1)
摘要: 转自http://www.cnblogs.com/ihainan/archive/2011/06/04/2072699.html七种qsort排序方法<本文中排序都是采用的从小到大排序>一、对int类型数组排序int num[100];Sample:int cmp ( const void *a , const void *b ) { return *(int *)a - *(int *)b; }qsort(num,100,sizeof(num[0]),cmp);二、对char类型数组排序(同int类型)char word[100];Sample:int cmp( const vo 阅读全文
posted @ 2011-11-07 08:44 找回失去的 阅读(228) 评论(0) 推荐(0)
摘要: 这份列表当然不是我原创的,转自月田人的博客http://www.cnblogs.com/qijinbiao/archive/2011/09/02/2163460.html※最近更新:Poj斜率优化题目1180,2018,3709列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740, 1742, 1887,1926, 1936, 1952, 阅读全文
posted @ 2011-11-07 08:34 找回失去的 阅读(322) 评论(0) 推荐(0)
摘要: 这道题是要我们将给的数字进行接龙成一个很长的数字,然后找出其中最大的数字。所以排序不是比较两个数字的大小,而是比较两个数字按照前后顺序接龙获得的数字的大小,因为数字可能很大所以用数组,借助strcmp函数来排序。最后再将排序后的数组输出。这次熟悉了下strcat函数,看来蛮好用。#include<stdio.h>#include<stdlib.h>#include<string.h>char num[55][100];int n;void init(){ for( int i = 0; i < n; i ++) scanf( "%s" 阅读全文
posted @ 2011-11-07 00:09 找回失去的 阅读(559) 评论(0) 推荐(0)