W - Pipe

W - Pipe

题目描述

经过激烈的争夺,Lele终于把那块地从Yueyue的手里抢了回来。接下来,Lele要开始建造他的灌溉系统。

通过咨询Lele的好友——化学系的TT,Lele决定在田里挖出N条沟渠,每条沟渠输送一种肥料。

每条沟渠可以看作是一条折线,也就是一系列线段首尾连接而成(除了第一条线段开头和最后一条线段的结尾)。由于沟渠很细,你可以忽略掉它的宽度。

由于不同的肥料之间混合会发生化学反应,所以修建的沟渠与沟渠之间不能相交。

现在TT给Lele画了一些设计图,Lele请你判断一下设计图中的沟渠与沟渠之间是否有相交。

Input

本题目包含多组测试,请处理到文件结束(EOF)。
每组测试的第一行有一个正整数N(0

Output

对于每组测试,如果该测试管道与管道之间有相交的话,输出”Yes”,否则输出”No”。

Sample Input

2
2
0 0
1 1
2
0 1
1 0
2
2
0 0
1 1
2
1 0
2 1
2
3
0 0
1 1
2 1
2
2 0
3 0

Sample Output

Yes
No
No


思路:

逐个判断水管之间是否相交,判断两根水管是否相交就是要判断组成折线水管的个条线段与另一根水管的其他线段是否相交;
判断两条线段(向量)是否相交的方式:
两个向量的向量积,是一个垂直于两个向量的向量,如果ABxAC,得到的结果是垂直于ABC这个平面的一个向量,这是用右手系判断的,如果是ABxAC,就是右手拇指朝上,手掌从AB边旋转小于180度的角度转到AC,这个结果就是拇指的方向。
如果AB和CD相交,可以画个图看看,ABxAC和ADxAB的拇指方向是相同的,ACxAD和BDxBC的拇指方向也是相同的。
ABxAC=(b.x-a.x)* (c.y-a.y)-(b.y-a.y)*(c.x-a.x);
(ABxAC)*(ADxAB)>=0,就是说明这两个向量积的方向相同,也就是拇指方向相同,也就是两个线段相交的判断条件。
其他的过程就是依次枚举。


代码

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define MAX 100+5
typedef long long LL;
const double pi=3.141592653589793;
const int INF=1e9;
const double inf=1e20;
const double eps=1e-6;
const int mod=1000000007;
struct point{
    int x,y;
}p[35][105];
double circulation(point a,point b,point c){
    return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}
bool cross(point a,point b,point c,point d){
    if(max(a.x,b.x)>=min(c.x,d.x)&&
       max(c.x,d.x)>=min(a.x,b.x)&&
       max(a.y,b.y)>=min(c.y,d.y)&&
       max(c.y,d.y)>=min(a.y,b.y)&&
       circulation(a,b,c)*circulation(a,d,b)>=0&&
       circulation(a,c,d)*circulation(b,d,c)>=0) return true;
    return false;
}
int main(){
    int n,k[35];
    while(cin>>n){
        memset(k,0,sizeof(k));
        memset(p,0,sizeof(p));
        for(int i=0;i<n;i++){
            cin>>k[i];
            for(int j=0;j<k[i];j++) scanf("%d%d",&p[i][j].x,&p[i][j].y);
        }
        if(n==1){
            printf("No\n");
            continue;
        }
        int flag=0;
        for(int i=0;i<n-1;i++){
            for(int j=1;j<k[i];j++){
                for(int t=i+1;t<n;t++){
                    for(int h=1;h<k[t];h++){
                        if(cross(p[i][j-1],p[i][j],p[t][h-1],p[t][h])){
                            flag=1;
                            break;
                        }
                    }
                }
            }
        }
        if(flag) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Command line: -prefix /home/liuyh/workspace/qt5.14.2-arm -opensource -confirm-license -release -strip -shared -xplatform linux-arm-gnueabi-g++ -optimized-qmake -c++std c++11 --rpath=no -pch -skip qt3d -skip qtactiveqt -skip qtandroidextras -skip qtcanvas3d -skip qtconnectivity -skip qtdatavis3d -skip qtdoc -skip qtgamepad -skip qtlocation -skip qtmacextras -skip qtnetworkauth -skip qtpurchasing -skip qtremoteobjects -skip qtscript -skip qtscxml -skip qtsensors -skip qtspeech -skip qtsvg -skip qttools -skip qttranslations -skip qtwayland -skip qtwebengine -skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns -make libs -make examples -nomake tools -nomake tests -gui -widgets -dbus-runtime --glib=no --iconv=no --pcre=qt --zlib=qt -no-openssl --freetype=qt --harfbuzz=qt -no-opengl -linuxfb --xcb=no -tslib --libpng=qt --libjpeg=qt --sqlite=qt -plugin-sql-sqlite -I/opt/tslib/include -L/opt/tslib/lib -recheck-all executing config test machineTuple + arm-linux-gnueabi-g++ -dumpmachine > sh: 1: arm-linux-gnueabi-g++: not found test config.qtbase.tests.machineTuple FAILED executing config test verifyspec + cd /home/liuyh/workspace/QT5.14.2/qt-everywhere-src-5.14.2/config.tests/verifyspec && /home/liuyh/workspace/QT5.14.2/qt-everywhere-src-5.14.2/qtbase/bin/qmake "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" 'QMAKE_LIBDIR += /opt/tslib/lib' 'INCLUDEPATH += /opt/tslib/include' -early "CONFIG += cross_compile" /home/liuyh/workspace/QT5.14.2/qt-everywhere-src-5.14.2/qtbase/config.tests/verifyspec + cd /home/liuyh/workspace/QT5.14.2/qt-everywhere-src-5.14.2/config.tests/verifyspec && MAKEFLAGS= /usr/bin/make clean && MAKEFLAGS= /usr/bin/make > rm -f verifyspec.o > rm -f *~ core *.core > arm-linux-gnueabi-g++ -c -O2 -march=armv7-a -mtune=cortex-a7 -mfpu=neon -mfloat-abi=hard -O2 -march=armv7-a -mtune=cortex-a7 -mfpu=neon -mfloat-abi=hard -pipe -O2 -w -fPIC -I/home/liuyh/workspace/QT5.14.2/qt-everywhere-src-5.14.2/qtbase/config.tests/verifyspec -I. -I/opt/tslib/include -I/home/liuyh/workspace/QT5.14.2/qt-everywhere-src-5.14.2/qtbase/mkspecs/linux-arm-gnueabi-g++ -o verifyspec.o /home/liuyh/workspace/QT5.14.2/qt-everywhere-src-5.14.2/qtbase/config.tests/verifyspec/verifyspec.cpp > make:arm-linux-gnueabi-g++:命令未找到 > make: *** [Makefile:172:verifyspec.o] 错误 127
最新发布
06-09

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值