惨啊…… 被卡常是一种什么感受&……

很明显的分治。

我们首先可以找到所有点中的最低点,然后对所有点进行一次极角排序,选取一个点使得他各侧飞弹和地堡一样多,并对两侧继续进行分治。

很容易证明这样做的正确性。

然而这样做是\(n^{2}log(n)\)。所以我们需要加些玄学的优化……比如通过增加每次分治的宽度,以减少排序的次数……

……总之就是水过啦QAQ

#include <bits/stdc++.h>
#define N 20010 const int H = ;
char s0[H] , * s1 = s0 , * s2 = s1;
#define I ( s1 == s2 &&( s2 = ( s1 = s0 ) + fread( s0 , 1 , H , stdin ) , s1 == s2 ) ? 32 : * s1++ )
inline int read()
{
register int x = , c, f = ;
while( isspace( c = I ) );
if (c == '-') f = ; else x = x * + c - ;
while(isdigit( c = I ) ) x = x * + c - ;
return (f? -x: x);
} using namespace std;
int n;
struct node
{
int x, y, t, i;
} L[N];
node O;
int ansi[N];
int ci[N]; int compc(int a, int b)
{
return ((L[a].x - O.x) * (L[b].y - O.y) - (L[b].x - O.x) * (L[a].y - O.y)) < ;
}
int comp(node a, node b)
{
return ((a.x - O.x) * (b.y - O.y) - (b.x - O.x) * (a.y - O.y)) < ;
}
void solve(int l, int r)
{
if (l > r) return;
for (int i = l + ; i <= r; ++ i)
if (L[ci[i]].y < L[ci[l]].y) swap(ci[i], ci[l]);
O = L[ci[l]];
sort(ci + l + , ci + r + , compc);
int np = l + ;
for (int i = l + , k = ; i < r; ++ i)
{
k += L[ci[i]].t;
if (k == )
{
solve(np, i);
np = i + ;
}
}
if (L[ci[l]].t > ) ansi[L[ci[l]].i] = L[ci[np]].i;
else ansi[L[ci[np]].i] = L[ci[l]].i;
solve(np + , r);
}
int compi(node a, node b)
{
if (a.t != b.t) return a.t > b.t;
else return a.i < b.i;
}
int checker()
{
sort(L + , L + n * + , compi);
for (int i = ; i <= n; ++ i)
for (int j = ; j <= n; ++ j)
if (i != j)
{
O = L[i];
int a = comp(L[ansi[i] + n], L[j]) ^ comp(L[ansi[i] + n], L[ansi[j] + n]);
O = L[j];
int b = comp(L[ansi[j] + n], L[i]) ^ comp(L[ansi[j] + n], L[ansi[i] + n]);
if (a && b)
return ;
}
return ;
}
int main()
{
//freopen("rak0.in", "r", stdin);
n = read();
for (int i = ; i <= * n; ++ i) ci[i] = i;
for (int i = ; i <= n; ++ i)
{
L[i].x = read(); L[i].y = read();
L[i].t = ; L[i].i = i;
}
for (int i = ; i <= n; ++ i)
{
L[i + n].x = read(); L[i + n].y = read();
L[i + n].t = -; L[i + n].i = i;
}
solve(, n * );
for (int i = ; i <= n; ++ i) printf("%d\n", ansi[i]);
//printf("%d", checker());
}

bzoj2928: [Poi1999]飞弹的更多相关文章

  1. BZOJ 2933([Poi1999]地图-区间Dp)

    2933: [Poi1999]地图 Time Limit: 1 Sec   Memory Limit: 128 MB Submit: 7   Solved: 7 [ Submit][ Status] ...

  2. 2929: [Poi1999]洞穴攀行

    2929: [Poi1999]洞穴攀行 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 41[Submit][Status][Di ...

  3. BZOJ 2929: [Poi1999]洞穴攀行

    2929: [Poi1999]洞穴攀行 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 351  Solved: 195[Submit][Status][ ...

  4. BZOJ2935: [Poi1999]原始生物(欧拉回路)

    2935: [Poi1999]原始生物 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 150  Solved: 71[Submit][Status][D ...

  5. bzoj 2929 [Poi1999]洞穴攀行 网络流

    2929: [Poi1999]洞穴攀行 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 499  Solved: 295[Submit][Status][ ...

  6. BZOJ2936 Codevs3634 POI1999 积水 【并查集】*

    BZOJ2936 Codevs3634 POI1999 积水 题目描述 有这样一块土地,它可以被划分成N×M个正方形小块,每块面积是一平方英寸,第i行第j列的小块可以表示成P(i,j).这块土地高低不 ...

  7. 【BZOJ2927】[Poi1999]多边形之战 博弈

    [BZOJ2927][Poi1999]多边形之战 Description 多边形之战是一个双人游戏.游戏在一个有n个顶点的凸多边形上进行,这个凸多边形的n-3条对角线将多边形分成n-2个三角形,这n- ...

  8. 【bzoj2935】[Poi1999]原始生物

    2935: [Poi1999]原始生物 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 145  Solved: 71[Submit][Status][D ...

  9. cogs 32. [POI1999] 位图

    32. [POI1999] 位图 ★   输入文件:bit.in   输出文件:bit.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述 ] 给定一个 n*m 的矩形位图, ...

随机推荐

  1. STL bind1st bind2nd详解

    STL bind1st bind2nd详解   先不要被吓到,其实这两个配接器很简单.首先,他们都在头文件<functional>中定义.其次,bind就是绑定的意思,而1st就代表fir ...

  2. [LeetCode] Binary Tree Maximum Path Sum 求二叉树的最大路径和

    Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. ...

  3. ImportError: cannot import name '_imagingtk'

    问题描述 使用tkinter画pillow生成的图片时,在tkinter中抛出此异常. 解决方案 pip install -I --no-cache-dir Pillow 更新pillow 重启解决一 ...

  4. 求n!最后一位非零数

    引子:求n!末尾0的个数 n!末尾的0来源只有2,5两个质数相乘.所以只需要考察n!中包含多少个2和多少个5.然后取其较小值即为所求.即ans=min(cnt(2),cnt(5)).而转念一想,cnt ...

  5. Elasticsearch索引自动套用模板

    公司ELK系统目前的设置是每月自动将日志信息记录至新的索引中,将日志数据按月分索引保存,在扩展的ELK架构中,利Logstash对接rabbitmq,获取日志消息,自动持久化至Elasticsearc ...

  6. 在 Linux 中查看时区

    1.date date +"%Z %z" 或者 date -R 2.timedatectl timedatectl|grep "Timezone" 可以使用 t ...

  7. Git bash下中文乱码问题

    Git bash下中文乱码--解决方案 解决办法1: 在git bash下,右键 出现下图,选择options: 选择"Text" 将Character set设置为 UTF-8 ...

  8. Linux在fstab中因配置错误导致服务器主机无法重启的问题应该如何解决

    fstab中配置错误导致系统无法启动的恢复方案 1制造错误的案例发生,在/etc/fstab中配置如下内容 结尾的倒数第一个为1表示进行磁盘检查,为0表示不进行磁盘检查,倒数第二个为0表示不备份,为1 ...

  9. Apache的dbutils的架构图

  10. [Android]学习笔记之布局

    5大布局,其中前3个是常用的,第四个绝对布局已经提示deprecated ![](http://images2015.cnblogs.com/blog/194303/201611/194303-201 ...