随笔分类 - acm训练
摘要:题目连接:http://poj.org/problem?id=2240思路:直接见图,floyd一遍之后看是否有自身大于一的。注意是有向图代码:View Code 1 #include <iostream> 2 #include <map> 3 #include <string> 4 #include <stdio.h> 5 using namespace std; 6 map<string,int> st; 7 string s1,s2; 8 double mp[50][50]; 9 void init(int n)10 {11 i
阅读全文
摘要:题目连接:http://poj.org/problem?id=1125题目就是要求你算每个点在能够到达所有点的情况下求到达所有点的费时中最大的最小值及其起点,如果不能到达直接输出disjoint。代码View Code 1 #include <iostream> 2 #include <stdio.h> 3 #define max 1000000 4 using namespace std; 5 int map[106][105]; 6 void init(int n) 7 { 8 int i,j; 9 for(i = 1;i <= n;i++)10 {11 ..
阅读全文
摘要:有N个点,青蛙A 在点1上,青蛙B在点2上,然后青蛙可以通过剩下的点来到达2点,求各个通路中最大的一段中的最小值~题目连接http://poj.org/problem?id=2253我的代码:View Code 1 #include <stdio.h> 2 #include <string.h> 3 #include <math.h> 4 #include<algorithm> 5 #include <iostream> 6 using namespace std; 7 8 int n; 9 10 struct node11 {12
阅读全文
摘要:题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4462当时比赛的时候读错题意了。。。很悲催的没有考虑n*n个稻草人的时候。。。。然后一直WA= =。。。悲剧啊。。。。回来的时候崔老师教了一个枚举的办法。。。就是位运算。。之前做的一道DFS也可以用位运算来写(其实取1或者取0的dfs都可以用位运算写= =)~、膜拜崔老师~View Code #include <iostream>#include <math.h>#include <stdio.h>#include <string.h>#include
阅读全文
摘要:题意不再赘述。。。连接http://acm.hdu.edu.cn/showproblem.php?pid=4460此题直接郁闷致死。。。。比赛的时候用的是floyd然后直接超时。。。当时闪过spfa的想法,但是觉得如果是一个循环spfa话也会超时。。。今天试了一下。。。果然超时= =。。。郁闷啊亲。。。然后优化了一下,用一个邻接表去存边。一开始忽略了一点就是-1的输出。。。代码。View Code 1 #include <stdio.h> 2 #include <iostream> 3 #define inf 10000 4 #include <map> 5
阅读全文
摘要:题目连接http://poj.org/problem?id=3083题目大意:一看就是基本的迷宫问题,一个是优先往左走,一个优先往右走,还有一个是求最短。额。。。。好久没写bfs= =...上来bfs没加vis= =。。。。然后dfs又写错,因为是左右思路相同,我是直接复制的,找了好久一直是re= =、你妹妹的。。。用一个全局变量保存朝向,用一个%4来保存结果View Code 1 #include <stdio.h> 2 #include <string.h> 3 char map[100][100]; 4 int m,n,sx,sy,dx,dy; 5 int dir
阅读全文
摘要:POJ挂掉了,然后去ZOJ上。记得uva上有这题,直接pow水过,后来崔老师说用二分也可以写。ZOJ上我写的TLE= =...崔老师WA= =。。。目测不到哪里有错= =。。。做的POJ开封。二分代码View Code 1 #include<iostream> 2 #include<math.h> 3 #include <stdio.h> 4 #define eps 0.0000000001 5 using namespace std; 6 7 void div(double n,double k) 8 { 9 long long l,r,mid;10 l
阅读全文
摘要:原来做过的贪心比较简单View Code 1 #include <stdio.h> 2 #include <string.h> 3 #include <math.h> 4 #include <algorithm> 5 using namespace std; 6 struct node 7 { 8 int x,y; 9 }il[10005];10 struct re11 {12 double x1,x2;13 }radar[10005];14 int cmp(struct re a,struct re b)15 {16 return a.x2 &
阅读全文
摘要:题目连接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1035题目大意:给你一个黑白的棋盘,每次翻一个子(翻的子上下左右也自动翻),看最后能否返程全黑或者全白、最少要几次。View Code 1 #include <stdio.h> 2 #include <string.h> 3 int ans = 10000; 4 char map[10][10]; 5 int pan() 6 { 7 int i,j; 8 for(i = 0;i < 4;i++) 9 {1
阅读全文
摘要:题目连接:http://poj.org/problem?id=2049第一次遇到这种网格bfs。因为是迷宫问题所以一开始就认为是bfs或者是最短路。然后发现不知道网格应该怎么处理,后来想用网格的一个点来代替这个网格,但是有四条边。后来一想其实可以认为每个网格只有两条边,右边和上边。这样可以用右上方的点代表一个网格,然后用一个三维map[2][i][j]来表示,0,1分别表示恨着和竖着,然后用类似最短路的一个数组来记录门数,当其sx和sy超过199小于0直接输出0;一开始拉了一个if一直re= =...代码:View Code 1 #include <stdio.h> 2 #incl
阅读全文
摘要:题目连接题目大意就是输入M,N。然后输入map,如果遇到.那么就可一走,耗时为一,如果不为‘x’就是遇到守卫,需要杀死,额外耗时一,'#'是墙。代码:View Code 1 #include <stdio.h> 2 #include <string.h> 3 struct node 4 { 5 int x,y; 6 int step; 7 }q[100000]; 8 char map[250][250]; 9 int vis[250][250]; 10 int to[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};//方向 11
阅读全文
摘要:题目题目大意就是输入一个T然后输入一个素数,再输入另一个数,输入第一个数变成另一个所需要的最少步数。代码:View Code 1 #include <stdio.h> 2 #include <iostream> 3 #include <string.h> 4 5 using namespace std; 6 7 int vis[10005]; 8 int prim[10005],leap; 9 struct node 10 { 11 int n[5],step; 12 int num; 13 }q[4*10005]; 14 void make_prim(..
阅读全文
摘要:题目崔老师推荐,用BFS找路径,然后由于一开始的时候不知道那个打架的时间要费时然后WA了一次,然后当时看见有discuss里说开头可能有怪兽然后又没加优先队列然后又WA了了一次,最后因为优先队列的那个排序错了又WA了一次,一晚上就只做了这一道题。。。悲哀= =。。。View Code 1 #include<stdio.h> 2 #include<string.h> 3 char map[205][205]; 4 struct node 5 { 6 int x,y,step,f;//f存先驱,step是当前的步数。 7 }q[400005]; 8 9 int way...
阅读全文
摘要:题目连接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=99&problem=189&mosmsg=Submission+received+with+ID+10567261这道题跟我们小时候学筛子的时候有关,因为是6面三个颜色所以,直接看1-6,2-5,3-4的颜色搭配是否相同,相当于无向图,看看两个图是否相同就可以了。。注意是无向图哦~View Code 1 #include <stdio.h>
阅读全文
摘要:连接:http://poj.org/problem?id=3211俩人只能一起溪一中衣服也就是说两人洗的时候就是01背包就是,然后吧各种衣服所用时间相加。。。View Code 1 #include <stdio.h> 2 #include <string.h> 3 4 struct node 5 { 6 char color[20]; 7 int sum; 8 int a[105]; 9 int count;10 }col[15];11 int count;12 int search(char s[],int m)13 {14 int i;15 ...
阅读全文
摘要:题目连接http://poj.org/problem?id=11131113#include <stdio.h>#include<algorithm>#include <math.h>using namespace std;int q[50050];int f;struct node{ int x,y;}a[50050];int cmp(struct node p1,struct node p2){ int x1 = p1.x-a[0].x; int x2 = p2.x-a[0].x; int y1 = p1.y-a[0].y; int y2 = p2.y-
阅读全文
摘要:题目连接http://poj.org/problem?id=1159这道题原来见过,那时候没学DFS什么的,以为是搜索然后直接暴搜,但是说真的真是没有想到这题竟然是DP,那时候也没学DP就放弃了。。。这道题的思路就是把整个问题分解成小问题,然后从下往上来求。。。我们先设一个DP[N][N],它里面是每个i~j变成回文的最小添加量,也就是说我们可以看做DP后已经全部都是回文。那么DP[1][N]就可以满足一个状态方程if(STR[1] == STR[N]I = 1,J = N;DP[1][N] == DP[I+1][J-1] + 1 (STR[I] == STR[J]) DP[...
阅读全文
摘要:比赛那天下午做的。。。比赛的时候真不知道怎么做。。。亏了没做,做了我就死了。。欧拉回路我是真心不会判断啊(真的是忘了)。。。虽然离散考了86(鼓掌~),也不过是全班最高(再次鼓掌~)但是真的是恶补出来的(天赋秉异,美女上台献花)不扯淡了。。。这道题因为数据量比较大。。。500000的数据,所以用map和平常的查找肯定会TLE所以,要用到TRIE树。然后欧拉通路的判定就是通过查找度数为奇数的节点 < 2 是否成立不成立肯定是错的,但是成立了也要判断是不是父节点是否为一个节点。比如red redblue blue答案就是impossible代码如下View Code 1 #include &
阅读全文
摘要:题目连接http://poj.org/problem?id=1088这道题其实说实话知道了思路真的很简单,但是那天晚上做的时候很苦逼的错了好多地方然后查还没查出来= =。。。表示DFS真的很吃力= =。。。所谓的记忆化搜索现在看来就是吧上搜索过的给存起来。。。需要一个状态方程dp[i][j] = max(dp[i+1][j],dp[i-1][j],dp[i][j+1],dp[i][j-1]);四个方向搜一遍找到最合适的即可。。。代码View Code 1 #include <string.h> 2 #include <stdio.h> 3 int num[105][10
阅读全文
摘要:题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1180昨天晚上开始做这道题。。。以前打算做做这题但是不知道这优先队列应该怎么用。。。昨晚这道题才有点深入的了解些。。。这道题因为楼梯会变换方向会变成不同的路,所以一不能标记。。。而且要注意边界这个是我纠结了4歌小时候都最后经大神鉴定改错后的代码。。。-#include <string.h>#include <stdio.h>char map[30][30];int dis[4][2]= {{1,0},{0,1},{-1,0},{0,-1}};struct node{ int
阅读全文

浙公网安备 33010602011771号