2012年3月22日
摘要: 1 # include <iostream> 2 # include <cstdio> 3 using namespace std; 4 int main() 5 { 6 int n, i, j, k; 7 int edge[21][191]; 8 for (i=1; i<21; ++i) 9 {10 for (j=0; j<=190; ++j)11 {12 if (j == 0)13 edge[i][j] = 1;14 else15 ... 阅读全文
posted @ 2012-03-22 23:22 万里心晴 阅读(175) 评论(0) 推荐(0) 编辑
  2012年3月19日
摘要: 输入:动物个数n以及k句话,接着输入k行,每一行形式为:d x y, 在输入时可以先判断题目所说的条件2和3,即: 1>若(x>n||y>n):即当前的话中x或y比n大,则假话数目num加1. 2>若(x==2&&x==y):即当前的话表示x吃x,则假话数目num加1. 而不属于这两种情况外的话语要利用并查集进行判断当前的话是否与此前已经说过的话相冲突. struct node { int parent; //p[i].parent表示节点i的父节点 int relation; //p[i].relation表示节点i与其父节点(即p[i].parent 阅读全文
posted @ 2012-03-19 17:35 万里心晴 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 1 # include <stdio.h> 2 # define N 1024 3 int parent[N]; 4 int rank[N]; 5 int findset(int x) 6 { 7 if (x != parent[x]) 8 x = findset(parent[x]); 9 return parent[x];10 }11 void init(int n)//接受城镇数12 {13 int i;14 for (i=1; i<=n; ++i)15 {16 parent[i] = i;17 r... 阅读全文
posted @ 2012-03-19 16:19 万里心晴 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 1 # include <stdio.h> 2 const int max = 50005; 3 int rank[max]; 4 int parent[max]; 5 int maxnum; 6 int findset(int x) 7 { 8 if (x != parent[x]) 9 x = findset(parent[x]);10 return parent[x];11 }12 void init(int n)13 {14 int i;15 for (i=1; i<=n; ++i)16 {17 parent[i... 阅读全文
posted @ 2012-03-19 16:02 万里心晴 阅读(130) 评论(0) 推荐(0) 编辑
  2012年3月15日
摘要: 1 # include <iostream> 2 # include <cstdio> 3 using namespace std; 4 int sum, m, mark; 5 int a[13][2]; //a[i][0]来存值, a[i][1]来存状态 6 int l; 7 void output() 8 { 9 mark++;10 int i;11 int flag = 0;12 for (i=0; i<m; ++i)13 {14 if (a[i][1] == 1)15 {16 if ... 阅读全文
posted @ 2012-03-15 07:31 万里心晴 阅读(172) 评论(0) 推荐(0) 编辑
  2012年3月14日
摘要: 引文: http://www.cnblogs.com/brokencode/archive/2011/07/01/2095158.htmlProblem Description呃......变形课上Harry碰到了一点小麻烦,因为他并不像Hermione那样能够记住所有的咒语而随意的将一个棒球变成刺猬什么的,但是他发现了变形咒语的一个统一规律:如果咒语是以a开头b结尾的一个单词,那么它的作用就恰好是使A物体变成B物体. Harry已经将他所会的所有咒语都列成了一个表,他想让你帮忙计算一下他是否能完成老师的作业,将一个B(ball)变成一个M(Mouse),你知道,如果他自己不能完成的话,他就只 阅读全文
posted @ 2012-03-14 20:15 万里心晴 阅读(228) 评论(0) 推荐(0) 编辑
摘要: 1 # include <iostream> 2 # include <queue> 3 # include <cstdio> 4 using namespace std; 5 int n, m; 6 int a[110][110]; 7 int step; 8 struct node 9 {10 int x;11 int y;12 }pp[110][110];13 char arr[110][110];14 int dir[8][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {-1, -1}, {-1, 1}, {1, - 阅读全文
posted @ 2012-03-14 16:59 万里心晴 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 5 using namespace std; 6 const int N = 100000; 7 struct coco 8 { 9 int s; 10 int m; 11 int n; 12 int step; 13 }q[N]; 14 15 int s, m, n; 16 int vis[101][101]; 17 18 int bfs() 19 { 20 coco p, t; 21 in... 阅读全文
posted @ 2012-03-14 16:15 万里心晴 阅读(252) 评论(0) 推荐(0) 编辑
  2012年3月8日
摘要: Problem Description给你一个m×n的整数矩阵,在上面找一个x×y的子矩阵,使子矩阵中所有元素的和最大。Input输入数据的第一行为一个正整数T,表示有T组测试数据。每一组测试数据的第一行为四个正整数m,n,x,y(0<m,n<1000 AND 0<x<=m AND 0<y<=n),表示给定的矩形有m行n列。接下来这个矩阵,有m行,每行有n个不大于1000的正整数。Output对于每组数据,输出一个整数,表示子矩阵的最大和。Sample Input14 5 2 23 361 649 676 588992 762 156 9 阅读全文
posted @ 2012-03-08 23:01 万里心晴 阅读(154) 评论(0) 推荐(0) 编辑
  2012年3月7日
摘要: 大致题意:有一个农夫要把一个木板钜成几块给定长度的小木板,每次锯都要收取一定费用,这个费用就是当前锯的这个木版的长度给定各个要求的小木板的长度,及小木板的个数n,求最小费用提示:以35 8 5为例:先从无限长的木板上锯下长度为21的木板,花费21再从长度为21的木板上锯下长度为5的木板,花费5再从长度为16的木板上锯下长度为8的木板,花费8总花费= 21+5+8 =34解题思路:利用Huffman思想,要使总费用最小,那么每次只选取最小长度的两块木板相加,再把这些“和”累加到总费用中即可本题虽然利用了Huffman思想,但是直接用HuffmanTree做会超时,可以用优先队列做因为朴素的Huf 阅读全文
posted @ 2012-03-07 17:20 万里心晴 阅读(718) 评论(0) 推荐(0) 编辑