题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4573

Problem Description
  Remember our childhood? A few naked children throw stones standing on the same position, the one throws farther win the game. Aha, of course, there are some naughty boys who care more about whether they can urinate father.
  You believe it or not, anyway, I believed. Nowadays, some of the children are smarter than we were, while others may be more naughty.
  A week ago, I saw several children throw stones. In fact, they are more clever than we were, since the game they played, apparently, is more complex than we did. Maybe you have different points of view, however, you’d better learn about the rules of the game before expressing your views. A group of children take turns to throw stones standing on the same position. After some child throw a stone, the children will draw a convex polyhedron with smallest volume together to enclose all the stones thrown by them. You may assume that the stone is so small as to be abstracted as a point in three-dimensional space. Naively, the children regard the space enclosed by the convex polyhedron as territory under their control. After a child throw his stone, the score he obtains equals the incremental of the volume of their territory.   Unfortunately, the first three child’s score will always be zero. At last, the child with the highest score will win the game, and known as the "King".
  I think you have accepted my opinion already, for the rules of their throwing stones game are really complicated. But, you also don’t need to be frustrated for it. Now, in order to show you are smarter, maybe you can write a program to help the children point out their "King".
 
Input
  Input consists of a number of cases. The data of each case appears on a number of input lines, the first of which contains an integer N. The following N lines contain three number (xi, yi, zi) indicating coordinates of the stone thrown by the i-th child. 
Note: 1 <= N <= 10^4, 1 <= i <= N, -10^4 <= xi , yi , zi <= 10^4.
 
Output
  For each test case, you should output two lines. The first line is "Case #K:", K means the number of the test case. The second line is "i v", i means index of the "King" and v means the score of the "King". If there are more than one "King", output the one throws stone earlier than others.
  Please round the result to 2 digits after decimal point if necessary.
 
题目大意:给一个三维空间点集依次加入N个点,形成一个三维凸包。问加入哪一个点的时候,凸包的体积增量最大,即前 i 个点组成的凸包体积减去前 i - 1个点组成的凸包体积最大。输出这个点,并输出这个增量。
思路:http://blog.csdn.net/catalyst1314/article/details/9017673
PS:我的代码框架几乎都是照着上面写的。但是怎么看内存都会超出限制,虽然不知道为什么实际上没有(我算错了?),虽说现场没有这种限制。然后不知为何说时间复杂度是O(n*sqrt(n)),我怎么觉得最坏情况下还是O(n^2)的……
 
代码(531MS):
 #include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL; const int MAXN = ;
const double EPS = 1e-; inline int sgn(double x) {
return (x > EPS) - (x < -EPS);
} struct Point {
double x, y, z;
Point() {}
Point(double x, double y, double z): x(x), y(y), z(z) {}
void read() {
scanf("%lf%lf%lf", &x, &y, &z);
}
Point operator - (const Point &rhs) const {
return Point(x - rhs.x, y - rhs.y, z - rhs.z);
}
double operator * (const Point &rhs) const {
return x * rhs.x + y * rhs.y + z * rhs.z;
}
};
double length(const Point &a) {
return sqrt(a * a);
}
Point cross(const Point &a, const Point &b) {
Point res;
res.x = a.y * b.z - a.z * b.y;
res.y = a.z * b.x - a.x * b.z;
res.z = a.x * b.y - a.y * b.x;
return res;
}
Point cross(const Point &o, const Point &a, const Point &b) {
return cross(a - o, b - o);
}
double volume(const Point &a, const Point &b, const Point &c, const Point &d) {
return cross(c - a , b - a) * (d - a) / ;
}
Point p[MAXN]; struct Face {
int a, b, c;
bool flag;
Face() {}
Face(int a, int b, int c, bool flag): a(a), b(b), c(c), flag(flag) {}
bool can_see(const Point &q) {
return sgn(volume(p[a], p[b], p[c], q)) > ;
}
};
Face fac[MAXN * ]; struct Convex {
double diff_vol;
int cnt, mat[MAXN][MAXN]; void init() {
cnt = ;
for(int i = ; i < ; ++i) {
Face newf = Face((i + ) % , (i + ) % , (i + ) % , true);
if(newf.can_see(p[i])) swap(newf.a, newf.c);
mat[newf.a][newf.b] = mat[newf.b][newf.c] = mat[newf.c][newf.a] = cnt;
fac[cnt++] = newf;
}
} void restore(int k, int a, int b) {
int f = mat[a][b];
if(fac[f].flag) {
if(fac[f].can_see(p[k])) dfs(k, f);
else {
mat[b][a] = mat[a][k] = mat[k][b] = cnt;
fac[cnt++] = Face(b, a, k, true);
}
}
} void dfs(int k, int f) {
diff_vol += volume(p[fac[f].a], p[fac[f].b], p[fac[f].c], p[k]);
fac[f].flag = false;
restore(k, fac[f].b, fac[f].a);
restore(k, fac[f].c, fac[f].b);
restore(k, fac[f].a, fac[f].c);
} double update(int k) {
diff_vol = ;
for(int i = ; i < cnt; ++i) {
if(!fac[i].flag || !fac[i].can_see(p[k])) continue;
dfs(k, i);
break;
}
return diff_vol;
} double vol() {
double res = ;
for(int i = ; i < cnt; ++i) if(fac[i].flag)
res -= volume(p[fac[i].a], p[fac[i].b], p[fac[i].c], Point(, , ));
return res;
}
} solver; int n, kase; void solve() {
int king = ;
double maxans = ;
for(int i = , tmp = ; i < n; ++i) {
if(tmp == ) {
tmp += sgn(length(p[] - p[i]));
if(tmp > ) swap(p[], p[i]);
} else if(tmp == ) {
tmp += sgn(length(cross(p[], p[], p[i])));
if(tmp > ) swap(p[], p[i]);
} else if(tmp == ) {
tmp += (sgn(volume(p[], p[], p[], p[i])) != );
if(tmp > ) {
swap(p[], p[i]);
solver.init();
for(int j = ; j <= i; ++j) solver.update(j);
king = i, maxans = solver.vol();
}
} else {
double v = solver.update(i);
if(sgn(v - maxans) > ) {
maxans = v;
king = i;
}
}
}
printf("%d %.2f\n", king + , maxans);
} int main() {
while(scanf("%d", &n) != EOF) {
for(int i = ; i < n; ++i) p[i].read();
printf("Case #%d:\n", ++kase);
solve();
}
}

