学习了一下平面图剖分的姿势,orz cbh

每次只要随便选择一条边,然后不停尽量向左转就行

#include <bits/stdc++.h>
#define N 1300000
#define M 5000013
#define LL long long
#define pb push_back
using namespace std;
LL n, m, k;
struct point
{
LL x, y;
} S[N];
vector <LL> bi[N];
vector <LL> re[N], vis[N], s1[N], s2[N];
vector <LL> bt[N], ca[N], cb[N];
LL tot_are;
LL siz[N], sum1[N], sum2[N], tot[N];
LL nwc;
LL comp(LL a, LL b)
{
return atan2(S[a].y - S[nwc].y, S[a].x - S[nwc].x) > atan2(S[b].y - S[nwc].y, S[b].x - S[nwc].x);
}
LL getsiz(point a, point b, point c)
{
return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
} namespace addr
{
LL hs[M]; LL dt[M];
LL get(LL a, LL b)
{
return 1ll * a * + b;
}
LL & find(LL a, LL b)
{
LL p = get(a, b); LL q = p % M;
while (hs[q] && hs[q] != p) q = (q + ) % M;
hs[q] = p; return dt[q];
}
}
LL tvis[N], fa[N];
void dfs(LL t)
{
//cout << t << "\n"; tvis[t] = ;
sum1[t] = siz[t] * siz[t];
sum2[t] = siz[t] * ;
for (LL i = ; i < bt[t].size(); ++ i)
if (!tvis[bt[t][i]])
{
dfs(bt[t][i]); fa[bt[t][i]] = t;
sum1[t] += sum1[bt[t][i]];
sum2[t] += sum2[bt[t][i]];
s1[ca[t][i]][addr :: find(ca[t][i], cb[t][i])] = sum1[bt[t][i]];
s2[ca[t][i]][addr :: find(ca[t][i], cb[t][i])] = sum2[bt[t][i]];
s1[cb[t][i]][addr :: find(cb[t][i], ca[t][i])] = -sum1[bt[t][i]];
s2[cb[t][i]][addr :: find(cb[t][i], ca[t][i])] = -sum2[bt[t][i]];
}
}
LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL c = ;
int main()
{
//freopen("mine2.in", "r", stdin);
n = read(); m = read(); k = read();
for (LL i = ; i <= n; ++ i) S[i].x = read(), S[i].y = read();
for (LL i = ; i <= m; ++ i)
{
LL a, b;
a = read(); b = read();
bi[a].push_back(b);
bi[b].push_back(a);
}
for (LL i = ; i <= n; ++ i) re[i].resize(bi[i].size()), s1[i] = s2[i] = vis[i] = re[i];
for (LL i = ; i <= n; ++ i) nwc = i, sort(bi[i].begin(), bi[i].end(), comp);
for (LL i = ; i <= n; ++ i)
for (LL j = ; j < bi[i].size(); ++ j)
addr :: find(i, bi[i][j]) = j;
for (LL i = ; i <= n; ++ i)
for (LL j = ; j < bi[i].size(); ++ j)
re[i][j] = addr :: find(bi[i][j], i); for (LL i = ; i <= n; ++ i)
for (LL j = ; j < bi[i].size(); ++ j)
if (!vis[i][j])
{
tot_are ++;
for (LL k = i, p = j; !vis[k][p]; )
{
siz[tot_are] += getsiz(S[i], S[k], S[bi[k][p]]);
vis[k][p] = tot_are;
LL np = (re[k][p] + ) % bi[bi[k][p]].size();
k = bi[k][p];
p = np;
}
if (siz[tot_are] < ) c = tot_are;
}
for (LL i = ; i <= n; ++ i)
for (LL j = ; j < bi[i].size(); ++ j)
bt[vis[i][j]].push_back(vis[bi[i][j]][re[i][j]]),
ca[vis[i][j]].push_back(i),
cb[vis[i][j]].push_back(bi[i][j]);
dfs(c);
for (LL i = , last = ; i <= k; ++ i)
{
LL d, ns1 = , ns2 = ;
d = read(); d = (d + last) % n + ;
LL fs, ls, nw;
fs = read(); fs = (fs + last) % n + ; ls = fs;
for (LL j = ; j <= d; ++ j, ls = nw)
{
nw = read(); nw = (nw + last) % n + ;
ns1 += s1[ls][addr :: find(ls, nw)];
ns2 += s2[ls][addr :: find(ls, nw)];
}
ns1 += s1[ls][addr :: find(ls, fs)];
ns2 += s2[ls][addr :: find(ls, fs)];
LL g = __gcd(ns1, ns2);
cout << ns1 / g << " " << ns2 / g << "\n";
last = ns1 / g;
}
}

