山东省ACM多校联盟省赛个人训练第六场 poj 3335 D Rotating Scoreboard
山东省ACM多校联盟省赛个人训练第六场 D Rotating Scoreboard
https://vjudge.net/problem/POJ-3335
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
This year, ACM/ICPC World finals will be held in a hall in form of a simple polygon. The coaches and spectators are seated along the edges of the polygon. We want to place a rotating scoreboard somewhere in the hall such that a spectator sitting anywhere on the boundary of the hall can view the scoreboard (i.e., his line of sight is not blocked by a wall). Note that if the line of sight of a spectator is tangent to the polygon boundary (either in a vertex or in an edge), he can still view the scoreboard. You may view spectator's seats as points along the boundary of the simple polygon, and consider the scoreboard as a point as well. Your program is given the corners of the hall (the vertices of the polygon), and must check if there is a location for the scoreboard (a point inside the polygon) such that the scoreboard can be viewed from any point on the edges of the polygon.
输入描述:
The first line contains three integers N, M, G(0 < N, M ≤ 500, 0 ≤ G ≤ 200).
Each of the following N lines contains M integers, representing the matrix. It is guaranteed that every integer in the matrix is in the range [-100, 100].
输出描述:
Output the maximum L in a single line.The first number in the input line, T is the number of test cases. Each test case is specified on a single line of input in the form n x
1
y
1
x
2
y
2
... xn ynwhere n (3 ≤ n ≤ 100) is the number of vertices in the polygon, and the pair of integers xi yi sequence specify the vertices of the polygon sorted in order.
示例1
输入
2
4 0 0 0 1 1 1 1 0
8 0 0 0 2 1 2 1 1 2 1 2 2 3 2 3 0
输出
YES
NO
分析
题目的意思就是在一个多边形的各个角上看整个区域,会不会有一个区域可以被所有的点都看到,或者反过来说可不可以找到一个点当做光源,使得这个光源发出的光各个点都能看到。
如果对平面几何有所了解的话,会立刻意识到这是多边形的核。
可惜我不是大神,我只是知道,这个东西是一个模板,而且我见过,这个模板叫啥,不知道,怎么用,不知道,用途是啥,不知道(否认三连)。
从网上超级容易直接就找到了教程和模板(之前做过类似的题目),直接使用AC掉本题一血并AK。
还是得多积累一些板子啊,不知道啥时候就用到了。
AC代码:
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long using namespace std;
const double pi = 3.1415926535;
/*
https://codeforces.com/contest/1106/problems
https://codeforces.com/contest/1106/submit
*/ //2.6 随机素数测试和大数分解(POJ 1811)
/* *************************************************
* Miller_Rabin 算法进行素数测试
* 速度快可以判断一个< 2^63 的数是不是素数
**************************************************//*
const int S = 8; //随机算法判定次数一般8∼10 就够了
// 计算ret = (a*b)%c a,b,c < 2^63
long long mult_mod(long long a,long long b,long long c) {
a %= c;
b %= c;
long long ret = 0;
long long tmp = a;
while(b) {
if(b & 1) {
ret += tmp;
if(ret > c)
ret -= c;//直接取模慢很多
}
tmp <<= 1;
if(tmp > c)
tmp -= c;
b >>= 1;
}
return ret;
}
// 计算ret = (a^n)%mod
long long pow_mod(long long a,long long n,long long mod) {
long long ret = 1;
long long temp = a%mod;
while(n) {
if(n & 1)
ret = mult_mod(ret,temp,mod);
temp = mult_mod(temp,temp,mod);
n >>= 1;
}
return ret;
}
// 通过a^(n-1)=1(mod n)来判断n 是不是素数
// n - 1 = x ∗ 2t 中间使用二次判断
// 是合数返回true, 不一定是合数返回false
bool check(long long a,long long n,long long x,long long t) {
long long ret = pow_mod(a,x,n);
long long last = ret;
for(int i = 1; i <= t; i++) {
ret = mult_mod(ret,ret,n);
if(ret == 1 && last != 1 && last != n-1)
return true;//合数
last = ret;
}
if(ret != 1)
return true;
else
return false;
}
//**************************************************
// Miller_Rabin 算法
// 是素数返回true,(可能是伪素数)
// 不是素数返回false
//**************************************************
bool Miller_Rabin(long long n) {
if( n < 2)
return false;
if( n == 2)
return true;
if( (n&1) == 0)
return false;//偶数
long long x = n - 1;
long long t = 0;
while( (x&1)==0 ) {
x >>= 1;
t++;
} srand(time(NULL));/* *************** */
/*
for(int i = 0; i < S; i++) {
long long a = rand()%(n-1) + 1;
if( check(a,n,x,t) )
return false;
}
return true;
}
*/ /*
LL gcd(LL a,LL b) {
if(a< b) {
ll t =a;
a =b;
b = t;
}
if(b == 0) {
return a;
} else {
return gcd(b,a%b);
}
}
*/#include<cstdio>
#include<cmath>
#include<algorithm>
#define MAXN 110
using namespace std;
const double eps = 1e-;
struct poi
{
double x,y;
poi(double x = ,double y = ) :x(x),y(y) {}
}pos[MAXN];
typedef poi vec;
vec operator +(vec A,vec B) {return vec(A.x + B.x, A.y + B.y);}
vec operator -(vec A,vec B) {return vec(A.x - B.x, A.y - B.y);}
vec operator *(vec A,double p) {return vec(A.x*p, A.y*p);}
int dcmp(double x)//别打成bool
{
if(fabs(x) < eps) return ;
else return x>?:-;
}
double cross(vec A,vec B) {return A.x*B.y - A.y*B.x;}
double dot(vec A,vec B) {return A.x*B.x + A.y*B.y;}
poi GetLineIntersection(poi A,vec v,poi B,vec w)
{
double t = cross(w,A - B) /cross(v,w);
return A + v*t;
}
bool OnSegment(poi p,poi A,poi B)
{
//return dcmp(cross(A-p,B-p)) == 0&&dcmp(dot(A-p,B-p)) < 0; 不晓得这个为什么被卡了
double mnx = min(A.x, B.x), mxx = max(A.x, B.x);
double mny = min(A.y, B.y), mxy = max(A.y, B.y);
return (mnx <= p.x + eps && p.x - eps <= mxx) && (mny <= p.y + eps && p.y - eps <= mxy);
}
struct polygon{
poi a[MAXN];
int sz;
};
polygon CutPolygon(polygon poly, poi A, poi B)
{
int m = ,n = poly.sz;
polygon newpoly;
for(int i = ; i < n; i++)
{
poi C = poly.a[i], D = poly.a[(i+)%n];
if(dcmp(cross(B - A, C - A)) <= ) newpoly.a[m++] = C;//f**kf**kf**kf**kf**k,题目的边按顺时针给出,所以是<=
if(dcmp(cross(B - A, C - D)) != ){
poi ip = GetLineIntersection(A, B-A, C, D-C);
if(OnSegment(ip, C, D)) newpoly.a[m++] = ip;
}
}
newpoly.sz = m;
return newpoly;
}
bool has_kernel(polygon poly)
{
polygon knl;
knl.a[] = poi(-1e6,-1e6),knl.a[] = poi(1e6,-1e6),knl.a[] = poi(1e6,1e6),knl.a[] = poi(-1e6,1e6);//边界过大也要WA
knl.sz = ;
for(int i = ; i < poly.sz; i++)
{
poi A = poly.a[i], B = poly.a[(i+)%poly.sz];
knl = CutPolygon(knl,A,B);
if(knl.sz == ) return false;
}
return true;
}
int main()
{
polygon poly;
int cas = ,n;
int T = ;
s(T )
while(T --){
s(n) for(int i = ; i < n; i++) scanf("%lf%lf",&poly.a[i].x,&poly.a[i].y);
poly.sz = n;
//printf("Floor #%d\n",++cas);
if(has_kernel(poly)) printf("YES\n");
else printf("NO\n"); }
}
山东省ACM多校联盟省赛个人训练第六场 poj 3335 D Rotating Scoreboard的更多相关文章
- “浪潮杯”第九届山东省ACM大学生程序设计竞赛重现赛 C-Cities
题目描述:There are n cities in Byteland, and the ith city has a value ai. The cost of building a bidirec ...
- 2019杭电暑假多校训练 第六场 Snowy Smile HDU - 6638
很多题解都是简单带过,所以打算自己写一篇,顺便也加深自己理解 前置知识:线段树.线段树维护最大字段和.二维坐标离散化 题解: 1.很容易想到我们需要枚举所有子矩阵来得到一个最大子矩阵,所以我们的任务是 ...
- 计蒜客 ACM竞赛高校联盟训练赛 第8场 煎牛排
水一水. https://nanti.jisuanke.com/t/24205 煎牛排 题目描述 又是一个难得的周六,是时候远离食堂和外卖出去大吃一顿了.圈内知名吃货AA正想着中午去吃汉堡炸鸡烤肉火锅 ...
- 记第五届山东省ACM程序设计比赛——遗憾并非遗憾
记第五届山东省ACM程序设计比赛 5月10日上午9点半左右,我们的队伍从学校出发,一个多小时后到达本次比赛的地点-哈尔滨工业大学. 报道,领材料,吃午饭,在哈工大的校园里逛了逛,去主楼的自习室歇息了一 ...
- ACM至大二省赛小结
大一进acm坑的,大一上就学了个c,下才学c++,不过 c 学完后学 c++ 感觉很简单,应该是大一下开学左右才开始刷题的,前面都在水???然后因为acm协会有各种月赛校赛什么的,班主任的提醒较多,所 ...
- 2017.12.10《“剑锋OI”普及组多校联盟系列赛(14)#Sooke#Kornal 的课余时间 》分析报告
报告内容如下 - - [导语] ------ 太晚了,时间也紧,一切尽量从简吧 PS:本文题目来自剑锋OI 所以废话也不多说,进入正题吧,代码直接跟在题目后边儿,主要分析在代码前,次要的就写在代码后面 ...
- 2018.12.21 浪在ACM 集训队第十次测试赛
浪在ACM 集训队第十次测试赛 A Diverse Substring B Vasya and Books C Birthday D LCM A 传送门 题解 B 传送门 题解: 这道题,就比较简单 ...
- 2018.12.14 浪在ACM 集训队第九次测试赛
浪在ACM 集训队第九次测试赛 B Battleship E Masha and two friends B 传送门 题意: 战船上有占地n*n的房间cells[][],只由当cells[i][j]= ...
- 2018.10.2浪在ACM 集训队第二次测试赛
2018.10.26 浪在ACM 集训队第二次测试赛 题目一览表 来源 考察知识点 A 1273 海港 NOIP 普及组 2016 差分数组+二分 B 1274 魔法阵 C 1267 金币 ...
随机推荐
- Kafka运维填坑(转)
前提: 只针对Kafka 0.9.0.1版本; 说是运维,其实偏重于问题解决; 大部分解决方案都是google而来, 我只是作了次搬运工; 有些问题的解决方案未必一定是通用的, 若应用到线上请慎重; ...
- EMF32名词解释
(EFM32)32位节能微控制器(Energy Friendly Microcontroller 32-bit) (Gecko)壁虎 (Starter Kit)入门套件 (STK)入门套件 (Debu ...
- Spring再接触 整合Hibernate
首先更改配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http ...
- 2、数据结构 proxy 代理 reflect 反射
增删改查 1.set (数组) 2.map (对象 key value) 数据结构横向对比 map.set('t',1) arr.push({t:1}) set.add({t:1}) arr.push ...
- react组件开发规范总结
开发react也有一段时间了,一开始的随手写,生命周期乱用,无状态组件的不熟悉.现在逐渐规范一下,从网上各个地方copy过来,整理出一份文档.可能不全,后续还得多提炼总结和完善. 一.组件内方法书写, ...
- kafka创建会话,报Error while executing topic command : Replication factor: 1 larger than available brokers: 0.
bin/kafka-topics.sh --create --zookeeper es1:2181 --replication-factor 1 --partitions 1 --topic top ...
- Maven工程控制台乱码问题(IDEA)
转自https://blog.csdn.net/love_live2/article/details/79311978 个人推荐使用文章中介绍的第三种方法,感觉挺好用的
- Go语言编程读书笔记:Go channel(1)
Channel是Go语言在语言级别提供的goroutine间的通信方式.我们可以用channel在两个或多个goroutine之间传递消息.channel是进程内的通信方式,因此通过channel传递 ...
- woff/woff2字体404找不到
每次控制台都报这个错,很纳闷,服务器上明明放了字体文件,怎么找不到呢 今天突然想起来,IIS的MIME类型要配置一下 之前部署网站,一个链接下载app的时候,IIS就不识别apk格式的文件,尽管服务器 ...
- PhoenixFD插件流体模拟——UI布局【Gird】详解
流体网格 本文主要讲解Grid折叠栏中的内容 主要内容 Overview 综述 Parameters 参数 General 普通参数 Example: Scene Scale Example: Gri ...