ZOJ 3495 Lego Bricks
计算几何,暴力。
题目中有一句话:$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 ;
}
ZOJ 3495 Lego Bricks的更多相关文章
- (转)LSTM NEURAL NETWORK FOR TIME SERIES PREDICTION
LSTM NEURAL NETWORK FOR TIME SERIES PREDICTION Wed 21st Dec 2016 Neural Networks these days are th ...
- New需谨慎
New is Glue When you’re working in a strongly typed language like C# or Visual Basic, instantiating ...
- (zhuan) LSTM Neural Network for Time Series Prediction
LSTM Neural Network for Time Series Prediction Wed 21st Dec 2016 Neural Networks these days are the ...
- Bookmarks_www2
Bookmarks Bookmarks alexis- (Alex Incogito) - Repositories · GitHub GitHub - aetcnc-Arduino_DeltaHMI ...
- Bookmarks www
Bookmarks alexis- (Alex Incogito) - Repositories · GitHub GitHub - aetcnc-Arduino_DeltaHMI_RS485 Ope ...
- 100 Most Influential Books According to Stack Overflow
Please read this blog post to see why this is here. This data was created on 02/13/2012 20:00:00 All ...
- [C3] Andrew Ng - Neural Networks and Deep Learning
About this Course If you want to break into cutting-edge AI, this course will help you do so. Deep l ...
- [C1] Andrew Ng - AI For Everyone
About this Course AI is not only for engineers. If you want your organization to become better at us ...
- zoj 1251 Box of Bricks
Box of Bricks Time Limit: 2 Seconds Memory Limit: 65536 KB Little Bob likes playing with his bo ...
随机推荐
- Win7 安装配置 nexus3.7.1
安装准备: nexus3.7.1 环境准备: maven.jdk 解压nexus目录结构为: E:\nexus-3.7.1-02 配置环境变量: 启动: nexus.exe /run
- java加载驱动
加载驱动方法 1.Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 2. DriverManager.r ...
- npm 淘宝镜像安装以及安装报错window_nt 6.1.7601 解决
http://www.cnblogs.com/ycxhandsome/p/6562980.html npm config set proxy null npm config set https-pro ...
- 51nod 1486 大大走格子——dp
有一个h行w列的棋盘,里面有一些格子是不能走的,现在要求从左上角走到右下角的方案数. Input 单组测试数据. 第一行有三个整数h, w, n(1 ≤ h, w ≤ 10^5, 1 ≤ n ≤ 20 ...
- 【BZOJ】1710: [Usaco2007 Open]Cheappal 廉价回文
[算法]区间DP [题解]回文问题的套路做法:区间DP. f[i][j]表示区间i~j回文的最小代价,则有f[i][j]=min{①②③}. ①f[i+1][j]+min(a[s[i]],b[s[i] ...
- POJ 2533 Longest Ordered Subsequence LIS O(n*log(n))
题目链接 最长上升子序列O(n*log(n))的做法,只能用于求长度不能求序列. #include <iostream> #include <algorithm> using ...
- TensorFlow 模型保存和导入、加载
在TensorFlow中,保存模型与加载模型所用到的是tf.train.Saver()这个类.我们一般的想法就是,保存模型之后,在另外的文件中重新将模型导入,我可以利用模型中的operation和va ...
- 项目记录 -- python调用回调函数
C源文件: static int get_callback(zpool_handle_t *zhp, void *data) { zprop_get_cbdata_t *cbp = (zprop_ge ...
- java封装示例代码
package com.imooc; public class Telphone { private float screen; private float cpu; private float me ...
- linux 服务简介
Linux服务(Linux services)对于每个应用Linux的用户来说都很重要.关闭不需要的服务,可以让Linux运行的更高效,但并不是所有的Linux服务都可以关闭.今天安装了一次CentO ...