上一页 1 2 3 4 5 6 7 8 ··· 13 下一页
  2013年8月5日
摘要: 题目链接。题目大意:题目相当晦涩难懂啊。一年的12个月,每5个月统计一次,如从1~5,2~6,3~7,...,8~12共统计了8次,已知每次都deficit,问这一年有没有盈利的可能。一个月surplus只能是s,deficit只能是d,不能是其它的值。分析:用贪心,先计算1~5,让每个月都盈利,然后从第5个月向前deficit,直到1~5的和为deficit。继续2~6,3~7.。。。,8~12.最后统计全年是否盈利。AC代码如下:#include #include #include #include #include using namespace std;int main(){ i... 阅读全文
posted @ 2013-08-05 10:56 Still_Raining 阅读(250) 评论(0) 推荐(0) 编辑
摘要: 题目链接。分析:简单模拟。#include #include #include #include #include using namespace std;char White[] = "KQRBNP";char Black[] = "kqrbnp";char G[10][10], s[50];int main(){ memset(G, 0, sizeof(G)); for(int i=0; i=0; i--) { for(int j=0; j<8; j++) { if(G[i][j] == White[k]) { ... 阅读全文
posted @ 2013-08-05 09:43 Still_Raining 阅读(274) 评论(0) 推荐(0) 编辑
  2013年8月3日
摘要: 题目链接。分析:简单的 Catalan 数将x~y编号,设解为 d(x, y), d(x, y) = {d(x+1,i-1)*d(i+1,y)}, 其中 x+1#include#include#include #include using namespace std;#define MAXN 9999#define DLEN 4class BigNum{private: int a[50]; //可以控制大数的位数 int len; //大数长度public: BigNum(){ len = 1; memset(a,0,sizeof(a)); } //构... 阅读全文
posted @ 2013-08-03 17:14 Still_Raining 阅读(381) 评论(0) 推荐(0) 编辑
摘要: 题目链接。分析:网络流增广路算法模板题。http://www.cnblogs.com/tanhehe/p/3234248.htmlAC代码:#include #include #include #include using namespace std;const int maxn = 20;const int INF = (1 q; memset(flow, 0, sizeof(flow)); int f = 0; while(true) { memset(a, 0, sizeof(a)); a[s] = INF; q.push(s)... 阅读全文
posted @ 2013-08-03 10:14 Still_Raining 阅读(426) 评论(0) 推荐(0) 编辑
摘要: 这部分内容在《算法竞赛入门经典》——刘汝佳 里面讲的已经很详细了。但里面对于反向流量的作用是没有说明的。这里只说一下反向流量的作用。推荐上http://www.cnblogs.com/g0feng/archive/2012/05/29/2524749.htm看下。反向流量能够让后面的流自我调整。例如当前状态下当前状态下如何寻找?用a表示残量, cap表示容量,很明显,3-4这条路不是最优的.此时BFS, 会得到 a[2] = 2, a[4] = 2, a[3] = 1 (提示:cap[4][3]-flow[4][3]=1),a[5]=1, a[6]=1, a[7]=1更新流量得到可以看到,通过 阅读全文
posted @ 2013-08-03 10:04 Still_Raining 阅读(6512) 评论(0) 推荐(0) 编辑
  2013年8月2日
摘要: 题目链接。分析:用dfs枚举每一波攻击的三个国家。很暴力,但没想到0ms。#include #include #include using namespace std;const int maxn = 20;int p[maxn], nervous[maxn], n, m, k, max_cnt;int att[110][3];void dfs(int cn) { //界限 if(max_cnt >= k) return ; if(cn >= k) { max_cnt = k; return ; } int a[3], bak[3]; for(... 阅读全文
posted @ 2013-08-02 14:32 Still_Raining 阅读(342) 评论(0) 推荐(0) 编辑
  2013年8月1日
