上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 13 下一页
  2013年5月16日
摘要: AC自动机,不得不说,很难理解。这里的代码是《算法竞赛入门经典——训练指南》上的代码,自己把散碎的代码整理了整理。#include <iostream>#include <cstdlib>#include <cstdio>#include <algorithm>#include <cstring>#include <stack>#include <vector>#include <queue>#include <map>using namespace std;const int maxn 阅读全文
posted @ 2013-05-16 22:50 Still_Raining 阅读(354) 评论(0) 推荐(0) 编辑
  2013年5月13日
摘要: 题目链接。分析:先用BFS将所有的火能到达的时间计算出来,然后再一次BFS,计算最短路径。要求人每到一个方格的时间,必须小于该方格的着火时间。直到走到边界。注意:WA很多次。。后来想出来了。少考虑了一种情况,那就是人一开始就在边界的情况。AC代码如下:#include <iostream>#include <cstdlib>#include <cstdio>#include <algorithm>#include <cstring>#include <stack>#include <vector>#includ 阅读全文
posted @ 2013-05-13 20:58 Still_Raining 阅读(455) 评论(0) 推荐(0) 编辑
  2013年5月12日
摘要: 题目链接。题目:最短路径题目描述为了准备一年一度的校赛,大家都在忙着往赛场搬运东西,比如气球什么的。这时YY也没有闲着,他也加入了搬运工的行列。已知学校有N个路口和M条路,YY并不是把东西直接搬到赛场,而是从S路口搬运到T路口。由于YY非常懒而且他有轻度强迫症。所以他要走的路需要尽可能的短,并且走过路径的数目要为X的倍数。输入输入的第一行为一个正整数T(1≤T≤20),代表测试数据组数。对于每组测试数据:输入的第一行为两个正整数N和M(1≤N≤100, 1≤M≤10000)。接下来M行每行三个正整数U、V、W(0≤U,V<N, 0≤W≤230),代表有一条从U到V的长度为W的有向路径。最 阅读全文
posted @ 2013-05-12 12:41 Still_Raining 阅读(337) 评论(0) 推荐(0) 编辑
  2013年5月10日
摘要: 题目链接。题目原文:地板砖题目描述利用假期时间,豆豆找个了临时工,帮有钱人家贴地板砖,假设房子的形状为N x M的矩形,每个地板砖的大小为1 x 1,且只有黑白两种颜色,这家人很奇怪,他们不喜欢房间中任何一个2 x 2的局部区域的4块地板砖的颜色一样。如果出现这种图案,豆豆就要重新贴,这当然难不倒豆豆,但爱学习的豆豆,想知道满足要求的贴法一共用多少种。如下图所示:Figure 1.为满足要求的贴法,Figure 2.为不满足要求的贴法输入输入包含多组测试数据,对于每组测试数据:输入只有两个正整数N、M(N≤500, M≤5),分别代表房间的长度和宽度。输出对于每组测试数据,输出满足要求的贴法总 阅读全文
posted @ 2013-05-10 23:04 Still_Raining 阅读(272) 评论(0) 推荐(0) 编辑
  2013年5月9日
摘要: 题目链接。分析:之前做过类似的题,用的字典树链表写法,今天在训练指南上学了字典树数组的写法。#include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>using namespace std;const int maxnode = 10000*10+10;const int sigma_size = 10;struct Trie { int ch[maxnode][s 阅读全文
posted @ 2013-05-09 22:53 Still_Raining 阅读(147) 评论(0) 推荐(0) 编辑
  2013年5月7日
