【LOJ】#6437. 「PKUSC2018」PKUSC
题解
我们把这个多边形三角形剖分了,和统计多边形面积一样
每个三角形有个点是原点,把原点所对应的角度算出来,记为theta
对于一个点,相当于半径为这个点到原点的一个圆,圆弧上的弧度为theta的一部分
相当于一条直线和这个小圆弧求交,直接算出有交的角度然后累加最后除2PI即可
可以拿余弦定理爆算(反着也不是你自己算
代码
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 1000005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,M;
db ans;
const db PI = acos(-1.0);
bool dcmp(db a,db b) {
return fabs(a - b) < eps;
}
struct Point {
db x,y;
Point(db _x = 0,db _y = 0) {
x = _x;y = _y;
}
friend Point operator + (const Point &a,const Point &b) {
return Point(a.x + b.x,a.y + b.y);
}
friend Point operator - (const Point &a,const Point &b) {
return Point(a.x - b.x,a.y - b.y);
}
friend Point operator * (const Point &a,const db &d) {
return Point(a.x * d,a.y * d);
}
friend Point operator / (const Point &a,const db &d) {
return Point(a.x / d,a.y / d);
}
friend db operator * (const Point &a,const Point &b) {
return a.x * b.y - a.y * b.x;
}
friend db dot(const Point &a,const Point &b) {
return a.x * b.x + a.y * b.y;
}
db norm() {
return sqrt(x * x + y * y);
}
}P[505],conv[505];
void Calc(Point a,Point b,db R) {
db f = 1;
if(a * b < 0) f = -1;
if(max(a.norm(),b.norm()) < R) return;
db theta = acos(dot(a,b) / (a.norm() * b.norm()));
db h = fabs(a * b) / (b - a).norm();
if(h >= R) {ans += f * theta;return;}
db beta = acos(dot(a - b,Point(-b.x,-b.y)) / ((a - b).norm() * b.norm()));
db alpha = acos(dot(b - a,Point(-a.x,-a.y)) / ((a - b).norm() * a.norm()));
db t = asin(h / R);
db s = 0.0;
if(t > alpha) s += (t - alpha);
if(t > beta) s += (t - beta);
s = min(s,theta);
ans += f * s;
}
bool check(Point a,Point b) {
Point c(1,0);
if(a.y < b.y) swap(a,b);
return c * a > 0 && b * c > 0 && b * a > 0;
}
void Init() {
read(N);read(M);
for(int i = 1 ; i <= N ; ++i) scanf("%lf%lf",&P[i].x,&P[i].y);
for(int i = 1 ; i <= M ; ++i) scanf("%lf%lf",&conv[i].x,&conv[i].y);
conv[M + 1] = conv[1];
}
void Solve() {
for(int i = 1 ; i <= M ; ++i) {
if(!dcmp(conv[i] * conv[i + 1],0)) {
for(int j = 1 ; j <= N ; ++j) {
if(!dcmp(P[j].norm(),0.0)) Calc(conv[i],conv[i + 1],P[j].norm());
}
}
}
for(int j = 1 ; j <= N ; ++j) {
if(dcmp(P[j].norm(),0)) {
bool flag = 1;int t = 0;
for(int i = 1 ; i <= M ; ++i) {
if(dcmp((conv[i] - P[j]) * (conv[i + 1] - P[j]),0.0)) {
if(dot((conv[i] - P[j]),(conv[i + 1] - P[j])) <= 0) {
flag = 0;break;
}
}
else {
if(dcmp(conv[i].y,0)) {
if(conv[i].x > 0) ++t;
}
else t += check(conv[i],conv[i + 1]);
}
}
if(flag && (t & 1)) ans += 2 * PI;
}
}
ans /= 2 * PI;
printf("%.5lf\n",ans);
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Init();
Solve();
}
【LOJ】#6437. 「PKUSC2018」PKUSC的更多相关文章
- 【LOJ】#6434. 「PKUSC2018」主斗地
题解 什么,我这题竟然快到了LOJ rk1???? 搜起来有点麻烦,不过感觉还是比斗地主好下手(至今没敢写斗地主 首先是暴力搜牌型,最多\(3^{16}\)(什么判解还要复杂度怂成一团)的样子?? 然 ...
- 【LOJ】#6436. 「PKUSC2018」神仙的游戏
题解 感觉智商为0啊QAQ 显然对于一个长度为\(len\)的border,每个点同余\(n - len\)的部分必然相等 那么我们求一个\(f[a]\)数组,如果存在\(s[x] = 0\)且\(s ...
- 【LOJ】#6435. 「PKUSC2018」星际穿越
题解 想出70的大众分之后就弃疗了,正解有点神仙 就是首先有个比较显然的结论,就是要么是一直往左走,要么是走一步右边,然后一直往左走 根据这个可以结合RMQ写个70分的暴力 我们就考虑,最优的话显然是 ...
- 【LOJ】#6433. 「PKUSC2018」最大前缀和
题解 神仙的状压啊QAQ 设一个\(f[S]\)表示数字的集合为\(S\)时\(sum[S]\)为前缀最大值的方案数 \(g[S]\)表示数字集合为\(S\)时所有前缀和都小于等于0的方案数 答案就是 ...
- 【LOJ】#6432. 「PKUSC2018」真实排名
题解 简单分析一下,如果这个选手成绩是0,直接输出\(\binom{n}{k}\) 如果这个选手的成绩没有被翻倍,那么找到大于等于它的数(除了它自己)有a个,翻倍后不大于它的数有b个,那么就从这\(a ...
- 【LOJ】#2210. 「HNOI2014」江南乐
LOJ#2210. 「HNOI2014」江南乐 感觉是要推sg函数 发现\(\lfloor \frac{N}{i}\rfloor\)只有\(O(\sqrt{N})\)种取值 考虑把这些取值都拿出来,能 ...
- 【LOJ】#3098. 「SNOI2019」纸牌
LOJ#3098. 「SNOI2019」纸牌 显然选三个以上的连续牌可以把他们拆分成三个三张相等的 于是可以压\((j,k)\)为有\(j\)个连续两个的,有\(k\)个连续一个的 如果当前有\(i\ ...
- 【LOJ】#3103. 「JSOI2019」节日庆典
LOJ#3103. 「JSOI2019」节日庆典 能当最小位置的值一定是一个最小后缀,而有用的最小后缀不超过\(\log n\)个 为什么不超过\(\log n\)个,看了一下zsy的博客.. 假如\ ...
- 【LOJ】#3102. 「JSOI2019」神经网络
LOJ#3102. 「JSOI2019」神经网络 首先我们容易发现就是把树拆成若干条链,然后要求这些链排在一个环上,同一棵树的链不相邻 把树拆成链可以用一个简单(但是需要复杂的分类讨论)的树背包实现 ...
随机推荐
- oracle 查出一个表中字段值出现次数大于2的所有记录
表web_order 列 name ,businesscode, a.account 周桥 18929609222 3754031157710000妙药 18929609233 3754031157 ...
- spring in action 学习笔记八:用@Primary 或者@Qualifier消除@Autowired引起的歧义现象
首先解释一下@Primary和@Qualifier这两个注解的意思:@Primary的意思是在众多相同的bean中,优先使用用@Primary注解的bean.而@Qualifier这个注解则指定某个b ...
- 个推数据统计产品(个数)iOS集成实践
最近业务方给我们部门提了新的需求,希望能一站式统计APP的几项重要数据.这次我们尝试使用的是个推(之前专门做消息推送的)旗下新推出的产品“个数·应用统计”,根据官方的说法,个推的数据统计产品通过专业的 ...
- 「Vue」路由
Vue-routerrouter-link active-class类型: string默认值: "router-link-active"设置 链接激活时使用的 CSS 类名.默认 ...
- python常用模块-调用系统命令模块(subprocess)
python常用模块-调用系统命令模块(subprocess) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. subproces基本上就是为了取代os.system和os.spaw ...
- [Spring] 学习Spring Boot之二:整合MyBatis并使用@Trasactional管理事务
一.配置及准备工作 1.在 Maven 的 pom 文件中新增以下依赖: <dependency> <groupId>mysql</groupId> <art ...
- spring中set注入的一些小细节错误
这是小白偶尔一直null指针的错误,调试了好久,原来是自己对spring注入的不够了解 我相信有很多跟我差不多的初学者会遇上,所以特地写出来,防止有人跟我一样.哈哈,也写上去,以防自己下次还犯这样的错 ...
- SHELL (1) —— shell脚本入门
摘自:Oldboy Linux运维——SHELL编程实战 SHELL Shell是一个命令解释器,解释执行用户输入的命令及程序等,用户每输入一条命令,Shell就解释执行一条.这种从键盘以输入命令,就 ...
- C#_界面程序_数码游戏
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 安装mongodb以及设置为windows服务 详细步骤
我的win7 32的,注意版本要正确! 一.下载mongodb压缩包:mongodb-win32-i386-2.6.9.zip() 二.在D盘新建文件夹mongodb,将压缩我的解压文件放进去(有一个 ...