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 ...
随机推荐
- 跟着百度学PHP[1]-if条件嵌套
权当自己的学习笔记.望大牛们切勿参考.如若发现错误,万望指出! 慕课任务 假设在发工资的时候,不仅判定性别,还要判定男性是否有房,没有房,可以发放住房补贴,对于女性,判定是否怀孕,怀孕还有怀孕补贴. ...
- PHPNG (next generation)
PHPNG (next generation) This page gives short information about development state of a new PHP branc ...
- (转载)【Android】ViewGroup全面分析
转载自:http://www.cnblogs.com/lqminn/archive/2013/01/23/2866543.html 一个Viewgroup基本的继承类格式如下: import andr ...
- java 异常处理 Throwable Error 和Exception
Java异常类层次结构图: 异常的英文单词是exception,字面翻译就是“意外.例外”的意思,也就是非正常情况.事实上,异常本质上是程序上的错误,包括程序逻辑错误和系统错误. 比如使用 ...
- 百度编辑器ueditor每次编辑后多一个空行的解决办法
用ueditor进行编辑文章时,每次编辑后文章前面都会多出一个空行. <script id="editor" type="text/plain" styl ...
- iOS中的NSTimer 和 Android 中的Timer
首先看iOS的, Scheduling Timers in Run Loops A timer object can be registered in only one run loop at a t ...
- 【JAVA、C++】LeetCode 016 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...
- 桐桐的贸易--WA
问题 A: 桐桐的贸易 时间限制: 1 Sec 内存限制: 64 MB提交: 15 解决: 2[提交][状态][讨论版] 题目描述 桐桐家在Allianceance城,好友ROBIN家在Horde ...
- codeforces A. Vasily the Bear and Triangle 解题报告
题目链接:http://codeforces.com/problemset/problem/336/A 好简单的一条数学题,是8月9日的.比赛中没有做出来,今天看,从pupil变成Newbie了,那个 ...
- Car的旅行路线(codevs 1041)
题目描述 Description 又到暑假了,住在城市A的Car想和朋友一起去城市B旅游.她知道每个城市都有四个飞机场,分别位于一个矩形的四个顶点上,同一个城市中两个机场之间有一条笔直的高速铁路,第I ...