摘要: 题目链接。题意:n个人,从左到右排列,每个人都有一个不同的技能值 ai, 每场比赛3个人: 两名选手, 一名裁判。 裁判必须在两名选手中间, 并且技能值也在两名选手之间, 问一共能组织多少种比赛。分析: 考虑第i个人当裁判的情形。假设 ai 到 ai-1 中有 ci 个比 ai 个小, 那么就有 (i-1)-ci 个比 ai 大; 同理, 假设 ai+1 到 an 中有di个比ai 小, 那么就有 (n-i)-di 个比 ai 大。 根据乘法原理和加法原理, i当裁判 有 ci(n-i-di)+(i-ci-1)*di 种比赛。 这样问题转化为求 ci 和 di. 题目已经明确每个人都有一个.. 阅读全文
posted @ 2013-05-07 20:51 Still_Raining 阅读(211) 评论(0) 推荐(0) 编辑
摘要: 校赛已经结束了几天了,除去名次,就表现而言,我不得不进行一次深刻的反省。 校赛,总共有八道题,5到水题,另外3道是有些难度的题。自己AC水题的速度还算凑合,基本上不到一个小时(或者是半个?忘了)就结束了。但剩下的三个题,我只做出来了一道。想想就有些羞愧了,3个小时一道题? 不应该啊,马虎了,大意了?这样的借口面对自己的过失,弥补不了吧。 兵器磨得还不够锋利,使用的还不够熟练? 我想应当是这样。 想想也是,不熟练兵器的太多了。比如说,状态压缩DP(比赛就碰到了),树状数组等等还有很多其它兵器。 想到这,接下来要做的事就不言而喻了。 我想要站得更高,我要把所有的结果都变成自己进步的... 阅读全文
posted @ 2013-05-07 16:28 Still_Raining 阅读(267) 评论(2) 推荐(0) 编辑
  2013年5月3日
