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 ...
随机推荐
- unity StreamingAssets路径
原地址:http://blog.csdn.net/nateyang/article/details/8493791 我们在读写例如XML和TXT文件的时候,在电脑上和手机上路径不一致,造成了很多麻烦, ...
- json串转对象
// 引入相应的包 //json-lib-2.2-jdk15.jar import net.sf.json.JSONArray;import net.sf.json.JSONObject; 1. // ...
- hdu4255筛素数+广搜
Mr. B has recently discovered the grid named "spiral grid".Construct the grid like the fol ...
- Python DBUtils
1 简介 DBUtils是一套Python数据库连接池包,并允许对非线程安全的数据库接口进行线程安全包装.DBUtils来自Webware for Python. DBUtils提供两种外部接口: P ...
- XPath常用定位节点元素语句总结
将一个XML或HTML文档转换成了DOM树结构后,如何才能定位到特定的节点?XPath实现了这样的功能,它通过DOM树中节点的路径和属性来导航,通过XPath路径表达式可以选择DOM树中的nodes( ...
- Java for LeetCode 203 Remove Linked List Elements
Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...
- codeforces 472C.Make It Nondeterministic 解题报告
题目链接:http://codeforces.com/problemset/problem/472/C 题目意思:给出 n 个 people(从第1行往下数,编号依次为1,2,...,n),每 个 p ...
- ubuntu 图形界面查看隐藏文件
在 Linux 下以 . 开头的文件或文件夹为隐藏文件,在图形界面(nautilus)下可用 CTRL + H 显示隐藏文件,终端下者可以用 ls -a 显示所有文件.
- 安装qmake与环境变量解析
转自:http://www.kuqin.com/qtdocument/qmake-manual-2.html 安装qmake 当Qt被连编的时候,默认情况下qmake也会被连编. 这一部分解释如何手工 ...
- 1.单件模式(Singleton Pattern)
意图:为了保证一个类仅有一个实例,并提供一个访问它的全局访问点. 1.简单实现(多线程有可能产生多个实例) public class CommonSigleton { /// <summary& ...