POJ 1755 Triathlon [半平面交 线性规划]
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 6912 | Accepted: 1790 |
Description
The speed of each contestant in all three sections is known. The judge can choose the length of each section arbitrarily provided that no section has zero length. As a result sometimes she could choose their lengths in such a way that some particular contestant would win the competition.
Input
Output
Sample Input
9
10 2 6
10 7 3
5 6 7
3 2 7
6 2 6
3 5 7
8 4 6
10 4 2
1 8 7
Sample Output
Yes
Yes
Yes
No
No
No
Yes
No
Yes
Source
题意:
3800: Saber VS Lancer
Time Limit: 1 Sec Memory Limit: 64 MB
Submit: 69 Solved: 25
[Submit][Status][Discuss]
Description
Input
Output
if(sgn(f(C))!=sgn(f(D))&&sgn(f(C))!=0&&sgn(f(D))!=0) 因为交点在直线上是不行的 我也不知道为什么要这样瞎凑出来的
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
const int N=;
const double INF=1e9;
const double eps=1e-1;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
} inline int sgn(double x){
if(abs(x)<eps) return ;
else return x<?-:;
} struct Vector{
double x,y;
Vector(double a=,double b=):x(a),y(b){}
bool operator <(const Vector &a)const{
return sgn(x-a.x)<||(sgn(x-a.x)==&&sgn(y-a.y)<);
}
void print(){printf("%lf %lf\n",x,y);}
};
typedef Vector Point;
Vector operator +(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}
Vector operator -(Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}
Vector operator *(Vector a,double b){return Vector(a.x*b,a.y*b);}
Vector operator /(Vector a,double b){return Vector(a.x/b,a.y/b);}
bool operator ==(Vector a,Vector b){return sgn(a.x-b.x)==&&sgn(a.y-b.y)==;}
double Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
double Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
double Len(Vector a){return sqrt(Dot(a,a));}
Vector Normal(Vector a){
return Vector(-a.y,a.x);//counterClockwise
};
struct Line{
Point s,t;
Line(){}
Line(Point a,Point b):s(a),t(b){}
};
bool isLSI(Line l1,Line l2){
Vector v=l1.t-l1.s,u=l2.s-l1.s,w=l2.t-l1.s;
return sgn(Cross(v,u))!=sgn(Cross(v,w));
}
Point LI(Line a,Line b){
Vector v=a.s-b.s,v1=a.t-a.s,v2=b.t-b.s;
double t=Cross(v2,v)/Cross(v1,v2);
return a.s+v1*t;
} void iniPolygon(Point p[],int &n,double inf){
n=;
p[++n]=Point(,);
p[++n]=Point(,inf);
p[++n]=Point(inf,inf);
p[++n]=Point(inf,);
}
Point t[N];int tn;
double a,b,c;
double f(Point p){return a*p.x+b*p.y+c;}
Point abcLI(Line l){
double u=abs(f(l.s)),v=abs(f(l.t));
return Point(l.s.x*v+l.t.x*u,l.s.y*v+l.t.y*u)/(u+v);
}
void CutPolygon(Point p[],int &n){
tn=;
Point C,D;
p[]=p[n];p[n+]=p[];
for(int i=;i<=n;i++){
C=p[i],D=p[i%n+];
if(sgn(f(C))>=) t[++tn]=C;
if(sgn(f(C))!=sgn(f(D))&&sgn(f(C))!=&&sgn(f(D))!=) t[++tn]=abcLI(Line(C,D));
//else{
// if(sgn(f(p[i-1]))>0) t[++tn]=abcLI(Line(p[i-1],p[i]));
// if(sgn(f(p[i+1]))>0) t[++tn]=abcLI(Line(p[i],p[i+1]));
//}
}
n=tn;for(int i=;i<=n;i++) p[i]=t[i];
} double PolygonArea(Point p[],int n){
double s=;
for(int i=;i<n;i++) s+=Cross(p[i]-p[],p[i+]-p[]);
return abs(s/);
}
struct Saber{
double a,b,c;
}s[N];
int n,m;
Point q[N];
bool solve(int id){
iniPolygon(q,m,INF);
q[]=q[];q[]=q[];
for(int i=;i<=n;i++) if(i!=id){
a=(s[id].a-s[i].a)/(s[id].a*s[i].a);//ax+by+c>0
b=(s[id].b-s[i].b)/(s[id].b*s[i].b);
c=(s[id].c-s[i].c)/(s[id].c*s[i].c);
if(sgn(a)==&&sgn(b)==&&sgn(c)<=) return false;
CutPolygon(q,m);
}
return sgn(PolygonArea(q,m));
} int main(int argc, const char * argv[]){
n=read();
for(int i=;i<=n;i++) s[i].a=read(),s[i].b=read(),s[i].c=read();
for(int i=;i<=n;i++) puts(solve(i)?"Yes":"No");
}
POJ 1755 Triathlon [半平面交 线性规划]的更多相关文章
- POJ 1755 Triathlon(线性规划の半平面交)
Description Triathlon is an athletic contest consisting of three consecutive sections that should be ...
- POJ 1755 Triathlon (半平面交)
Triathlon Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4733 Accepted: 1166 Descrip ...
- POJ 1755 Triathlon
http://poj.org/problem?id=1755 题意:铁人三项,每个人有自己在每一段的速度,求有没有一种3条路线长度都不为0的设计使得某个人能严格获胜? 我们枚举每个人获胜,得到不等式组 ...
- poj 3335(半平面交)
链接:http://poj.org/problem?id=3335 //大牛们常说的测模板题 ------------------------------------------------- ...
- LA 2218 Triathlon(半平面交)
Triathlon [题目链接]Triathlon [题目类型]半平面交 &题解: 做了2道了,感觉好像套路,都是二分答案,判断半平面交是否为空. 还有刘汝佳的代码总是写const +& ...
- POJ 1755 Triathlon 半平面交
看的这里:http://blog.csdn.net/non_cease/article/details/7820361 题意:铁人三项比赛,给出n个人进行每一项的速度vi, ui, wi; 对每个人 ...
- LA2218 Triathlon /// 半平面交 oj22648
题目大意: 铁人三项分连续三段:游泳 自行车 赛跑 已知各选手在每个单项中的速度v[i],u[i],w[i] 设计每个单项的长度 可以让某个特定的选手获胜 判断哪些选手有可能获得冠军 输出n行 有可能 ...
- poj 1755 半平面交+不等式
Triathlon Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6461 Accepted: 1643 Descrip ...
- poj 1279 半平面交核面积
Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6668 Accepted: 2725 Descr ...
随机推荐
- MySQL的ibdata1文件占用过大
处理MySQL的ibdata1文件过大问题 本人遇到一次在安装zabbix监控的时候,yum安装的MySQL数据库,后面用了一段时间发现data目录下的ibdata1的空间特别大,反而我的zabbix ...
- 微信小程序模板消息详解
先放代码 wxml: <form name='pushMsgFm' report-submit bindsubmit='orderSign'> <view> 单号: 0< ...
- 【深度学习系列】CNN模型的可视化
前面几篇文章讲到了卷积神经网络CNN,但是对于它在每一层提取到的特征以及训练的过程可能还是不太明白,所以这节主要通过模型的可视化来神经网络在每一层中是如何训练的.我们知道,神经网络本身包含了一系列特征 ...
- linux日志查看命令
tail tail 命令用于显示文本文件的末尾几行, 对于监控文件日志特别有用 tail example.txt #显示文件 example.txt 的后十行内容: tail -n 20 exampl ...
- NSMutableArray 记住取不到时要进行强转
NSMutableArray 记住取不到时要进行强转
- SpringMVC运行原理
一.SpringMVC运行原理图 二.相关接口解释 DispatcherServlet接口: Spring提供的前端控制器,所有的请求都有经过它来统一分发.在DispatcherServlet将请 ...
- linux下建ftp用户,并限制用户访问路径[转]
目的是:在linux系统上建立ftp用户,并限制其通过ftp访问时,只能访问用户主目录:其主目录显示路径也是“/”,看不到上级目录. 例如,我要建立用户usertest,密码为usertest ...
- mybatis分页+springmvc+jsp+maven使用步骤
作者注:本文主要用于个人学习.复习.同时欢迎指导讨论 1,添加maven依赖<dependency> <groupId>com.github.miemiedev ...
- linkinFrame--测试项目添加git管理
OK,前面一篇博客,已经搭建好了项目的基础的结构.现在我们添加一个简单的servlet来测试下项目能不能跑,然后在讲项目添加到coding上用git管理. 1,我们编写一个servlet,编写一个js ...
- junit设计模式--命令者模式
命令模式的意图 将一个请求封装成一个对象,从而使你可以用不同的请求对客户进行参数化: 对请求排队或记录请求日志,以及支持可撤销的操作: 命令模式告诉我们可以为一个操作生成一个对象并给出它的一个执行方法 ...