摘要: 做了一天水题,挑几个还算凑合的发上来。POJ1008Maya Calendar分析:#include #include #include #include using namespace std;char Haab[][10] = {"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "za 阅读全文
posted @ 2013-08-01 20:51 Still_Raining 阅读(345) 评论(0) 推荐(0) 编辑
  2013年7月31日
摘要: 题目链接。分析:应当用字典树,但stl的map做很简单.#include #include #include #include #include #include #include #include #include using namespace std;const int maxn = 20;map m;int main() { char s[maxn], s1[maxn], s2[maxn]; while(gets(s), s[0] != 0) { sscanf(s, "%s%s", s1, s2); m[s2] = s1; } while(g... 阅读全文
posted @ 2013-07-31 23:49 Still_Raining 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 题目链接。题目大意:N个球,从1~N编号,质量不同,范围1~N,无重复。给出小球间的质量关系(#include #include #include #include #include #include #include #include using namespace std;const int maxn = 200+10;bool G[maxn][maxn];int n, m, ind[maxn], a[maxn];bool topsort() { for(int i=n; i>=1; i--) { int k; for(k=n; k>=1; k--) ... 阅读全文
posted @ 2013-07-31 20:00 Still_Raining 阅读(508) 评论(0) 推荐(0) 编辑
摘要: 题目链接。题目大意:三维迷宫,搜索从s到e的最小步骤数。分析:#include #include #include #include #include #include #include #include #include using namespace std;const int maxn = 35;int dx[] = {0, 0, -1, 1, 0, 0};int dy[] = {0, 0, 0, 0, -1, 1};int dz[] = {-1, 1, 0, 0, 0, 0};char G[maxn][maxn][maxn];bool vis[maxn][maxn][maxn];int 阅读全文
posted @ 2013-07-31 16:53 Still_Raining 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 题目链接。分析:用 dfs 一行一行的搜索,col记录当前列是否已经放置。AC代码如下:#include #include #include #include #include #include #include #include #include using namespace std;const int maxn = 10;int n, k, cnt;bool col[maxn];char G[maxn][maxn];void dfs(int row, int num) { if(num == k) { cnt++; return ; } if(row+1 > n) retur... 阅读全文
posted @ 2013-07-31 15:50 Still_Raining 阅读(196) 评论(0) 推荐(0) 编辑
  2013年7月30日
摘要: 题目链接。分析:本题BFS A不了。001000000101020000000001000010000100001000030对于这样的数据,本来应当是 5 步,但bfs却 4 步。具体原因可以仔细看一下上面的样例。应当dfs穷举所有的可能,找出最短的。#include #include #include using namespace std;const int maxn = 23;const int INF = (1= 10) return ; for(int d=0; d= h || ny >= w) continue ; if(G[nx][ny] == 1) con... 阅读全文
posted @ 2013-07-30 18:53 Still_Raining 阅读(853) 评论(0) 推荐(0) 编辑
  2013年7月29日
摘要: 题目链接。题目大意:给定一个矩阵,马的初始位置在(0,0),要求给出一个方案,使马走遍所有的点。列为数字,行为字母,搜索按字典序。分析:用 vis[x][y] 标记是否已经访问。因为要搜索所有的可能,所以没搜索完一次要把vis[x][y]标记为未访问。详情见代码。用 p[x][y] 表示 (x,y)点的祖先,以便输出路径。dfs搜索即可。#include #include #include #include #include using namespace std;const int maxn = 30;const int VAL = 10000;int dx[] = {-1, 1, -2, 阅读全文
posted @ 2013-07-29 19:06 Still_Raining 阅读(233) 评论(0) 推荐(0) 编辑
摘要: 题目链接。题目大意:给定n个字符串,找出最长相同且长度大于3的子串,如果存在多个,找出字典序最小的。分析:直接枚举(暴搜)。对于s[0]的每一个子串,判断是否在其它n-1个字符串中都存在。#include #include #include #include using namespace std;#define N 60string s[30], str, str_max;int main(){ int T, n, max_len; scanf("%d", &T); while(T--) { scanf("%d", &n); max_l 阅读全文
posted @ 2013-07-29 15:02 Still_Raining 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 题目链接。题目大意:给定一个n,和两个序列a[i], p[i]. a[i] 表示需要购买 i品质 的数量,p[i] i 等级的价格。1.每个品质都会有不同的价格,价格依据品质上升而上升2.买一次 i 品质,都要加上10个 i 品质 价格的手续费。3.可一用高品质的代替低品质.求最少的花费.分析:这题就简单地矩阵链乘法(《算法导论》第15章,动态规划)。用 dp[i][j] 表示购买 i 品质到 j 的最少的花费.dp[i][j] = min{dp[i][k]+dp[k+1][j]), i#include using namespace std;const int maxn = 1500;int 阅读全文
posted @ 2013-07-29 09:19 Still_Raining 阅读(351) 评论(0) 推荐(0) 编辑
  2013年7月24日
摘要: 题目链接。分析:哈希竟然能这么用。检查两片雪花是否相同不难,但如果是直接暴力,定会超时。所以要求哈希值相同时再检查。AC代码:#include #include #include #include #include #include #include #include #include using namespace std;const int maxn = 100000+10;const int MOD_VAL = 97777;int sn[maxn][6];vectorhash[MOD_VAL];bool check(int a, int b) { //检查两片是否相等 for(i... 阅读全文
posted @ 2013-07-24 12:41 Still_Raining 阅读(211) 评论(0) 推荐(0) 编辑
  2013年7月13日
摘要: 题目链接。分析:用 d1[i] 表示左向右从0到i的最大连续和,d2[i] 表示从右向左, 即从n-1到i 的最大连续和。ans = max(ans, d1[i]+d2[i+1]), i=0,1, 2,...,n-2直接枚举会TLE, 优化下就可AC。#include #include #include #include #include #include #include #include using namespace std;const int maxn = 50000+10;const int INF = (1= 0) d1[i] = a[i] + d1[i-1]; ... 阅读全文
posted @ 2013-07-13 18:13 Still_Raining 阅读(164) 评论(0) 推荐(0) 编辑
  2013年7月11日
摘要: 题目链接。分析:感叹算法的力量。方法一:设 dp[i][j] 为字符串 s, 从 i 到 j 需要添加的最少字符数。那么如果 s[i] == s[j], dp[i][j] = dp[i+1][j-1]. 如果 s[i] != s[j], dp[i][j] = min(dp[i+1][j], dp[i][j-1]) + 1.#include #include #include #include #include using namespace std;const int maxn = 5000;short dp[maxn][maxn];char s[maxn];int d(int i, int 阅读全文
posted @ 2013-07-11 19:48 Still_Raining 阅读(243) 评论(0) 推荐(0) 编辑
摘要: 题目链接。分析:和 LCS 差不多。#include #include #include #include #include using namespace std;const int maxn = 200;int G[][5] = { {5, -1, -2, -1, -3}, {-1, 5, -3, -2, -4}, {-2, -3, 5, -2, -2}, {-1, -2, -2, 5, -1}, {-3, -4, -2, -1, 0}};int dp[maxn][maxn];void trans(char *s, int n) { for(int i=... 阅读全文
posted @ 2013-07-11 18:31 Still_Raining 阅读(192) 评论(0) 推荐(0) 编辑
  2013年7月9日
摘要: 题目链接。分析:用的《训练指南》上的方法。详见P17.从6个面中选一个做顶面,再从剩下的4个面中选1个做正面,则此正方体唯一确定。需要枚举共6*4=24种。#include #include #include #include #include #include #include #include using namespace std;const int maxn = 1000;int _left[6] = {4, 0, 2, 3, 5, 1};int up[6] = {2, 1, 5, 0, 4, 3};char s1[maxn], s2[maxn], s[maxn];void rot(i 阅读全文
posted @ 2013-07-09 13:21 Still_Raining 阅读(1227) 评论(1) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 13 下一页