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

很明显的分治。

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

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

然而这样做是\(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. html之select标签

    循环select标签 <select name="group_id"> {% for row in group_list %} <option value={{r ...

  2. [LeetCode] Best Time to Buy and Sell Stock with Cooldown 买股票的最佳时间含冷冻期

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  3. [LeetCode] Range Sum Query - Immutable 区域和检索 - 不可变

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  4. IT培训行业揭秘(二)

    培训机构与高校之间是怎么"勾结"的? 每一个做院招的培训机构通常会有一个“院校关系”部门,这个部门就是专门为培训机构做疏通培训班与高校之间的关系的,通常这个部门都会拥有一张各大高校 ...

  5. JavaScript模板引擎artTemplate.js——template.helper()方法

    上一篇文章我们已经讲到了helper()方法,但是上面的例子只是一个参数的写法,如果是多个参数,写法就另有区别了. <div id="user_info"></d ...

  6. 混合使用UITabBarController和UINavigationController

    混合使用这两个控件的好处是我们可以在NavigationBar添加更多的东西,如标题,按钮等.让用户能够获得更多的信息. UITabBarController的属性ViewControllers接受以 ...

  7. IO流-----写到输出流

    输出流:---链接:http://blog.csdn.net/du_minchao/article/details/49045421 /** * 方法名:writeStream * 方法描述:写到输出 ...

  8. 安装cocoapods

    1. 看一下ruby的版本 ruby -v 2. 删除默认源 gem sources --remove https://rubygems.org/ 3. 添加淘宝源 gem sources -a ht ...

  9. IE下get传中文乱码的问题 -- 解决方案 (js)

    W3school 函数 JavaScript 全局对象 定义和用法 encodeURI() 函数可把字符串作为 URI 进行编码. 语法 encodeURI(URIstring) 参数 描述 URIs ...

  10. php stdclass转数组

    打印输出是这样 object(stdClass)[11] //object public 'xx' => string 'xxxxxx' (length=21)可用函数处理 get_object ...