HDU 4573 Throw the Stones(动态三维凸包)(2013 ACM-ICPC长沙赛区全国邀请赛)的更多相关文章

  1. HDU 4571 Travel in time ★(2013 ACM/ICPC长沙邀请赛)

    [题意]给定N个点,每个点有一个停留所需的时间Ci,和停留能够获得的满意度Si,有M条边,每条边代表着两个点走动所需的时间ti,现在问在规定的T时间内从指定的一点S到E能够获得的最大的满意度是多少?要 ...

  2. HDU 4568 Hunter(最短路径+DP)(2013 ACM-ICPC长沙赛区全国邀请赛)

    Problem Description One day, a hunter named James went to a mysterious area to find the treasures. J ...

  3. HDU 4747 Mex(线段树)(2013 ACM/ICPC Asia Regional Hangzhou Online)

    Problem Description Mex is a function on a set of integers, which is universally used for impartial ...

  4. HDU 4582 DFS spanning tree(DFS+贪心)(2013ACM-ICPC杭州赛区全国邀请赛)

    Problem Description Consider a Depth-First-Search(DFS) spanning tree T of a undirected connected gra ...

  5. HDU 4569 Special equations(枚举+数论)(2013 ACM-ICPC长沙赛区全国邀请赛)

    Problem Description Let f(x) = anxn +...+ a1x +a0, in which ai (0 <= i <= n) are all known int ...

  6. HDU 4571 Travel in time(最短路径+DP)(2013 ACM-ICPC长沙赛区全国邀请赛)

    Problem Description Bob gets tired of playing games, leaves Alice, and travels to Changsha alone. Yu ...

  7. HDU 4565 So Easy!(数学+矩阵快速幂)(2013 ACM-ICPC长沙赛区全国邀请赛)

    Problem Description A sequence Sn is defined as:Where a, b, n, m are positive integers.┌x┐is the cei ...

  8. HDU 5874 Friends and Enemies 【构造】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Friends and Enemies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  9. HDU 4063 Aircraft(计算几何)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4063 Description You are playing a flying game. In th ...

随机推荐

  1. (转)js一道比较考验的题目

    转载下别人曾经出过的一道面试题,此题是他出的一套前端面试题中的最后一题,用来考核面试者的JavaScript的综合能力,很可惜到目前为止的将近两年中,几乎没有人能够完全答对,并非多难只是因为大多面试者 ...

  2. 局部变量、结构体和main函数

    在函数中定义的变量称为自动局部变量.因为每次调用该函数时,它们都自动“创建”,并且它们的只对于函数来说是局部的,局部对象的变量都会默认为空.局部变量的值只能在定义该变量的函数中访问,不能从函数之外访问 ...

  3. 【Android测试】【随笔】与 “58同城” 测试开发交流

    ◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/5384698.html 初衷 一直都有一个这样的想法: 虽然 ...

  4. HTML知识点总结以及典型例子讲解

    一.HTML文本格式化标签(这些标签都不换行) eg: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&qu ...

  5. Java学习-030-JSON 之四 -- 判断 JSONObject 是否包含键值对

    前文对获取 JSON 数据封装方法,使之可通过类似于 cssSelector 的方法获取 JSON 数据,使获取数据变得简单.敬请参阅:模仿 cssSelector 封装读取 JSON 数据方法. 在 ...

  6. php猴子称王或者约瑟夫难题

    问题描述: 一群猴子排成一圈,按1,2,...,n依次编号.然后从第1只开始数,数到第m只,把它踢出圈,从它后面再开始数,再数到第m只,在把它踢出去...,如此不停的进行下去,直到最后只剩下一只猴子为 ...

  7. 表单设置line-height,在ff中的不垂直居中问题???

    在ff中有时候input中的line-height,是有bug存在的,设置了line-height,发现文字并不是垂直居中. 1.这是正常现象,不需要刻意调整样式 2.以后尽量使用button,来避免 ...

  8. axis2_1.6.2之构建web端和客户端 .

    参考资料: http://blog.csdn.net/apei830/article/details/5448897 axis2的官网 http://axis.apache.org/axis2/jav ...

  9. js工具类大全

    /********** 日期处理函数 *********/<script type="text/javascript" src="${springMacroRequ ...

  10. php 配置本地自定义域名

    一.设置host文件 二.设置httpd.conf # Virtual hosts Include conf/extra/httpd-vhosts.conf 三.设置httpd-vhosts.conf ...