题意:很复杂的题意,我描述不清楚。

题目链接:http://acm.bnu.edu.cn/bnuoj/contest_show.php?cid=3033#problem/33526

大致是,给定一个起点,一个终点,和一些墙,这些墙是不能越过的,然后一个人他每次走可以往四个方向走,可以加速,可以减速,也可以匀速。

也不一定是四个方向,因为他有一个VX,VY,所以每次走的方向其实都是不固定的,所以的四个方向就是他加速度的方向就是这四个。大家理解就好。

然后要从起点开始,走到终点,问最少需要多少步,而且走到终点的时候速度必须是0。

这道题的搜索部分其实很好想到,BFS开四维记录坐标和当前的VX,VY 。

因为速度有负的,所以我把起始速度开到16 。

然后搜索部分没什么问题了,对于计算几何部分的话,就是一个线段交的模版,没敲错基本上没问题。

CODE:.

#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#define Max 2505
#define FI first
#define SE second
#define ll long long
#define PI acos(-1.0)
#define inf 0x3fffffff
#define LL(x) ( x << 1 )
#define bug puts("here")
#define PII pair<int,int>
#define RR(x) ( x << 1 | 1 )
#define mp(a,b) make_pair(a,b)
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,s,t) for( int i = ( s ) ; i <= ( t ) ; ++ i ) using namespace std; struct Point {
int x , y ;
Point() {}
Point(int xx ,int yy) : x(xx) , y(yy) {}
};
struct stline {
Point a,b;
} line1,line2;
int n , m ;
int num ;
int sx , sy , ex , ey ;
struct WAll {
int sx , sy , ex ,ey ;
} w[11] ; #define N 64
int dis[N][N][32][32] ;
queue<pair<PII, PII> > qe ;
#define MP(a , b , c , d) mp(mp(a, b) , mp(c , d))
int mx[] = {1 , -1 , 0 ,0 , 0 } ;
int my[] = {0 , 0 , 0 ,1 , -1 } ;
int inmap(int x ,int y) {
if(x >= 0 && x < n && y >= 0 && y < m)return 1 ;
return 0 ;
} int dblcmp(double a,double b) {
if (fabs(a-b)<=1E-6) return 0;
if (a>b) return 1;
else return -1;
}
//***************点积判点是否在线段上***************
double dot(double x1,double y1,double x2,double y2) { //点积
return x1*x2+y1*y2;
}
int point_on_line(Point a,Point b,Point c) { //求a点是不是在线段bc上,>0不在,=0与端点重合,<0在。
return dblcmp(dot(b.x-a.x,b.y-a.y,c.x-a.x,c.y-a.y),0);
}
//**************************************************
double cross(double x1,double y1,double x2,double y2) { //叉积
return x1*y2-x2*y1;
}
double ab_cross_ac(Point a,Point b,Point c) { //ab与ac的叉集
return cross(b.x-a.x,b.y-a.y,c.x-a.x,c.y-a.y);
}
int ab_cross_cd (Point a,Point b,Point c,Point d) { //求ab是否与cd相交
double s1,s2,s3,s4;
int d1,d2,d3,d4;
Point p;
d1=dblcmp(s1=ab_cross_ac(a,b,c),0);
d2=dblcmp(s2=ab_cross_ac(a,b,d),0);
d3=dblcmp(s3=ab_cross_ac(c,d,a),0);
d4=dblcmp(s4=ab_cross_ac(c,d,b),0);
//如果规范相交则求交点
if ((d1^d2)==-2 && (d3^d4)==-2) {
p.x=(c.x*s2-d.x*s1)/(s2-s1);
p.y=(c.y*s2-d.y*s1)/(s2-s1);
return 1;
} //如果不规范相交
if (d1==0 && point_on_line(c,a,b)<=0) {
p=c;
return 1 ;
}
if (d2==0 && point_on_line(d,a,b)<=0) {
p=d;
return 1 ;
}
if (d3==0 && point_on_line(a,c,d)<=0) {
p=a;
return 1 ;
}
if (d4==0 && point_on_line(b,c,d)<=0) {
p=b;
return 1 ;
}
//如果不相交
return 0;
} int check(int x ,int y ,int xx ,int yy){
Point p1(x ,y) ;
Point p2(xx ,yy) ;
for (int i = 0 ; i < num ; i ++ ){
Point p3(w[i].sx , w[i].sy) ;
Point p4(w[i].ex , w[i].ey) ;
if(ab_cross_cd(p1 , p2 , p3 , p4)) return 1 ;
}
return 0 ;
}
int bfs() {
while(!qe.empty())qe.pop() ;
qe.push(MP(sx , sy , 16 , 16)) ;
for (int i = 0 ; i < N ; i ++ ) {
for (int j = 0 ; j < N ; j ++ ) {
for (int k = 0 ; k < N / 2; k ++ )
for (int x = 0 ; x < N / 2 ; x ++ )
dis[i][j][k][x] = inf ;
}
}
dis[sx][sy][16][16] = 0 ;
while(!qe.empty()) {
pair<PII , PII > tp = qe.front() ;
qe.pop() ;
for (int i = 0 ; i < 5 ; i ++ ) {
int vx = tp.SE.FI + mx[i] - 16 ;
int vy = tp.SE.SE + my[i] - 16 ;
int tx = tp.FI.FI + vx ;
int ty = tp.FI.SE + vy ;
if(inmap(tx ,ty) && vx > -16 && vy > -16 && vx < 16 && vy < 16 && !check(tp.FI.FI ,tp.FI.SE , tx ,ty)) {
if(dis[tx][ty][vx + 16][vy + 16] > dis[tp.FI.FI][tp.FI.SE][vx - mx[i] + 16][vy - my[i] + 16] + 1 ) {
dis[tx][ty][vx + 16][vy + 16] = dis[tp.FI.FI][tp.FI.SE][vx - mx[i] + 16][vy - my[i] + 16] + 1 ;
qe.push(MP(tx , ty , vx + 16, vy + 16)) ;
}
}
}
}
return dis[ex][ey][16][16] ;
}
int main() {
while(cin >> m >> n ) {
cin >> sy >> sx >> ey >> ex ;
cin >> num ;
for (int i = 0 ; i < num ; i ++ )cin >> w[i].sy >> w[i].sx >> w[i].ey >> w[i].ex ;
int fk = bfs() ;
cout << fk << endl;
}
return 0 ;
}

UVALIVE 5893 计算几何+搜索的更多相关文章

  1. BZOJ4614 UVA1742 Oil 计算几何+搜索+扫描线

    正解:计算几何+搜索+扫描线 解题报告: 传送门 哇我是真的觉得这题很妙了!各个方面都很妙啊... 首先有一个很重要的结论:最优线一定可以通过各种变换(旋转/平移)使得经过一条线段的左端点(...并不 ...

  2. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  3. NOIP考点

    NOIP考点 基础算法 图 树 数论 数据结构 动态规划 搜索 其他算法 省选知识点汇总 图论 数据结构 字符串相关算法及数据结构 数学 计算几何 搜索 动态规划 其他算法 转自:巨佬的博客 加*号是 ...

  4. poj2148

    题意:给出若干个没有公共面积的多边形,几个多边形可能属于同一个国家,要求给这个地图染色,同一个国家用相同的颜色,相邻国家不能用相同颜色.问最少需要多少种颜色. 分析:计算几何+搜索.先判断哪些多边形是 ...

  5. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  6. UVALive 4864 Bit Counting --记忆化搜索 / 数位DP?

    题目链接: 题目链接 题意:如果一个数二进制n有k位1,那么f1[n] = k,如果k有s位二进制1,那么f2[n] = f1[k] = s.  如此往复,直到fx[n] = 1,此时的x就是n的”K ...

  7. UVALive 6255 Kingdoms --状态搜索

    题意:n个国家,给出国家间相互的债务关系,每个国家如果债务>收入就要破产,破产后该国的所有债务关系全部清除,第一个破产的国家不同有可能造成最后的没破产的国家的不同,问哪些国家有可能成为独自存活的 ...

  8. UVALive 6470 Chomp --记忆化搜索

    题意:给一个只有三行的方块阵(横向最多100个),然后p,q,r分别代表第1,2,3层的方格数,两人轮流去掉一个格子,此时这个格子的右上方都会被去掉,面临只剩最左下角的一个格子的状态的人输,问先手能否 ...

  9. UVALive 4426 Blast the Enemy! 计算几何求重心

    D - Blast the Enemy! Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Subm ...

随机推荐

  1. Nginx配置同一个域名http与https两种方式都可访问

    ##配置 http://test.pay.joyhj.com https://test.pay.joyhj.com 两者都可访问 # vim /usr/local/nginx/conf/vhost/t ...

  2. OC - 19.GCD

    简介 GCD(Grand Center Dispatch)是Apple为多核的并行运算提出的解决方案,纯C语言 更加适配多核处理器,且自动管理线程的生命周期,使用起来较为方便 GCD通过任务和队列实现 ...

  3. chop 与 chomp 的对比

    chop       截去最后一个字符,无论是什么字符 chomp   截去末尾的分隔符(\n),行分隔符由$/决定 $a="ab\n\n\n"; #截去多个空行. $/=&quo ...

  4. Linux 使用yum install安装mysql登陆不上解决办法

    CentOS yum安装mysql后 Can’t connect to local MySQL server through socket ‘/var/lib/ CentOS Can’t connec ...

  5. function field , store={}...

    def _get_product_state(self,cr,uid,ids,fields,arg=None,context=None): res={} dic=dict( self.pool.get ...

  6. 我学C的那些年[ch01]:浅淡C语言的编译过程

    前几天大致学习了C语言的编译过程,那么今天就和大家分享一下 首先,编译C语言,需要一个文本编辑器(windows自带的也行),和一个MinGW编译器(需要配置环境),就可以将.c文件编译成.exe文件 ...

  7. IIC 概述之1

    概述: I²C 是Inter-Integrated Circuit的缩写,发音为"eye-squared cee" or "eye-two-cee" , 它是一 ...

  8. windows下实现uboot的tftp下载功能

    一.原理分析 带有uboot的开发板实际上充当的就是tftp客户端,而PC机扮演的角色就是tftp服务器端,而tftp下载功能实际上就是文件传输.tftp服务器可以建立在虚拟机linux下,也可以建立 ...

  9. iPad和iPhone开发的比较

    一.iPad简介 1.什么是iPad 一款苹果公司于2010年发布的平板电脑 定位介于苹果的智能手机iPhone和笔记本电脑产品之间 跟iPhone一样,搭载的是iOS操作系统 2.iPad的市场情况 ...

  10. shell条件测试

    文件状态测试-b filename : 当filename 存在并且是块文件时返回真(返回0)-c filename : 当filename 存在并且是字符文件时返回真-d pathname : 当p ...