IT民工
加油!
上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 29 下一页
摘要: 这道题是判断无向图是否存在欧拉回路:所有的点的度数(出度和入度之和)为偶数。所有的点都在一个集合中。#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 找回失去的 阅读(266) 评论(0) 推荐(1)
摘要: 搜索*号能到的位置,置为#,然后输出整个输入的迷宫。#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 找回失去的 阅读(227) 评论(0) 推荐(0)
摘要: 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 找回失去的 阅读(250) 评论(0) 推荐(0)
摘要: 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 找回失去的 阅读(208) 评论(0) 推荐(0)
摘要: 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 找回失去的 阅读(212) 评论(0) 推荐(0)
摘要: 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 找回失去的 阅读(175) 评论(0) 推荐(0)
摘要: #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 找回失去的 阅读(161) 评论(0) 推荐(1)
摘要: 这道题是将一定量的硬币分给两个人,让两个人分到的数目尽量的平均,首先的最简单的分法是一个人拿掉全部的,另一个没拿,所以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 找回失去的 阅读(489) 评论(0) 推荐(0)
摘要: 用冒泡排序计算变量交换的次数。好久没写冒泡排序了...#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 找回失去的 阅读(181) 评论(0) 推荐(0)
摘要: 计算将一块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 找回失去的 阅读(475) 评论(0) 推荐(0)
上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 29 下一页