摘要: 题目链接。分析:本题可以用树状数组,也可以用线段树。树状数组:对于树状数组,请详见本随笔。要注意的是,比如说上图,要求 2 到 4 之间的最大值, c[4] 并非 2 到 4 之间的最大值,因为 c[4] 是 1 到 4 之间的最大值。这时候就只能单独看A[4], A[3], A[2]了。AC代码:#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;const int maxn = 200000 + 10;int n 阅读全文
posted @ 2013-05-03 09:46 Still_Raining 阅读(205) 评论(0) 推荐(0) 编辑
摘要: 树状数组又称二叉索引树(Binary Indexed Tree,BIT),是一种解决动态连续和查询问题的数据结构。辅助数组 C: Ci= Ai-lowbit(i)+1 + Ai-lowbit(i)+2 + ... + Ai其中 lowbit(x) 代表 x的二进制表达式中最右边的1所对应的的值, 那么lowbit(x) = x & -x即C[6] 代表 A[5] 和 A[6] 的和, C[4] 代表 A[1] + A[2] + A[3] + A[4]那么如何求前缀和 Si 呢, 顺着结点i往左走, 边走边“往上爬”, 把沿途经过的 Ci 累加起来就可以了。int sum(int x){ 阅读全文
posted @ 2013-05-03 09:38 Still_Raining 阅读(258) 评论(0) 推荐(0) 编辑
  2013年4月29日
摘要: 题目链接。分析:博弈论水题。要使行列都走到关键数.如果行是关键数,列不是,就向下走一;如果行是行不是关键数,列是,就想左走一;如果行列都不是,就想左下走一;如果行列都是的话,就pity了。#include <iostream>#include <algorithm>#include <cstdio>#include <cstdlib>#include <cstring>#include <queue>#include <stack>#include <map>using namespace std; 阅读全文
posted @ 2013-04-29 23:51 Still_Raining 阅读(205) 评论(0) 推荐(0) 编辑
摘要: 题目链接。分析:《算法竞赛入门经典——训练指南》上的一道例(水)题,map的应用,个人感觉代码中注释掉的那一句没有什么意义,就注释掉了,提交确实也对了。map的小知识点(总结自c++ primer):对于map容器,如果下标所表示的键在容器中不存在,则添加元素。书中的例子:map<string, int> word_count;sting word;while(cin>>word) ++word_count[word];在单词第一次出现时,会在word_count中创建并插入一个以该单词为索引的新元素,同时将它的值初始化为0。当只想要知道某元素存在,而当元素不存在时,并 阅读全文
posted @ 2013-04-29 17:56 Still_Raining 阅读(181) 评论(0) 推荐(0) 编辑
  2013年4月28日
摘要: 题目链接。分析:该题目是一个约瑟夫环的变形,区别就是第一个删除的数是m。该题的n和k都比较大,链表法O(nk),是不行的。因为只关心最后一个被删除的编号,而不需要完整的删除顺序,可以用递推法求解。先分析一下传统的约瑟夫环:n个人,编号0~n-1,每喊道k该人就被淘汰,直到最后剩下一个人。公式为:f(n) = (f(n-1) + k) % n,f(1)=0(这里的f(n)为最后一个人在序列剩余n个人时的编号)公式推导:初始的序号为(一)0, 1, ..., q-1, q, q+1, ..., n-1设q = k % n, 出列q-1后,序列变为(二)0, 1, ..., q-2, q, q+1, 阅读全文
posted @ 2013-04-28 13:19 Still_Raining 阅读(256) 评论(0) 推荐(0) 编辑
  2013年4月23日
摘要: 题目链接。分析:《训练指南》上的代码是二维的,优化了下,改成了一维的。#include <iostream>#include <vector>#include <cstring>#include <algorithm>#include <cstdio>#include <cmath>using namespace std;const int maxn = 1000 + 10;int _left[maxn], _right[maxn], _up[maxn];char mat[maxn];int main(){ int T, 阅读全文
posted @ 2013-04-23 12:51 Still_Raining 阅读(158) 评论(0) 推荐(0) 编辑
  2013年4月20日
摘要: 题目链接。分析:《训练指南》上的代码,写的不是一般的漂亮。贴之以珍藏。#include <iostream>#include <vector>#include <cstring>#include <algorithm>#include <cstdio>#include <cmath>using namespace std;const int maxn = 1000 + 10;vector<int> g[maxn], nodes[maxn];int fa[maxn], k, n;bool covered[maxn 阅读全文
posted @ 2013-04-20 19:45 Still_Raining 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 题目链接。分析:贪心不能解决背包问题在于,它无法保证能将背包装满,部分闲置的背包空间使每公斤背包空间的价值降低了。因此可以大范围用贪心,小范围用背包。注意:提交过程中WA了很多次,原因已查明, WA时用的int p, v;而AC用的是long long p, v; 题目中已明确给出数据范围,按理说int是可以的,不明白为什么会WAAC代码如下:#include <iostream>#include <vector>#include <cstring>#include <algorithm>#include <cstdio>#inclu 阅读全文
posted @ 2013-04-20 16:23 Still_Raining 阅读(324) 评论(0) 推荐(0) 编辑
  2013年4月16日
摘要: 题目链接。分析:自己写的时候是直接模拟的,但似乎训练指南上的解法更好。偶的代码:View Code #include <iostream>#include <algorithm>#include <cstdio>using namespace std;const int maxn = 1010;struct Job{ int b, j;}a[maxn];int cmp(const Job &x, const Job &y){ return x.j > y.j;}int main(){ int n, cnt=0; while(cin> 阅读全文
posted @ 2013-04-16 13:04 Still_Raining 阅读(243) 评论(0) 推荐(0) 编辑
  2013年4月13日
摘要: Emergency【Description】Kudo’s real name is not Kudo. Her name is Kudryavka Anatolyevna Strugatskia, andKudo is only her nickname.Now, she is facing an emergency in her hometown:Her mother is developing a new kind of spacecraft. This plan costs enormous energy butfinally failed. What’s more, because o 阅读全文
posted @ 2013-04-13 23:15 Still_Raining 阅读(324) 评论(0) 推荐(0) 编辑
  2013年4月11日
摘要: 题目链接。分析:作为状态压缩DP入门题,很好。由题意可知:1.任意两牛(包括行和列)不能临近2.牛只能在有草的即值为1的地方3.不放牛也为一种方案定义dp[i][s]为第i行状态s下的方案数。dp[i][s] =∑(dp[i-1][s']),其中s'为不与s冲突的状态注意:因为位运算优先级很低,所以要多加括号。因此if((cow & (cow<<1)) != 0) return 0;和if(cow & (cow<<1) != 0) return 0;是不一样的#include <cstdio>#include <cstr 阅读全文
posted @ 2013-04-11 13:37 Still_Raining 阅读(239) 评论(0) 推荐(0) 编辑
  2013年4月10日
摘要: 很强悍的算法,至今,仍旧迷迷糊糊。先将看懂的代码贴上来。牛人讲解:http://blog.csdn.net/lhshaoren/article/details/7526480以下代码是转自牛人的。#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>using namespace std;#define MAXN 21const double INF = 1<<23;struct Node{ int x 阅读全文
posted @ 2013-04-10 21:29 Still_Raining 阅读(224) 评论(0) 推荐(0) 编辑
  2013年4月7日
摘要: 题目链接。分析;主要是学着用一下bsearch。#include <stdio.h>#include <stdlib.h>#include <string.h>struct Entry{ char english[15], foreign[15];}entrys[100010];int cmp(const void *a, const void *b){ return strcmp((*(struct Entry *)a).foreign, (*(struct Entry *)b).foreign);}int b_cmp(const void *a, con 阅读全文
posted @ 2013-04-07 12:09 Still_Raining 阅读(180) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 13 下一页