码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 13 b

时间:2019-04-22 14:04:03      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:span   code   view   在线   sed   else   names   技术   lse   

给你三根线段判段是否组成了A

条件,两条线段交于端点并且夹角不大于90,第三条线段端点在两条线段上并且划分的大小满足 大:小<4:1

注释很全。(主要是我记不清楚了,,好像过了一个多星期了)

技术图片
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 typedef long long db;
 5 int inmid(db k1,db k2,db k3){return (k1-k3)*(k2-k3)<=0;}// k3 在 [k1,k2] 内
 6 struct point{
 7     ll x,y;
 8     point operator + (const point &k1) const{return (point){k1.x+x,k1.y+y};}
 9     point operator - (const point &k1) const{return (point){x-k1.x,y-k1.y};}
10     point operator * (db k1) const{return (point){x*k1,y*k1};}
11     point operator / (db k1) const{return (point){x/k1,y/k1};}
12     int operator == (const point &k1) const{return x==k1.x&&y==k1.y;}
13 };
14 int inmid(point k1,point k2,point k3){return inmid(k1.x,k2.x,k3.x)&&inmid(k1.y,k2.y,k3.y);}
15 ll cross(point k1,point k2){return k1.x*k2.y-k1.y*k2.x;}
16 ll dot(point k1,point k2){return k1.x*k2.x+k1.y*k2.y;}
17 struct line {
18     // p[0]->p[1]
19     point p[2];
20     line(point k1, point k2) {p[0] = k1;p[1] = k2;}
21     point &operator[](int k) { return p[k]; }
22 };
23 ll cross(line a,line b){return cross(a[1]-a[0],b[1]-b[0]);}
24 ll dot(line a,line b){return dot(a[1]-a[0],b[1]-b[0]);}
25 int t;point p[7];
26 vector<line> l;
27 bool check(ll x,ll y){if(x*5<y)return 0;if(x*5>y*4)return 0;return 1;}
28 bool slove(line a,line b,line c){
29     if(a[1]==b[1])swap(a[0],a[1]),swap(b[0],b[1]);
30     if(a[1]==b[0])swap(a[0],a[1]);
31     if(a[0]==b[1])swap(b[0],b[1]);
32     if(!(a[0]==b[0]))return 0;//判相交
33     if(cross(a,b)==0)return 0;//重合
34     if(dot(a,b)<0)return 0;//夹角
35     if(cross(a[1]-a[0],c[1]-a[0])==0&&cross(b[1]-b[0],c[0]-b[0])==0){}
36     else swap(c[0],c[1]);
37     if(!(cross(a[1]-a[0],c[1]-a[0])==0&&cross(b[1]-b[0],c[0]-b[0])==0))return 0;//共线
38     if(!inmid(a[0],a[1],c[1]))return 0;//在线段上
39     if(!inmid(b[0],b[1],c[0]))return 0;
40     //比例
41     if(!check(abs(a[0].x-c[1].x),abs(a[1].x-a[0].x)))return 0;
42     if(!check(abs(a[0].y-c[1].y),abs(a[1].y-a[0].y)))return 0;
43     if(!check(abs(b[0].x-c[0].x),abs(b[0].x-b[1].x)))return 0;
44     if(!check(abs(b[0].y-c[0].y),abs(b[0].y-b[1].y)))return 0;
45     return 1;
46 }
47 
48 int main(){
49     scanf("%d",&t);
50     while(t--){
51         l.clear();
52         for(int i=1;i<=6;i++)scanf("%lld%lld",&p[i].x,&p[i].y);
53         l.push_back({p[1],p[2]});l.push_back({p[3],p[4]});l.push_back({p[5],p[6]});
54         if(slove(l[0],l[1],l[2]))cout<<"YES"<<endl;
55         else if(slove(l[0],l[2],l[1]))cout<<"YES"<<endl;
56         else if(slove(l[1],l[2],l[0]))cout<<"YES"<<endl;
57         else cout<<"NO"<<endl;
58     }
59 }
60 /**
61 1
62 0 0 0 6
63 0 6 2 -4
64 1 1 0 1
65  */
View Code

 

codeforces 13 b

标签:span   code   view   在线   sed   else   names   技术   lse   

原文地址:https://www.cnblogs.com/MXang/p/10749603.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!