放在class里的东西还会爆栈QAQ,以后不敢用了

4541: [Hnoi2016]矿区的更多相关文章

  1. BZOJ 4541: [Hnoi2016]矿区 平面图转对偶图+DFS树

    4541: [Hnoi2016]矿区 Time Limit: 30 Sec  Memory Limit: 512 MBSubmit: 433  Solved: 182[Submit][Status][ ...

  2. ●BZOJ 4541 [Hnoi2016]矿区

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=4541 题解: 平面图的对偶图,dfs树 平面图的对偶图的求法: 把所有双向边拆为两条互为反向 ...

  3. bzoj 4541: [Hnoi2016]矿区【平面图转对偶图+生成树】

    首先平面图转对偶图,大概思路是每条边存正反,每个点存出边按极角排序,然后找每条边在它到达点的出边中极角排序的下一个,这样一定是这条边所属最小多边形的临边,然后根据next边找出所有多边形,用三角剖分计 ...

  4. [HNOI2016]矿区

    [HNOI2016]矿区 平面图转对偶图 方法: 1.分成正反两个单向边,每个边属于一个面 2.每个点按照极角序sort出边 3.枚举每一个边,这个边的nxt就是反边的前一个(这样找到的是面的边逆时针 ...

  5. 【LG3249】[HNOI2016]矿区

    [LG3249][HNOI2016]矿区 题面 洛谷 题解 先平面图转对偶图, 建好了对偶图之后随意拿出一个生成树,以无边界的范围为根. 无边界的范围很好求,用叉积算出有向面积时,算出来是负数的就是无 ...

  6. BZOJ4541 [Hnoi2016]矿区

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  7. 【bzoj4541】 Hnoi2016—矿区

    http://www.lydsy.com/JudgeOnline/problem.php?id=4541 (题目链接) 题意 给出一个平面图,若干询问,每次询问一个凸多边形内小多边形面积的平方和与面积 ...

  8. BZOJ4541 HNOI2016矿区(平面图转对偶图)

    考虑先将平面图转化为对偶图.具体地,将无向边拆成两条有向边.每次考虑找到包围一个区域的所有边.对当前考虑的边,找到该边的反向边在该边终点的出边集中,按极角序排序的后继,这条后继边也是包围该区域的边.这 ...

  9. [BZOJ4541][HNOI2016]矿区(平面图转对偶图)

    https://www.cnblogs.com/ljh2000-jump/p/6423399.html #include<cmath> #include<vector> #in ...

随机推荐

  1. Permutations II

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  2. [LeetCode] Remove Element 移除元素

    Given an array and a value, remove all instances of that value in place and return the new length. T ...

  3. 用EmEditor实现PDF转Word后的对齐排版

    Redraw = false//禁止重绘(类似于VBA中的: Application.screenupdating=FALSE),以提高运行效率 //去除所有空行和只由空白字符构成的行 documen ...

  4. MySQL练习题参考答案

    MySQL练习题参考答案 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: 思路: 获取所有有生物课程的人(学号,成绩) - 临时表 获取所有有物理课程的人(学号,成绩) - 临时表 根据[ ...

  5. PRINCE2风险模块

    我们前几个节学习了PRINCE2七大主题的商业论证.组织.质量和计划,今天我们开展对于风险模块的讲解. 风险:目的是识别.评估和控制不确定性,从而提高项目的成功率.PRINCE2对风险登记册进行了详细 ...

  6. cocos2dx3.0的CCCallFunc、CCCallFuncN

    来源: http://blog.csdn.net/crayondeng/article/details/18767407 二.在cocos2d-x中,还有一个地方是需要大量使用到回调函数的,这就是回调 ...

  7. [bzoj1670][Usaco2006 Oct]Building the Moat

    Description 为了防止口渴的食蚁兽进入他的农场,$Farmer John$决定在他的农场周围挖一条护城河.农场里一共有$N$股泉水,并且,护城河总是笔直地连接在河道上的相邻的两股泉水.护城河 ...

  8. Android源码——Logger日志系统

    Android的Logger日志系统是基于内核中的Logger日志驱动程序实现的. 日志保存在内核空间中 缓冲区保存日志   分类方法:日志的类型  +   日志的输出量   日志类型:   main ...

  9. Clean Old Kernels on CentOS

    1. Check Installed Kernels $ rpm -q kernel 2. Clean Old Kernels ## need Install yum-utils ## ## Pack ...

  10. centos6.5 卸载php

    1.删除php,删除之前需要查看php依赖包,使用 rpm -qa|grep php [root@localhost ~]# rpm -qa |grep phpphp55w-mysql-5.5.38- ...