摘要: 2013 ACM-ICPC吉林通化全国邀请赛http://acm.hdu.edu.cn/contests/contest_show.php?cid=4762013 ACM-ICPC南京赛区全国邀请赛http://acm.hdu.edu.cn/contests/contest_show.php?cid... 阅读全文
posted @ 2014-05-10 20:24 basement_boy 阅读(94) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1210 1 ///2014.5.8 2 ///hdu1210 3 4 #include 5 #include 6 #include 7 #include 8 #include 9 #inclu... 阅读全文
posted @ 2014-05-10 19:41 basement_boy 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 题目来源:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=456&page=show_problem&problem=1822刘汝佳《算法竞赛入门经典训练指南》1.1例5 1 ///2014.4.13 2 ///10881 3 ///刘汝佳《算法竞赛入门经典训练指南》1.1例5 4 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 using namespace st 阅读全文
posted @ 2014-04-13 14:07 basement_boy 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 题目来源:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=456&page=show_problem&problem=4134刘汝佳《算法竞赛入门经典训练指南》1.1例4 1 ///2014.4.12 2 ///uva1388 3 ///刘汝佳《算法竞赛入门经典训练指南》1.1例4 4 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 using namespace 阅读全文
posted @ 2014-04-13 00:09 basement_boy 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=456&page=show_problem&problem=2275刘汝佳《算法竞赛入门经典训练指南 1.1例3 1 ///2014.4.12 2 ///uva11300 3 ///刘汝佳《算法竞赛入门经典训练指南 1.1例3 4 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 using namespace 阅读全文
posted @ 2014-04-12 22:16 basement_boy 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=456&page=show_problem&problem=2829刘汝佳《算法竞赛入门经典训练指南 1.1例2表示uva这么卡,让人怎么受得了。。。 1 ///2014.4.12 2 ///uva11729 3 ///刘汝佳《算法竞赛入门经典训练指南 1.1例2 4 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 阅读全文
posted @ 2014-04-12 17:10 basement_boy 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2267刘汝佳《算法竞赛入门经典训练指南》1.1例1 1 ///2014.4.12 2 ///uva11292 3 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std;10 11 #define maxn 2001012 int n,m;13 int A[maxn],B[m 阅读全文
posted @ 2014-04-12 11:31 basement_boy 阅读(83) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=2661吴永辉《算法设计编程实验》1.1.1 1 ///2014.4.12 2 ///poj2661 3 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 10 int main()11 {12 // freopen("in","r",stdin);13 // freopen("out","w",stdout);14 15 int a;16 while( cin> 阅读全文
posted @ 2014-04-12 11:01 basement_boy 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=3628动态规划第二题,还是纯01背包题意:就是给出n和b,然后给出n个数,用这n个数中的某些,求出一个和,这个和是>=b的最小值,输出最小值与b的差。分析:这里的n个物品,每个物品的重量为c[i],价值为w[i]并且c[i]==w[i],,容量为所有c[i]的和sum。只要在f[]中从头开始找,找到一个最小>=b的就是题目要的解 1 ///2014.4.10 2 ///poj3628 3 4 #include 5 #include 6 #include 7 using namespace std; 8 9 int N, 阅读全文
posted @ 2014-04-10 19:27 basement_boy 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=362401背包问题,接触DP的第一题。 1 ///2014.4.10 2 ///poj3624 3 4 #include 5 #include 6 #include 7 using namespace std; 8 9 int N,M;10 int w[3500],c[3500];11 int f[13500];12 13 int main()14 {15 // freopen("in","r",stdin);16 // freopen("out","w&quo 阅读全文
posted @ 2014-04-10 18:25 basement_boy 阅读(93) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=1426简单的搜索题,一开始想着用bfs,结果TLE了,看有用dfs写A掉了,就用dfs写,过然AC了。bfs超时的代码: 1 ///2014.4.7 2 ///poj1426 3 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 10 const int MaxLength = 1000000;11 unsigned long long queue[MaxLength];12 int n;13 14 unsigned long lon... 阅读全文
posted @ 2014-04-07 12:21 basement_boy 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=3278题目是简单的bfs,我却花了好多时间调试 1 ///2014.4.5 2 ///poj3278 3 //16MS 4 5 #include 6 #include 7 #include 8 #include 9 using namespace std;10 11 #define MAXLENGTH 40010012 13 struct node14 {15 int line;16 int deep;17 };18 int N,K;19 node queue[MAXLENGTH];20 bool vis... 阅读全文
posted @ 2014-04-07 00:05 basement_boy 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3040水题,排个序就好了。 1 ///2014.4.3 - 2014.4.5 2 ///hdu3040 3 4 ///203MS 5 6 #include 7 #include 8 #include 9 #include 10 using namespace std;11 12 struct Vote{13 int time;14 long long tel;15 int num;16 };17 18 int N;19 int girlGet[11];20 int... 阅读全文
posted @ 2014-04-05 20:59 basement_boy 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://codeforces.com/contest/409/problem/A很水很水的题 1 ///2014.4.2 2 ///codeforces April Fools Day Contest 2014 3 ///A. The Great Game 4 5 #include 6 #include 7 #include 8 using namespace std; 9 10 int main()11 {12 // freopen("in","r",stdin);13 // freopen("out"," 阅读全文
posted @ 2014-04-02 23:18 basement_boy 阅读(189) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=2251题目大意:给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径移动方向可以是上,下,左,右,前,后,六个方向每移动一次就耗费一分钟,要求输出最快的走出时间。不同L层的地图,相同RC坐标处是连通的简单的bfs 1 ///2014.3.30 - 2014.4.2 2 ///poj2251 3 4 #include 5 #include 6 using namespace std; 7 8 int L,R,C; 9 char maze[40][40][40];10 bool visted 阅读全文
posted @ 2014-04-02 21:32 basement_boy 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=1321poj少有的中文题目,很嗨皮直接上代码: 1 ///2014.3.30 2 ///poj1321 3 4 #include 5 #include 6 using namespace std; 7 8 int N,K; 9 bool board[10][10];10 bool used[10];11 int C;12 13 void init(){14 char temp;15 for(int i=1 ; i>temp;19 if( temp=='#' )20 ... 阅读全文
posted @ 2014-03-30 22:24 basement_boy 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=3009/**************************************/懒得写题意,下面是抄自小优师姐的题意解释:就是要求把一个冰壶从起点“2”用最少的步数移动到终点“3”其中0为移动区域,1为石头区域,冰壶一旦想着某个方向运动就不会停止,也不会改变方向(想想冰壶在冰上滑动),除非冰壶撞到石头1 或者 到达终点 3注意的是:冰壶撞到石头后,冰壶会停在石头前面,此时(静止状态)才允许改变冰壶的运动方向,而该块石头会破裂,石头所在的区域由1变为0. 也就是说,冰壶撞到石头后,并不会取代石头的位置。终点是一个摩擦力很大的区 阅读全文
posted @ 2014-03-30 11:01 basement_boy 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://codeforces.com/contest/404/problem/B 模拟题,但是数据很大,可能会溢出。所以要使用一些防止溢出。 刚开始写没有注意防止溢出,结果过不了后面的数据,下面是没有通过的代码:///2014.3.19///Codeforces Round #237 Div.2///B#include #include using namespace std;int main(){ // freopen("in","r",stdin); // freopen("out","w",s 阅读全文
posted @ 2014-03-20 21:37 basement_boy 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://codeforces.com/contest/404/problem/A模拟题,第一次没有考虑对角线上的字符和其余地方的字符是相同的的情况,改掉后就OK了。 1 ///2014.3.19 2 ///Codeforces Round #237 Div.2 3 ///A 4 5 #include 6 #include 7 using namespace std; 8 9 char table[310][310];10 11 int main()12 {13 // freopen("in","r",stdin);14 // freope 阅读全文
posted @ 2014-03-20 21:29 basement_boy 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://codeforces.com/contest/402/problem/C 刚刚看了题目完全没有头绪,看了题解还是不理解为什么。但直接根据题解写代码A掉了。最后想想,题解的思路是这样的:要得到满足条件的图,则应该让边尽可能的分布在每两个点之间。这样才能任选一部分点使得这部分构成的子图的边数的最大值尽可能小。 1 ///2014.3.18 2 ///codeforces round #236 div.2 3 ///C 4 5 #include 6 #include 7 using namespace std; 8 9 int main()10 {11 //... 阅读全文
posted @ 2014-03-20 21:26 basement_boy 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://codeforces.com/contest/402/problem/B暴力求解,第一次做没有考虑到剪切后树的高度不能为零和负值,WA了,改掉后就OK了 1 ///2014.3.16 - 2014.3.18 2 ///codeforces round #236 div.2 3 ///B 4 5 #include 6 #include 7 using namespace std; 8 9 int n;10 int k;11 int tree[1050];12 13 int numOfNotCutTree;14 int numNotCut;15 16 bool in... 阅读全文
posted @ 2014-03-20 21:21 basement_boy 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://codeforces.com/contest/402/problem/A第一次做codeforces。第一道水题,没什么算法,直接贴代码。 1 ///2014.3.16 2 ///codeforces round #236 div.2 3 ///A 4 5 #include 6 #include 7 using namespace std; 8 9 int main()10 {11 int k,a,b,v;12 scanf("%d%d%d%d",&k,&a,&b,&v);13 int n = 0;14 while( a 阅读全文
posted @ 2014-03-20 21:17 basement_boy 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 贪心算法,从第0列开始扫描,删除从该列开始到后面最长的墙。祥见代码。 学习程序设计语言时老师总是耳提面命的告诉我们要养成良好的代码风格,要先有清晰的思路在动手写代码。先前总是有个大致思路就急于写代码实现。导致写着后面改前面,调试时也是很费力。如果动手前能有更清晰的思路和规划,写起来的确会更流畅,也方便调试。这些道理都懂,但还是亲身实践过才有更深刻的体会,才会自觉的用在coding中。 1 ///2014.3.15 - 2014.3.16 2 ///poj1230 3 4 #include 5 #include 6 #include 7 using namespace std; 8... 阅读全文
posted @ 2014-03-16 09:54 basement_boy 阅读(450) 评论(0) 推荐(0) 编辑
摘要: 2014-03-13TLE后就把输入和输出全改成 scanf( ) 和 printf( ) 了,但还是超时。感觉是搜索最短路径时用的方法太慢了。下面是TLE的代码: 1 ///2014.3.11 - 2014.3.13 2 ///poj3083 3 4 #include 5 #include 6 using namespace std; 7 8 int w,h; ///记录迷宫的大小 9 char maze[50][50]; ///记录迷宫 10 int start_w,start_h; ///记录迷宫的开始位置 11 int ... 阅读全文
posted @ 2014-03-13 19:53 basement_boy 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 这一题是比较简单的搜索题,但是题目要求走法是按照字典序的,这样要求搜索时注意顺序。 1 ///2014.3.10 2 ///poj2488 3 4 //16MS 5 6 /** 7 *简单的DFS,但是题目有个坑人的地方,就是字典序 8 *因为要求字典序,在搜索时要注意搜索步骤 9 *在搜索步骤上浪费了两个小时啊!!!10 */11 12 #include 13 #include 14 using namespace std;15 16 int p,q;17 int coordinate_x[30]; ///记录每一步的坐标18 int coordinate_y[30];19 ... 阅读全文
posted @ 2014-03-10 23:03 basement_boy 阅读(206) 评论(0) 推荐(0) 编辑
摘要: 1 ///2014.3.9 2 ///poj1573 3 4 /** 5 *模拟水题,比poj2632还水 6 */ 7 8 #include 9 #include 10 #include 11 using namespace std;12 13 int main()14 {15 // freopen("in","r",stdin);16 // freopen("out","w",stdout);17 18 int L,W;19 int first;20 while( cin>>L>>W&g 阅读全文
posted @ 2014-03-09 19:51 basement_boy 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 2014-03-0911:37:46题意就不解释了,很容易明白,直接上代码 1 ///2014.3.8 2 ///poj2632 3 4 /** 5 *模拟水题,主要是细心 6 *写了好长时间,自己编程速度还是不够 7 *速度不够有几个原因 8 *首先是整体思维的把握不够强烈, 9 * 有写到后面改前面的情况 10 *其次是编码不够熟练,积累不够 11 */ 12 13 #include 14 #include 15 #include 16 using namespace std; 17 18 struct robot{ 19 int... 阅读全文
posted @ 2014-03-09 11:39 basement_boy 阅读(269) 评论(0) 推荐(0) 编辑
摘要: 1 ///2014.3.8 2 ///poj1068 3 4 //time:0MS 5 6 /** 7 *对于给出的原括号串,存在两种数字密码串: 8 *1.p序列:当出现匹配括号对时, 9 * 从该括号对的右括号开始往左数,10 * 直到最前面的左括号数,就是pi的值。11 *2.w序列:当出现匹配括号对时,12 * 包含在该括号对中的所有右括号数(包括该括号对),13 * 就是wi的值。14 *题目的要求:对给出的p序列,求出对应的w序列。15 */16 17 #include 18 #include 19 #include 20 #include 21 u... 阅读全文
posted @ 2014-03-08 20:56 basement_boy 阅读(251) 评论(0) 推荐(0) 编辑
摘要: 写完代码在自己机子上用样例数据直接通过了,提交结果RE,然后改。改了以后WA,一直不得其解。上无聊的课时又把代码拿出来看,原来少打了一条 break; 语句。。。 1 ///2014.3.4 - 2014.3.6 2 ///poj3295 3 4 /** 5 *大致题意: 6 *输入由p、q、r、s、t、K、A、N、C、E共10个字母组成的逻辑表达式, 7 *其中p、q、r、s、t的值为1(true)或0(false),即逻辑变量; 8 *K、A、N、C、E为逻辑运算符, 9 *K --> and: x && y 10 *A --> or: x || y... 阅读全文
posted @ 2014-03-06 17:14 basement_boy 阅读(400) 评论(0) 推荐(0) 编辑
摘要: 1 ///2014.3.3 2 ///poj2586 3 4 /** 5 *题目大意是一个公司在12个月中,或固定盈余s,或固定亏损d. 6 *但记不得哪些月盈余,哪些月亏损, 7 *只能记得连续5个月的代数和总是亏损(20 21 int s,d;22 int dInFive; ///表示在连续五个月中最少有几个月份亏损23 int month[6] = {0,2,4,6,9,12}; 24 ///month[i]表示 i 为 dInFive时,12个月中的最少亏损月份数,笔算即可求出25 int S;26 27 void init( )28 {29 for(dInFiv... 阅读全文
posted @ 2014-03-03 20:26 basement_boy 阅读(239) 评论(0) 推荐(0) 编辑
摘要: 1 ///2014.3.2 2 ///poj2109 3 4 /** 5 *解法来自csdn上“ζёСяêτ - 小優YoU”的博客 6 *原博客链接: 7 * http://blog.csdn.net/lyy289065406/article/details/6642602 8 */ 9 10 #include 11 #include 12 #include 13 using namespace std;14 15 int main( )16 {17 // freopen("in","r",stdin);18 // freopen(" 阅读全文
posted @ 2014-03-02 21:01 basement_boy 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 思路在代码的注释中 1 ///2014.3.1 - 2014.3.2 2 ///poj1328 3 4 /** 5 *对要扫描到的每个岛求出雷达可以安置在海岸上的区间[begin,end], 6 *对这些区间按begin从小到大排序 7 *从第一个区间的end点开始安置雷达,然后依次检索下一个区间, 8 *若下一个区间完全在刚刚安置雷达的区间内(new.begin>=pre.begin && 9 * new.end17 #include 18 #include 19 20 struct Section21 {22 double begin;23 double end... 阅读全文
posted @ 2014-03-02 20:25 basement_boy 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 2014-03-01 poj2965,题目类似 poj1753,一开始用 1753 的代码改的,自己跑好多组数据都正确,但是超时了。代码如下: 1 ///2014.3.1 2 ///poj2965 3 4 #include 5 6 int chess; ///二进制末16位表示锁盘,1表示锁着、0表示打开状态 7 int step; 8 bool flag = false; ///标记是否是已经找到解 9 int solution[16];10 ///方便最后输出拨动的位置11 int forEasyCoutRow[16] = {1,1,1,1,2,2,2,2,3,3,... 阅读全文
posted @ 2014-03-01 20:32 basement_boy 阅读(251) 评论(0) 推荐(0) 编辑
摘要: 1 ///2014.2.28 - 2014.3.1 2 ///poj1753 3 4 /** 5 *题意: 6 *给你一个4*4的黑白棋盘,通过翻棋子使棋盘变为全白或全黑, 7 *(以下“翻一个位置”皆指翻着个位置和它周围的四个棋子。) 8 *翻子时四周的四个棋子如果存在的话颜色也会跟着改变。 9 *问最少需要多少步可以使棋盘变为一种颜色。10 **11 *思路:12 *每一次翻子会改变这个棋子和它周围的四个棋子的颜色,13 *所以在一个解中一个位置的棋子只应翻一次,14 *同时在不同的位置间翻子的顺序是对最后翻完后的结果没有影响的。15 *所以可以逐次翻每一个位置,... 阅读全文
posted @ 2014-03-01 15:56 basement_boy 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 对于满足(F0= 0,F1= 1, andFn=Fn− 1+Fn− 2forn≥ 2)的斐波那契数列,第n项可由矩阵求出公式如下: 1 ///2014.2.24 2 ///poj3070 3 4 #include 5 #include 6 #include 7 using namespace std; 8 9 #define MOD 1000010 //定义二阶矩阵11 struct MATRIX12 {13 long long f11;14 long long f12;15 long long f21;16 long long f22;17 };18... 阅读全文
posted @ 2014-02-24 19:45 basement_boy 阅读(508) 评论(0) 推荐(0) 编辑