计算几何,暴力。

题目中有一句话:$The$ $mass$ $of$ $each$ $brick$ $is$ $equally$ $distributed$ $and$ $it$ $will$ $be$ $stable$ $if$ $it$ $is$ $placed$ $on$ $bases$ $or$ $stable$ $bricks$ $and$ $the$ $moment$ $of$ $it$ $can$ $be$ $zero$ $when$ $it$ $is$ $placed$.

核心原则:左右半段均有稳定的东西支撑,这条才算是稳定的。暴力扩展就可以了。需要用到判断线段不严格相交以及点到线段的最小距离。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c))
{
x = x * + c - '';
c = getchar();
}
} const double eps=1e-;
#define zero(x)(((x)>0?(x):(-x))<eps) struct point
{
double x,y;
point(double X,double Y)
{
x=X;
y=Y;
}
}; double xmult(point p1,point p2,point p0)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
} int dots_inline(point p1,point p2,point p3)
{
return zero(xmult(p1,p2,p3));
} int same_side(point p1,point p2,point l1,point l2)
{
return xmult(l1,p1,l2)*xmult(l1,p2,l2)>eps;
} int dot_online_in(point p,point l1,point l2)
{
return zero(xmult(p,l1,l2))&&(l1.x-p.x)*(l2.x-p.x)<eps&&(l1.y-p.y)*(l2.y-p.y)<eps;
} int intersect_in(point u1,point u2,point v1,point v2)
{
if(!dots_inline(u1,u2,v1)||!dots_inline(u1,u2,v2)) return !same_side(u1,u2,v1,v2)&&!same_side(v1,v2,u1,u2);
return dot_online_in(u1,v1,v2)||dot_online_in(u2,v1,v2)||dot_online_in(v1,u1,u2)||dot_online_in(v2,u1,u2);
} int T;
struct YUAN
{
double x,y,r;
} yuan[];
struct XIAN
{
double p1x,p1y,p2x,p2y;
} xian[];
int n,m; int f[]; double DIS(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} point intersection(point u1,point u2,point v1,point v2)
{
point ret=u1;
double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
ret.x+=(u2.x-u1.x)*t;
ret.y+=(u2.y-u1.y)*t;
return ret;
} point ptoseg(point p,point l1,point l2)
{
point t=p;
t.x+=l1.y-l2.y,t.y+=l2.x-l1.x;
if(xmult(l1,t,p)*xmult(l2,t,p)>eps)
return DIS(p,l1)<DIS(p,l2)?l1:l2;
return intersection(p,t,l1,l2);
} int check(point A,point B,int b)
{
point F=ptoseg(point(yuan[b].x,yuan[b].y),A,B);
double dis=DIS(F,point(yuan[b].x,yuan[b].y));
if(dis<=yuan[b].r) return ;
return ;
} int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=; i<=n; i++) scanf("%lf%lf%lf",&yuan[i].x,&yuan[i].y,&yuan[i].r);
for(int i=; i<=m; i++) scanf("%lf%lf%lf%lf",&xian[i].p1x,&xian[i].p1y,&xian[i].p2x,&xian[i].p2y); memset(f,,sizeof f); int sum=;
while()
{
int Z=; for(int i=; i<=m; i++)
{
if(f[i]==) continue; point p1= point(xian[i].p1x,xian[i].p1y);
point p2= point(xian[i].p2x,xian[i].p2y);
point p3= point((p1.x+p2.x)/,(p1.y+p2.y)/); int f1=,f2=; for(int j=; j<=n; j++)
{
if(check(p1,p3,j)) f1=;
if(check(p2,p3,j)) f2=;
} for(int j=; j<=m; j++)
{
if(f[j]==) continue; if(intersect_in(p1,p3,point(xian[j].p1x,xian[j].p1y),point(xian[j].p2x,xian[j].p2y))) f1=;
if(intersect_in(p2,p3,point(xian[j].p1x,xian[j].p1y),point(xian[j].p2x,xian[j].p2y))) f2=;
} if(f1==&&f2==) f[i]=,Z++;
} if(Z==) break;
sum=sum+Z;
} if(sum!=m) printf("NO\n");
else printf("YES\n"); }
return ;
}

最新文章

  1. log4cplus 直接创建logger 对象
  2. 关于STM32-MDK中preprocessor symbols解释
  3. C# JIT &amp; AOT
  4. [转] Making GTFS query more convenient
  5. Qt和KDevelop在Linux下安装(qt-x11-commercial-src-4.3.1和kdevelop-3.5.0)
  6. Myeclipse 2013 professional 破解,下载
  7. Extjs 4.x 得到form CheckBox的值
  8. E - Phone List(字典序,string类型使用)
  9. php sprintf函数
  10. Docker MySQL备份
  11. C++: typedef与template的配合使用;
  12. 53.CSS---CSS水平垂直居中常见方法总结
  13. 使用vue-cli开发过程中如何把jQuery设置为全局
  14. 动手动脑(lesson2)
  15. [python网络编程]使用scapy修改源IP发送请求
  16. linux 时间相关
  17. [bug]不包含“AsNoTracking”的定义
  18. centos7 下安装 nginx-1.12.2
  19. 转:.NET面试题汇总(三)
  20. Docker 入门 第二部分: 容器

热门文章

  1. Android SearchView设置与用法的那点事儿
  2. Vue.js -- 过滤器
  3. dijkstra spfa prim kruskal 总结
  4. 【HDU】2222 Keywords Search
  5. python学习笔记(一)之为什么学习python
  6. JSX语法规范
  7. document.onclick在ios上不触发的解决方法与touchstart点击穿透处理
  8. python实战===用python识别图片中的中文
  9. python基础===输入必须为数字的检验的另一种方法
  10. nfs 文件共享 服务