
ACM - 搜索
文章平均质量分 69
Freenm
这个作者很懒,什么都没留下…
展开
-
HDU 3345 - War Chess
#include#include#includeusing namespace std;int n,m,mv;char map[103][103];bool vis[103][103];struct type{ int i,j,mv; bool operator<(const type &oth)const { return mv<oth.mv原创 2017-04-05 23:06:11 · 367 阅读 · 0 评论 -
POJ 3187 - Backward Digit Sums
依然是非常暴力的DFS,1~n这n个数字,全排列一遍,找到第一个符合的排列就是答案。#include#includeusing namespace std;int n,sum,num[11],finish=0;int cal(){ int temp[11][11]; for(int i=0;i<n;i++) temp[1][i]=num[i]; for(int i=2;i<=n原创 2017-03-24 10:12:15 · 317 阅读 · 0 评论 -
POJ 3050 - Hopscotch
超级大水题,一次过……以5*5的map的某一格 ( i , j ) 为起点,dfs到deep=6,直接把得到的那个数字插入到set容器里(set容器保证每个元素不重复),然后 i=1 to 5 { j = 1 to 5{...} } ,把每一格都作为起点进行搜索,最后set::size()就是答案#include #include#includeusing namespa原创 2017-03-23 21:26:41 · 324 阅读 · 0 评论 -
POJ 1753 - Flip Game
港真,这题,DFS太暴力了……就是16格,flip或者不flip,2^16情况全部测试一遍,找那个使得 judge() == 1(满足全棋盘同色),同时step最小。#include#includeusing namespace std;int chess[4][4];int dx[4]={0,-1,0,+1};int dy[4]={+1,0,-1,0};int cnt=99999原创 2017-03-23 15:44:29 · 326 阅读 · 0 评论 -
POJ 3669 - Meteor Shower
#include#include#includeusing namespace std;int dx[4]={+1,0,-1,0};int dy[4]={0,+1,0,-1};struct type{ int x,y,t;}meteor[50000+5],now,next;int n,map[305][305],latest;bool vis[305][305];int bf原创 2017-03-21 22:26:16 · 306 阅读 · 0 评论 -
POJ 1979 - Red and Black
“.”能走,“#”不能走,“@”为起点,求所有能走到的地方。BFS:#include#include#includeusing namespace std;int w,h;int dir[4][2]={{0,+1},{-1,0},{0,-1},{+1,0}};char t[23][23];bool vis[23][23];struct type{ int x,y;}s原创 2017-03-20 22:13:34 · 312 阅读 · 0 评论 -
HDU 1372 - Knight Moves
(感觉自己越来越懒了,题目都不用贴了……)谨以此纪念一下自己学会的第一道BFS~#include#include#includeusing namespace std;struct type{ int x,y,step;}st,ed;bool s[10][10];int dir[8][2] = {{-1,+2},{-2,+1},{-2,-1},{-1,-2},{1,-2},原创 2017-03-20 20:39:40 · 311 阅读 · 0 评论