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 ...
随机推荐
- Spring学习日志之Spring Security配置
依赖引入 <dependency> <groupId>org.springframework.security</groupId> <artifactId&g ...
- MVC学习笔记(分享)
一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 <!--conf ...
- UI Automation
public Form1() { InitializeComponent(); this.textBox1.AccessibilityObject.Name = "t1"; thi ...
- jquery 和 mui 上拉加载
jquery: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <m ...
- 微信小程序使用字体图标的方法
一.先到阿里巴巴矢量图标库(http://iconfont.cn/),用微博帐号登录,搜索你想要的图标,然后添加入库 从项目里下载下来并解压,找到ttf格式文件 二.到这个平台https://tran ...
- Entity framework 中Where、First、Count等查询函数使用时要注意
在.Net开发中,Entity framework是微软ORM架构的最佳官方工具.我们可以使用Lambda表达式在Entity framework中DbSet<T>类上直接做查询(比如使用 ...
- Mac OS启动服务优化高级篇
一.Mac下的启动服务主要三个可配置的地方 1.系统偏好设置->帐户->登陆项 2./System/Library/StartupItems 和 /Library/StartupItems ...
- struts2 从一个action跳转到另一个action的struts.xml文件的配置
解释: 想要用<result>跳转到另一个action,原来的配置代码是: <action name="insertDept" class="strut ...
- jQuery --- 实现 checkbox 样式的单选框
早就想写点博客了 一直懒着动 最近发现一些写过的东西都不记得了,下决心把自己平时遇到的问题.得到的经验记录下来,希望能大家一点帮助 这是之前写的一个模态框 要求单选 但是 要求radio的默认样式 ...
- linux根据端口号查询来源程序
1.根据端口号查询进程 netstat -tunlp|grep port 2.根据进程查询来源程序 ps aux | grep pid 上图看出所属进程为2281 上图看出占用8083端口的程序为n ...