IT民工
加油!
12 2011 档案
UVA 10161 - Ant on a Chessboard
摘要:#include<cstdio>#include<cmath>int n ,s ,a;int x, y;int main(){ while( scanf( "%d", &n) == 1) { if( n == 0) break; a = ( int )sqrt( n); s = a; a *= a; if( n == a) x = 1, y = s; else { s ++; n -= a; if( n <= s... 阅读全文
posted @ 2011-12-18 23:51 找回失去的 阅读(170) 评论(0) 推荐(0)
POJ 1017-Packets
摘要:这本来是一个简单的贪心题,但是我写的有点罗嗦了,这题只要把握住三点就行了:1. a/b是向下去整,我们要事先将a 变成 a+b-1,这样除法才不会错误。2. 把握6 * 6的箱子能放几个 各种类型的物品。3. 从大的放起,剩余空间要利用好,也就是要贪心。#include<cstdio>#include<cstring>#include<cstdlib>int a[7] = { 0};int res[5] = { 0};int ans;int main(){ while( scanf( "%d", &a[1]) == 1) { fo 阅读全文
posted @ 2011-12-17 23:44 找回失去的 阅读(242) 评论(0) 推荐(0)
UVA 532 - Dungeon Master
摘要:六个方向广搜...先是knowledgetime的代码,我写了一遍能A、、、#include <stdio.h>#include <string.h>#define Msize 29800typedef struct Dungeon{ int x,y,z,d;};const int step[10][3]={{-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,0,-1},{0,0,1}};Dungeon q[Msize]={0};int L,R,C,mat[40][40][40]={0},mins;bool vis[40][40][40]={fal 阅读全文
posted @ 2011-12-16 13:08 找回失去的 阅读(313) 评论(0) 推荐(0)
POJ 1088-滑雪
摘要:矩阵里的数字代表当前点的高度,只能从高的点滑到低的点,求最长能滑的距离。初始点不规定。我们可以向每个点的四周搜索,能走则就在当前距离加1。并将已经求的值保存在二维数组中。(记忆化搜索)/*Accepted 252K 47MS C++ 1158B 2012-07-23 16:13:17*/#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>using namespace std;const int MAXN = 105;const int dx[] = {0, 0 阅读全文
posted @ 2011-12-15 23:27 找回失去的 阅读(132) 评论(0) 推荐(0)
UVA 10596 - Morning Walk
摘要:这道题是判断无向图是否存在欧拉回路:所有的点的度数(出度和入度之和)为偶数。所有的点都在一个集合中。#include<cstdio>#include<cstring>#include<cstdlib>#define MAXN 205int d[MAXN], p[MAXN];int N, R;int find_set( int x){ return p[x] == x ? x : ( p[x] = find_set( p[x]) );}void union_set( int x, int y){ x = find_set( x); y = find_set( 阅读全文
posted @ 2011-12-15 09:58 找回失去的 阅读(264) 评论(0) 推荐(1)
UVA 784 - Maze Exploration
摘要:搜索*号能到的位置,置为#,然后输出整个输入的迷宫。#include<cstdio>#include<cstring>#include<cstdlib>char a[35][85];char b[100];const int dx[] = { 1, -1, 0, 0};const int dy[] = { 0, 0, -1, 1};void dfs( int x, int y){ for( int d = 0; d < 4; d ++) { int nx = x + dx[d]; int ny = y + dy[d]; if( a[nx][... 阅读全文
posted @ 2011-12-14 23:44 找回失去的 阅读(225) 评论(0) 推荐(0)
CSUOJ 1226: ACM小组的内战
摘要:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1226这也是月赛题,不知道当时怎么想的,居然没有写这道题...两个字符串中的字符有对应的关系,一对多和多对一都不行...#include<cstdio>#include<cstring>#include<cstdlib>#define SIZE 300char s1[SIZE], s2[SIZE], s3[SIZE], s4[SIZE], a[SIZE], b[SIZE], c[SIZE], d[SIZE];bool f1[100], f2[100];int 阅读全文
posted @ 2011-12-14 13:37 找回失去的 阅读(249) 评论(0) 推荐(0)
CSUOJ 1010: Water Drinking
摘要:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1010这道题是要我们找到一个队伍的最后一个骆驼的编号,队伍的要求有两点1. 骆驼数最少2. 与池塘相连#include<cstdio>#include<cstring>#include<cstdlib>#define MAXN 100005int next[MAXN], s[MAXN];int N, top, k;int main(){ while( scanf( "%d", &N) == 1) { int n = N; top = 阅读全文
posted @ 2011-12-13 22:18 找回失去的 阅读(206) 评论(0) 推荐(0)
POJ 3620-Avoid The Lakes
摘要:http://poj.org/problem?id=3620学长说这道题是广搜题,但是貌似用深搜做更容易,将被淹了的点标记为true,然后对其上下左右4个点进行深搜,找到相连的最多的点。/*Accepted 288K 47MS C++ 1080B 2012-07-23 12:20:58*/#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespace std;const int MAXN = 105;const int dx[] = { 1, 阅读全文
posted @ 2011-12-13 20:32 找回失去的 阅读(209) 评论(0) 推荐(0)
POJ -1753-Flip Game
摘要:http://poj.org/problem?id=1753这道题用的深搜,操作方式还是蛮麻烦的 o(2^16) ,然后在读入的时候用了%c然后悲剧了...#include<cstdio>#include<cstring>#include<cstdlib>int map[4][4];int dx[] = { 1, -1, 0, 0};int dy[] = { 0, 0, -1, 1};int min = 100;void init(){ char a[10]; for( int i = 0; i < 4; i ++) { scanf( "%s 阅读全文
posted @ 2011-12-13 20:15 找回失去的 阅读(171) 评论(0) 推荐(0)
月赛两道能A的题
摘要:#include<cstdio>#include<cstring>#include<cstdlib>int n, m, x1, y1, x2, y2;int dx[] = { -1, -1, 1, 1, 2, 2, -2, -2};int dy[] = { 2, -2, 2, -2, 1, -1, 1, -1};int d[25][25], qx[500], qy[500];int main(){ int x, y, front, rear; while( scanf( "%d%d", &n, &m) == 2) { sc 阅读全文
posted @ 2011-12-11 22:29 找回失去的 阅读(159) 评论(0) 推荐(1)
UVA 562- Dividing coins
摘要:这道题是将一定量的硬币分给两个人,让两个人分到的数目尽量的平均,首先的最简单的分法是一个人拿掉全部的,另一个没拿,所以f[0] = true;根据这种情况来推的话,我们可以将所有可能的出现的硬币组成的钱数判断出来,f[j - coin[i]] = true;则f[j] = true;时间复杂度是O( m * C),将所有的可能值都置为true,然后从平均值开始判断就可以找到其中一个人拿到的钱数,他们俩的差值就很容易得出了。#include<cstdio>#include<cstring>#define MAXN 105int coin[MAXN];bool f[MAXN 阅读全文
posted @ 2011-12-09 23:03 找回失去的 阅读(486) 评论(0) 推荐(0)
UVA 299 - Train Swapping
摘要:用冒泡排序计算变量交换的次数。好久没写冒泡排序了...#include<stdio.h>int main(){ int n, s[55]; int cas; scanf( "%d", &cas); while( cas --) { scanf( "%d", &n); int ans = 0; for( int i = 0; i < n; i ++) scanf( "%d", &s[i]); for( int i = 0; i < n; i ++) for( int ... 阅读全文
posted @ 2011-12-07 13:39 找回失去的 阅读(178) 评论(0) 推荐(0)
UVA 10970 - Big Chocolate
摘要:计算将一块n*m的巧克力切成n*m块所需的次数,我们可以先横切,先切成n条,一共切了n-1刀,然后将每条都切m-1次,则一共切了 n - 1 + n*( m - 1) = n *m - 1刀,另一种方法也差不多,m - 1 + m*( n - 1) = m*n - 1。巧克力不能折叠,而且切开后不能把几条放一块一起切。#include<stdio.h>int main(){ int n, m; while( scanf( "%d%d", &n, &m) == 2) { int a = (n - 1) + n * ( m - 1); printf( 阅读全文
posted @ 2011-12-07 13:18 找回失去的 阅读(472) 评论(0) 推荐(0)
UVA 10790 - How Many Points of Intersection?
摘要:上面给出a个点,下面给出b个点,上面的每一个点跟下面的给一个点都有连线,求连线的交点数。#include<stdio.h>long long a, b;int main(){ int cas = 0; while( scanf( "%lld%lld", &a, &b), a && b) { printf( "Case %d: %lld\n", ++ cas, b*(b-1)*a*(a-1)/4); } return 0;} 阅读全文
posted @ 2011-12-06 21:15 找回失去的 阅读(178) 评论(0) 推荐(0)
UVA 11044
摘要:题意:给你一个n*m(6<=n,m<=10000)的矩阵,一个点能覆盖它本身和它周围的8个点,问你要多少个点能把矩形完全覆盖(矩形的边缘不用覆盖。)#include<stdio.h>int main(){ int cas; scanf( "%d", &cas); while( cas --) { int n, m; scanf( "%d%d", &n, &m); printf( "%d\n", (int)(n / 3) * ( m / 3)); } return 0;} 阅读全文
posted @ 2011-12-06 20:36 找回失去的 阅读(139) 评论(0) 推荐(0)
UVA 10050 - Hartals
摘要:这道题要求罢工的天数,看图看了好久才明白题意,我们用数组模拟,输入的h1这些都是罢工的周期,然后在周五和周六的不算,因为不上班,将其他时间的罢工天数加起来就是题目要我们输出的结果。#include<cstdio>#include<string.h>const int MAXN = 3657;bool d[MAXN];int main(){ int T; scanf( "%d", &T); while( T --) { int n, p; scanf( "%d%d", &n, &p); memset( d, 阅读全文
posted @ 2011-12-06 20:05 找回失去的 阅读(582) 评论(0) 推荐(0)
UVA 10004 - Bicoloring
摘要:模拟染色,因为只有两种颜色,所以分别用 0、 1 代表这两种颜色,然后从0开始深搜,如果每个点都能染上色,且相邻两点的颜色不同,则符合要求。#include<stdio.h>#include<string.h>#define MAXN 210int map[MAXN][MAXN];int paint[MAXN];int u, v, M, N;bool dfs( int i, int color){ for( int j = 0; j < N; j ++) { if( map[i][j]) { if( paint[j] != -1 &... 阅读全文
posted @ 2011-12-06 18:54 找回失去的 阅读(192) 评论(0) 推荐(0)
UVA 10465 - Homer Simpson
摘要:这道题要尽可能的多吃Krusty- burger,尽可能的少浪费时间,也是背包问题。#include<stdio.h>#include<string.h>#define MAXT 10005int a[2], t[MAXT], cnt[MAXT];int T;void dp(){ memset( t, 0, sizeof t); memset( cnt, 0, sizeof cnt); for( int i = 0; i < 2; i ++) for( int j = a[i]; j <= T; j ++) { if( t[ ... 阅读全文
posted @ 2011-12-05 22:15 找回失去的 阅读(151) 评论(0) 推荐(0)
UVA 10404 - Bachet's Game
摘要:用一个bool数组d,stan和ollie每次取石头时都要想办法让对方输,所以当剩下的石头i,当i大于 a[j] 时,他们都会想办法使对方陷入失败,即使得d[ i - a[j] ]为false。直到取完所有的石头,d[N]为true就是先取的人赢。#include<stdio.h>#include<string.h>#define MAXN 1000005#define MAXM 15int N, M, a[MAXM];bool d[MAXN];void init(){ for( int i = 0; i <= N; i ++) { d[i] = false; . 阅读全文
posted @ 2011-12-05 20:45 找回失去的 阅读(264) 评论(0) 推荐(0)
UVA 437 - The Tower of Babylon
摘要:这道题以前写过,首先block可以摆成三种形式,要求堆在它上面的木块的长和宽都比它小,所以我先将木块根据长的一级升序,宽的二级升序排序,然后枚举一遍在一块木块上可以堆的高度,选择最高的加上,最后找到一个最大高度。#include<stdio.h>#include<stdlib.h>#define MAXD 100typedef struct a{ int x, y, z;}S;S d[MAXD];int N, maxh;int cmp( const void *_p, const void *_q){ S *p = (S *)_p; S *q = (S *)_q; if 阅读全文
posted @ 2011-12-05 19:53 找回失去的 阅读(433) 评论(0) 推荐(1)
UVA 10131-Is Bigger Smarter?
摘要:这道题要求我们找到一个满足体重是升序,智商是降序的最长的序列。首先将大象的体重做升序排序,这样我们就只要找到排序后的序列的关于智商的最长下降子序列。为了方便操作,定义一个结构体,包含 体重、 智商、 编号。还有定义一个数组来模拟链表,数组存的是点的父节点,然后用输出路径的函数将路径输出。这道题输入比较奇葩,而且我们检查是否正确也会比较麻烦。#include<stdio.h>#include<stdlib.h>#include<string.h>#define MAXD 1005typedef struct aa{ int w; int s; int r;}E 阅读全文
posted @ 2011-12-05 18:28 找回失去的 阅读(269) 评论(0) 推荐(1)
UVA 10192 - Vacation
摘要:为了让父母都满意,所以只能选择他们给的建议中的相同的序列,即最长公共子序列,求长度并输出。#include<stdio.h>#include<string.h>#define MAXD 105char a[MAXD], b[MAXD];int f[MAXD][MAXD], len1, len2;int max( int a, int b){ return a > b ? a : b;}void dp(){ len1 = strlen( a + 1), len2 = strlen( b + 1); memset( f, 0, sizeof f); for( int 阅读全文
posted @ 2011-12-04 23:51 找回失去的 阅读(245) 评论(0) 推荐(1)
CSUOJ 1215: 稳定排序
摘要:这道题看了标程后应该用归并排序做的,但是我用了qsort,qsort不是稳定排序,但是我用的是结构体,然后加上了一个标记,所以也符合题目要求第一关键值相同情况下不改变原数组次序#include<stdio.h>#include<stdlib.h>#define MAXD 100005typedef struct aa{ int a; int b; int f;}S;S t[MAXD];int N;int cmp( const void *_p, const void *_q){ S *p = ( S *)_p; S *q = ( S *)_q; if( p-... 阅读全文
posted @ 2011-12-04 10:57 找回失去的 阅读(292) 评论(0) 推荐(0)
UVA 10369 - Arctic Network
摘要:这道题开始以为是求最小生成树,然后写出来之后发现和样例输出不符合,再看了一遍题,发现求所有的点之间的最大通信成本D。其中有s个卫星频道,可以和任一点连线。我们要降低成本的话就是让远的点用卫星频道,用kruskal算法合并到有 P - S棵树组成的森林,其中后S个点分别单独为一棵树,使用卫星频道。前面的点用的则为radio通信,然后合并到符合条件时取得的边为radio的最大边。#include<stdio.h>#include<math.h>#include<stdlib.h>#include<string.h>#define MAXD 510in 阅读全文
posted @ 2011-12-03 22:38 找回失去的 阅读(221) 评论(0) 推荐(0)
CSUOJ 1219: 建食堂
摘要:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1219这道题先用floyd算法求出所有点之间的距离,然后枚举判断每个点到其他点的最大距离,找出其中最小的一个,如果发现其中有一个点不可到其他点,则输出Can not。#include<stdio.h>#include<stdlib.h>#define MAXD 105#define INF 1000007int d[MAXD][MAXD];int n, m, u, v, w, max, mini;bool flag;int min( int a, int b){ retu 阅读全文
posted @ 2011-12-03 20:45 找回失去的 阅读(252) 评论(0) 推荐(0)
CSUOJ 1212: 中位数
摘要:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1212这道题要找到中位数,我的方法是将两个序列的数字比较,然后将小的那个放入s中,当s的计数器过了N后,就可以跳出比较的循环,输出s[N]。#include<stdio.h>#include<stdlib.h>#define MAXD 100005int s[MAXD], N, a[2 * MAXD];int main(){ while( scanf( "%d", &N) == 1) { for( int i = 1; i <= 2 * 阅读全文
posted @ 2011-12-03 20:38 找回失去的 阅读(325) 评论(1) 推荐(0)
UVA 11137 - Ingenuous Cubrency
摘要:递推,状态转移方程:dp[j] = dp[j - a[i]]; 依题意a[i] = i^3.#include<stdio.h>#include<string.h>#define MAXD 10005long long dp[MAXD], a[25];int N;int main(){ for( int i = 1; i <= 21; i ++) a[i] = i * i * i; memset( dp, 0, sizeof dp); dp[0] = 1; for( int i = 1; i <= 21; i ++) for( int j = ... 阅读全文
posted @ 2011-12-03 00:15 找回失去的 阅读(203) 评论(0) 推荐(1)
UVA 10130 - SuperSale
摘要:这道题还是0-1背包问题,看一个队能拿到的最大价值是多少并输出。开始理解错题意,将每个人能拿的最大重量加在一块,然后一起拿一次。其实应该是每个人都拿一次...#include<stdio.h>#include<string.h>#define MAXD 1005int f[MAXD * 31];int p[MAXD], w[MAXD];int c, ans, T, N, G;int max( int a, int b){ return a > b ? a : b;}int main(){ scanf( "%d", &T); while( 阅读全文
posted @ 2011-12-02 22:43 找回失去的 阅读(195) 评论(0) 推荐(0)
UVA 624 - CD
摘要:这道题给定一个时间上限,然后一个数字N,后面跟着N首歌的时间长度,要我们求在规定时间w内每首歌都要完整的播放,最多能播放多少时间。一个比较典型的背包问题,但是要标记出我们选出的歌曲的编号,然后按顺序输出他们的长度,最后输出求的的最长播放时间。#include<stdio.h>#include<string.h>#define W 10005int f[W], a[25];bool vis[25][W];int w, N;int main(){ int j; while( scanf( "%d", &w) == 1) { scanf( &quo 阅读全文
posted @ 2011-12-02 14:42 找回失去的 阅读(489) 评论(0) 推荐(1)
UVA 147 - Dollars
摘要:这道题有三点需要注意:1. 输入的钱数是5c的倍数。2. 浮点数的处理。3. 输出的格式。关于这两点,把5c看成一个单位,将所有的面额转换成5c的倍数存入数组。浮点数的处理我一直没把握好,用了强制类型转换,发现一直WA,然后参考了staginner的处理方法,用了floor函数,然后AC了。#include<stdio.h>#include<string.h>#include<math.h>#define MAXD 6005const int coin[] = { 1, 2, 4, 10, 20, 40, 100, 200, 400, 1000, 2000} 阅读全文
posted @ 2011-12-01 11:30 找回失去的 阅读(170) 评论(0) 推荐(1)
UVA 357 - Let Me Count The Ways
摘要:这道题和之前的 Coin Change 有点类似,dp[j] = dp[ j - coin[i]];但是得注意数据的范围。#include<stdio.h>#include<string.h>#define MAXD 30005long long dp[MAXD];const int coin[] = { 1, 5, 10, 25, 50};int main(){ int c; memset( dp, 0, sizeof dp ); dp[0] = 1; for( int i = 0; i < 5; i ++) for( int j = 0; j < 30. 阅读全文
posted @ 2011-12-01 10:51 找回失去的 阅读(157) 评论(0) 推荐(1)