judge

Virtual Judge HDU 1241 Oil Deposits

萝らか妹 提交于 2019-12-02 13:14:30
八方向 深搜 #include <iostream> #include<cstdio> #include<cstdlib> #include<algorithm> using namespace std; char maps[1050][1050]; int n,m,d[8]= {-1,-1,-1,0, 0, 1,1,1}; int z[8]= {-1, 0, 1,-1,1,-1,0,1}; //8个方向 void dfs(int x, int y) { maps[x][y] = '*'; //变为*,相当于走过 for (int i = 0; i < 8; i++) { int nx = x + d[i], ny = y + z[i]; if (0<=nx&&nx<m&&0<=ny&&ny<n) { if (maps[nx][ny]=='@') { dfs(nx, ny); } } } } int main() { while(~scanf("%d%d", &m, &n)&&(m || n)) { int count = 0; for(int i = 0; i < m; i++) scanf("%s", maps[i]); for(int i = 0; i < m; i++) for(int j = 0; j < n; j++) { if(maps[i][j]=='@') {

Virtual Judge POJ 2251 Dungeon Master

倾然丶 夕夏残阳落幕 提交于 2019-12-02 13:14:26
三维数组加宽搜 #include <stdlib.h> #include <string.h> #include <stdio.h> const int MAXN=50; int c, k, h; char ma[MAXN][MAXN][MAXN]; //定义三维数组 长宽高 int visit[MAXN][MAXN][MAXN]; //标记数组 struct node { int c, k, h;//结构体记录到达某个点 c长k宽h高 int step;//走的步数 }; struct node t[33433];//结构体队列 struct node p, q, w, l; int f[][3] = {0,0,1, 0,0,-1, 0,1,0, 0,-1,0, 1,0,0, -1,0,0};//向上下左右前后六个方向移动 包括上楼 void bfs() { visit[p.c][p.k][p.h] = 1;//标记已经走过 int front = 0, rear = 0; t[rear++] = p;//入队 while(front!=rear) { //当队列不为空的时候 w = t[front++]; if(w.c==q.c&&w.k==q.k&&w.h==q.h) { //如果是终点,直接输出 printf("Escaped in %d minute(s).\n", w

Virtual Judge POJ 3278 Catch That Cow

情到浓时终转凉″ 提交于 2019-12-02 13:14:20
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<queue> const int maxn =100010; using namespace std; int n,m; struct data { int x,step; } p; int vis[100005]; void bfs() { memset(vis,0,sizeof(vis)); //重置 queue<data>q; //队列 p.x=n; //起点 p.step=0; //起点到起点的距离 q.push(p); //压入队列 vis[n]=1; //走过 while(!q.empty()) { p=q.front(); q.pop(); if(p.x==m) { printf("%d\n",p.step); //直接输出 return ; } data k=p; if(k.x+1<maxn&&!vis[k.x+1]) { //尝试前进一步 k.x++; //如果可以,加坐标 vis[k.x]=1; //标记走过 k.step++; // 加步数 q.push(k); //新的位置压入队列 } k=p; if(k.x-1>=0&&!vis[k.x-1]) { /

Virtual Judge POJ 1328 Radar Installation

痞子三分冷 提交于 2019-12-02 13:14:18
贪心 #include<algorithm> #include<iostream> #include<cstdio> #include<cmath> using namespace std; struct Radar { double start,end; } radar[1005]; bool cmp(Radar a,Radar b) { return a.start<b.start; } int main() { int n,d,x,y,m,num,flag; double l,r; m = 1; while(scanf("%d%d",&n,&d)) { if(!n && !d) //如果为0 break; flag = true; for(int i = 0; i < n; i++) { scanf("%d%d",&x,&y); if(y > d) flag = false; radar[i].start = x - sqrt(d * d - y * y); //勾股定理 radar[i].end = x + sqrt(d * d - y * y); //区间覆盖范围 } if(!flag) { printf("Case %d: -1\n",m++); continue; } sort(radar,radar + n,cmp); //排序 n为岛屿数目 num = 1,l =

LeetCode132——分割回文串II

允我心安 提交于 2019-12-02 02:30:31
我的LeetCode代码仓: https://github.com/617076674/LeetCode 原题链接: https://leetcode-cn.com/problems/palindrome-partitioning-ii/description/ 题目描述: 知识点:动态规划 思路:动态规划 首先是对回文串的判断,不像 LeetCode131——分割回文串 中的做法,对一个字符串s用指向首字符和末字符的双指针分别向后和向前遍历字符串s中的字符来判断s是否是回文串。 本题对回文串的判别方法使用动态规划的思路。对于字符串s,如果其首字符和末字符不相同,显然其不是一个回文串。如果其首字符和末字符相同,那么我们去判断字符串s出去首字符和末字符的子串是否是回文串。 状态定义 :judge(i, j) -------- 字符串s中[i, j]范围内的子串是否是回文串 状态转移 : (1)如果s.charAt(i) != s.charAt(j),judge(i)(j) = false。 (2)如果s.charAt(i) == s.charAt(j), a:如果此时j - i <= 1,即[i, j]范围内的字符个数小于等于2个,judge(i)(j) = true。 b:否则,judge(i)(j) = judge(i + 1)(j - 1)。 很显然的一点是