[BZOJ4064/Cerc2012]The Dragon and the knights
Description
与当地鞋匠协会发生冲突的瓦维尔城堡的龙决定将它的狩猎场移出克拉科夫以减少敌对的邻居数量。现在他正在给和平而宁静的Bytes王国带来灾难与恐怖。
在Bytes王国有n条河流,每一条河流都是一条直线(你可以认为Bytes王国就像是欧几里得平面上被一些直线划分的一些区域),不存在三条河流共用同一个点,河流们将王国划分成了一些区域。
幸运的是,现在王国里有m个勇士。每个勇士都发誓要保护其所在的区域。王国也许就因此受到了长远持久的保护?
我们所知道的只有龙不会攻击存在至少一个勇士的区域。勇士们因为他们的勇气被人所熟知,然而他们的智力却低的可怕,他们不会离开自己所在的区域,只会保护所在的区域。
给出一个王国的地图,和勇士的坐标,请你计算是否所有的区域都被保护到了。
Input
第一行一个正整数T,表示有T组数据。
每组数据第一行两个正整数n和m,表示有n条河流,m个勇士,\(1\leqslant n\leqslant 100,1\leqslant m\leqslant50000\)。
接下来n行,第j行三个整数\(A_j, B_j, C_j\),表示第j个河流的直线方程是\(A_j * x + B_j * y + C_j = 0\),三个数字的绝对值都不超过10000。
接下来m行,第i行两个整数\(X_i, Y_i\),表示第i个勇士的坐标是\((X_i, Y_i)\),\(-10^9\leqslant X_i, Y_i\leqslant10^9\)。
你可以认为没有一个勇士站在河流上(如果他这么做他的铠甲会很快生锈呢)。两个勇士的坐标可能相同。不存在两条河流是重合的直线,不存在三条河流共用同一个点。
Output
对于每组数据输出一行,如果每个区域都可以被保护,输出"PROTECTED",否则输出"VULNERABLE"。(不含引号)
Sample Input
2
3 7
0 1 0
1 0 0
1 1 -3
1 1
5 -1
3 2
2 -2
-2 6
-1 -2
-8 4
1 1
0 1 0
0 1
Sample Output
PROTECTED
VULNERABLE
乱搞……
首先求出直线将平面分成多少个区域,对于一条直线,若它和之前\(x\)条直线相交,则平面会多划分出\(x+1\)个区域(注意初始区域数目为1)
然后我们只需要求出骑士们所在的区域个数是否等于分出的区域个数即可
如何判?
考虑将骑士与\((0,0)\)连线,不同的区域所交的直线编号必定不同,hash判重即可
如果有直线经过\((0,0)\)怎么办?我们在平面中随机找一个不被任何直线经过的点,与所有骑士连线即可
注意存在\(0x+0y=0\)的直线,不用特判,直接做即可(应该不论如何都会输出"VULNERABLE")
然后还要记得,直线判交是判断斜率是否相等,判断斜率使用交叉相乘,不要用\(A_1\)\(A_2\)&&\(B_1\)\(B_2\),x+y=0和2x=2y=1斜率相同……
/*program from Wolfycz*/
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define Fi first
#define Se second
#define MK make_pair
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<long double,long double> pdd;
inline char gc(){
static char buf[1000000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int frd(){
int x=0,f=1; char ch=gc();
for (;ch<'0'||ch>'9';ch=gc()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=gc()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline int read(){
int x=0,f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline void print(int x){
if (x<0) putchar('-'),x=-x;
if (x>9) print(x/10);
putchar(x%10+'0');
}
const int N=1e2,M=5e4,V=1e9;
const ld eps=1e-8;
const int limit=254753,Mod=379541;
struct S1{
ll A,B,C;
S1(){A=B=C=0;}
S1(ll _A,ll _B,ll _C){A=_A,B=_B,C=_C;}
void rd(){A=read(),B=read(),C=read();}
bool ck(int x,int y){return 1ll*A*x+1ll*B*y+C==0;}
}Line[N+10];
ui g[N+10],f[N+10];
struct S2{
int pre[M+10],now[Mod+10];
int stack[Mod+10],top,tot;
ui child[M+10];
void insert(int x,ui y){pre[++tot]=now[x],now[x]=tot,child[tot]=y;}
void insert(ui x){insert(stack[++top]=x%Mod,x);}
bool find(ui x){
int Now=x%Mod;
for (int p=now[Now];p;p=pre[p])
if (child[p]==x) return 1;
return 0;
}
void clear(){
for (int i=1;i<=top;i++) now[stack[i]]=0;
top=0;
}
}Hash;
bool ck(const S1 &x,const S1 &y){return 1ll*x.A*y.B==1ll*x.B*y.A;}
bool G(int l,int r,ld x){
if (l>r) swap(l,r);
if ((l<x||fabs(x-l)<=eps)&&(x<r||fabs(x-r)<=eps)) return 1;
return 0;
}
pdd get(const S1 &a,const S1 &b){
ld x=(1.0*a.B*b.C-1.0*b.B*a.C)/(1.0*b.B*a.A-1.0*a.B*b.A);
ld y=(1.0*a.A*b.C-1.0*b.A*a.C)/(1.0*b.A*a.B-1.0*a.A*b.B);
return MK(x,y);
}
int main(){
srand(time(0)); g[0]=1;
for (int i=1;i<=N;i++) g[i]=g[i-1]*limit;
for (int T=read();T;T--){
Hash.clear();
int n=read(),m=read(),cnt=1,num=0;
for (int i=1;i<=n;i++){
Line[i].rd(),cnt++;
for (int j=1;j<i;j++) if (!ck(Line[i],Line[j])) cnt++;
}
int Zx,Zy;
while (true){
Zx=1ll*rand()*rand()%V;
Zy=1ll*rand()*rand()%V;
bool flag=1;
for (int i=1;i<=n;i++){
if (Line[i].ck(Zx,Zy)){
flag=0;
break;
}
}
if (flag) break;
}
for (int i=1;i<=m;i++){
int x=read(),y=read(); ui z=0;
S1 tmp(y-Zy,Zx-x,1ll*x*Zy-1ll*Zx*y);
for (int j=1;j<=n;j++){
pdd res=get(tmp,Line[j]);
if (G(x,Zx,res.Fi)&&G(y,Zy,res.Se)) z+=g[j];
}
if (Hash.find(z)) continue;
num++,Hash.insert(z);
}
printf(cnt==num?"PROTECTED\n":"VULNERABLE\n");
}
return 0;
}
[BZOJ4064/Cerc2012]The Dragon and the knights的更多相关文章
- UVALive 6263 The Dragon and the knights --统计,直线分平面
题意:给n条直线,将一个平面分成很多个部分,再给m个骑士的坐标,在一个部分内只要有一个骑士即可保护该部分,问给出的m个骑士是不是保护了所有部分. 解法:计算每个骑士与每条直线的位置关系(上面还是下面) ...
- Central Europe Regional Contest 2012 Problem I: The Dragon and the Knights
一个简单的题: 感觉像计算几何,其实并用不到什么计算几何的知识: 方法: 首先对每条边判断一下,看他们能够把平面分成多少份: 然后用边来对点划分集合,首先初始化为一个集合: 最后如果点的集合等于平面的 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 要back的题目 先立一个flag
要back的题目 目标是全绿!back一题删一题! acmm7 1003 1004 acmm8 1003 1004 sysu20181013 Stat Origin Title Solved A Gy ...
- Uva11292--------------(The Dragon of Loowater)勇者斗恶龙 (排序后贪心)
---恢复内容开始--- 题目: Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major ...
- [ACM_水题] UVA 11292 Dragon of Loowater [勇士斗恶龙 双数组排序 贪心]
Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shor ...
- The Dragon of Loowater
The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into ...
- uva-----11292 The Dragon of Loowater
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- uva 11292 Dragon of Loowater (勇者斗恶龙)
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
随机推荐
- Chrome浏览器 js 关闭窗口失效解决方法
//获取元素ID var DelHtml = document.getElementById("imgdel"); //alert(DelHtml); //添加点击事件 DelHt ...
- sanic官方文档解析之ssl,debug mode模式和test(测试)
1,ssl 示例: 可选择的SSLContent from sanic import Sanic import ssl context = ssl.create_default_context(pur ...
- Spark SQL is a Spark module for structured data processing.
http://spark.apache.org/docs/latest/sql-programming-guide.html
- 探讨Ajax中有关readyState(状态值)和status(状态码)的问题
先看下面一段代码,然后给大家详细介绍,Ajax中有关readyState(状态值)和status(状态码)的问题,具体内容如下所示: var getXmlHttpRequest = function ...
- MYSQL进阶学习笔记十:MySQL慢查询!(视频序号:进阶_23-24)
知识点十一:MySQL 慢查询的应用(23) 一.慢查询定义 MySQL记录下查询超过指定时间的语句,我们将超过指定时间的SQL语句查询称为慢查询. 查看时间限制 show variables lik ...
- codeforces 445B. DZY Loves Chemistry 解题报告
题目链接:http://codeforces.com/problemset/problem/445/B 题目意思:给出 n 种chemicals,当中有 m 对可以发生反应.我们用danger来评估这 ...
- Oracle:varchar2、nvarchar2 字段类型的区别
一直对varchar2.nvarchar2 字段类型存储字符数不清楚,现测试如下: 创建TT测试表 测试脚本如下: insert into tt values('1111','1111'); --- ...
- 【转载】asp.net 后台弹出提示框
感觉这种最好用: public void showMessage(string str_Message) { ClientScript.RegisterStartupScript(this.GetTy ...
- 扩展KMP(占位)
先放代码. #include<cstdio> #include<iostream> #include<cstring> using namespace std; ; ...
- FTOUR2 - Free tour II
传送门 题目翻译的很清楚……似乎点分治的题题目描述都非常简洁. 还是那个操作,一条路径要么全部在一棵子树中,要么经过当前的重心,所以考虑点分治. 首先dfs求出重心的每一棵子树中,有i个黑点的最长路径 ...