BZOJ1829 : [Usaco2010 Mar]starc星际争霸
设出$x,y,z$三个未知量分别表示三种单位的战斗力。
那么各种不等式都可以表示成$ax+by+cz\geq 0$的形式。
注意到$z>0$,那么两边都除以$z$得到$ax+by+c\geq 0$。
然后半平面交求出所有顶点后,对于每次询问将所有顶点带入求值即可。
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=400;
const double eps=1e-10;
struct P{
double x,y;
P(){x=y=0;}
P(double _x,double _y){x=_x,y=_y;}
P operator-(const P&a)const{return P(x-a.x,y-a.y);}
P operator+(const P&a)const{return P(x+a.x,y+a.y);}
P operator*(double a)const{return P(x*a,y*a);}
}p[N],a[N];
struct L{
P p,v;double a;
L(){}
L(P _p,P _v){p=_p,v=_v;}
bool operator<(const L&b)const{return a<b.a;}
void cal(){a=atan2(v.y,v.x);}
}line[N],q[N];
int n,m,cl,h,t;
inline double cross(const P&a,const P&b){return a.x*b.y-a.y*b.x;}
//新的半平面,在这条向量a->b的逆时针方向
inline void newL(const P&a,const P&b){line[++cl]=L(a,b-a);}
inline bool left(const P&p,const L&l){return cross(l.v,p-l.p)>0;}
inline P pos(const L&a,const L&b){
P x=a.p-b.p;double t=cross(b.v,x)/cross(a.v,b.v);
return a.p+a.v*t;
}
inline void halfplane(){
for(int i=1;i<=cl;i++)line[i].cal();
sort(line+1,line+cl+1);
h=t=1;
q[1]=line[1];
for(int i=2;i<=cl;i++){
while(h<t&&!left(p[t-1],line[i]))t--;
while(h<t&&!left(p[h],line[i]))h++;
if(fabs(cross(q[t].v,line[i].v))<eps)q[t]=left(q[t].p,line[i])?q[t]:line[i];else q[++t]=line[i];
if(h<t)p[t-1]=pos(q[t],q[t-1]);
}
while(h<t&&!left(p[t-1],q[h]))t--;
p[t]=pos(q[t],q[h]);
}
int main(){
newL(P(0,0),P(100,1));
newL(P(100,0),P(100,100));
newL(P(1,100),P(0,0));
newL(P(100,100),P(0,100));
newL(P(0.01,100),P(0.01,0));
newL(P(0,0.01),P(100,0.01));
scanf("%d%d",&n,&m);
while(n--){
char ch[5];int a,b,c,d,e,f;
scanf("%s",ch);
if(ch[0]=='J')scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
else scanf("%d%d%d%d%d%d",&d,&e,&f,&a,&b,&c);
a-=d,b-=e,c-=f;
if(!a&&!b)continue;
if(b){
P A=P(0,-1.0*c/b),B=P(100,(-100.0*a-c)/b),C=A;C.y+=1;
if(C.x*a+C.y*b+c>0)newL(A,B);else newL(B,A);
}else{
P A=P(-1.0*c/a,0),B=P(-1.0*c/a,100),C=A;C.x-=1;
if(C.x*a+C.y*b+c>0)newL(A,B);else newL(B,A);
}
}
halfplane();
while(m--){
int a,b,c,d,e,f;
scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
a-=d,b-=e,c-=f;
int flag=0;
for(int i=h;i<=t;i++){
double tmp=p[i].x*a+p[i].y*b+c;
if(tmp>-eps)flag|=1;
if(tmp<eps)flag|=2;
}
if(flag==1)puts("J");
else if(flag==2)puts("B");
else puts("U");
}
return 0;
}
BZOJ1829 : [Usaco2010 Mar]starc星际争霸的更多相关文章
- BZOJ 1829 [Usaco2010 Mar]starc星际争霸 ——半平面交
发现最终的结果只和$s1$,$s2$,$s3$之间的比例有关. 所以直接令$s3=1$ 然后就变成了两个变量,然后求一次半平面交. 对于每一个询问所属的直线,看看半平面在它的那一侧,或者相交就可以判断 ...
- 【BZOJ1827】[Usaco2010 Mar]gather 奶牛大集会 树形DP
[BZOJ][Usaco2010 Mar]gather 奶牛大集会 Description Bessie正在计划一年一度的奶牛大集会,来自全国各地的奶牛将来参加这一次集会.当然,她会选择最方便的地点来 ...
- 20. 星际争霸之php设计模式--适配器模式
题记==============================================================================本php设计模式专辑来源于博客(jymo ...
- 19. 星际争霸之php设计模式--迭代器模式
题记==============================================================================本php设计模式专辑来源于博客(jymo ...
- 18. 星际争霸之php设计模式--观察者模式
题记==============================================================================本php设计模式专辑来源于博客(jymo ...
- 17. 星际争霸之php设计模式--职责链模式
题记==============================================================================本php设计模式专辑来源于博客(jymo ...
- 16. 星际争霸之php设计模式--组合模式
题记==============================================================================本php设计模式专辑来源于博客(jymo ...
- 15. 星际争霸之php设计模式--策略模式
题记==============================================================================本php设计模式专辑来源于博客(jymo ...
- 14. 星际争霸之php设计模式--状态模式
题记==============================================================================本php设计模式专辑来源于博客(jymo ...
随机推荐
- sqlMapConfig.xml配置文件详解
sqlMapConfig.xml配置文件详解: Xml代码 Xml代码 <? xml version="1.0" encoding="UTF-8" ?& ...
- LocalResizeIMG前端HTML5本地压缩图片上传,兼容移动设备IOS,android
LocalResizeIMG前端HTML5本地压缩图片上传,兼容移动设备IOS,android jincon 发表于 2015-02-26 18:31:01 发表在: php开发 localresiz ...
- mysql sql维护常用命令
mysql修改表名,列名,列类型,添加表列,删除表列 alter table test rename test1; --修改表名 alter table test add column name v ...
- 全面解释StringBuilder、StringBuffer和String的关系
1. String 类 String的值是不可变的,这就导致每次对String的操作都会生成新的String对象,不仅效率低下,而且大量浪费有限的内存空间. String a = " ...
- HTML模仿桌面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Java for LeetCode 027 Remove Element
Given an array and a value, remove all instances of that value in place and return the new length. T ...
- 【JAVA、C++】LeetCode 017 Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- DP:Islands and Bridges(POJ 2288)
2015-09-21 造桥基建工程 题目大意,就是有n座岛和k座桥,要你找一条哈密顿圈(找完所有的岛,并且每个岛只经过一次),当经过一座岛就加上岛的价值,如果两岛联通,则加上两座岛的价值之积,如果三座 ...
- ORACLE查询某一字段重复的数据
第一种方法: select a.* from ASSET_MAINTAIN a inner join ASSET_MAINTAIN b on a.asset_id=b.asset_id and a. ...
- LightOJ 1315 - Game of Hyper Knights(博弈sg函数)
G - Game of Hyper Knights Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & ...