poj 3246 Game
| Time Limit: 4000MS | Memory Limit: 65536K | |
| Total Submissions: 2707 | Accepted: 488 |
Description
Wintokk likes playing games on convex-hull. One day, Dragon wants to test him.
Dragon has drawn N points on a plane with no points in the same place. Dragon wants to know the smallest of the N convex-hulls formed by removing exactly one point from the N points.
But Wintokk is so stupid. Can you help him find the smallest area after removing a single point?
Input
The input contains several test cases.
Each test starts with an integer N(4 ≤ N < 105+1), the total number of points on the plane.
The next N lines, each contains two integers x and y, indicating the position of the point.
The input ends up with N=0.
Output
Output the smallest area with two digits after the decimal point.
Sample Input
4
1 0
0 0
0 1
1 1
0
Sample Output
0.50 翻译:给定平面上N个点,现在从中去掉一个点,去掉后使得剩余的点所构成的凸包的面积达到最小值,求这个最小值。
思路:直接穷举水过。
AC代码:
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<cmath>
#include<vector>
#include<bitset>
#include<string>
#include<queue>
#include<cstring>
#include<cstdio>
#include <climits>
using namespace std;
#define INF 0x3f3f3f3f
const int N_MAX = + ;
int N;
struct P {
int x, y,id;
P() {}
P(int x, int y) :x(x),y(y){}
P operator +(P p) {
return P(x + p.x, y + p.y);
}
P operator -(P p) {
return P(x - p.x, y - p.y);
}
P operator *(int d) {
return P(x*d, y*d);
}
int dot(P p) {
return x*p.x+y*p.y;
}
int det(P p) {
return x*p.y - y*p.x;
}
int norm() {
return x*x + y*y;
}
bool operator < (const P& b)const{
if (x != b.x)return x < b.x;
return y < b.y;
} };
P p[N_MAX],tmp[N_MAX];
struct Segment{
P p1, p2;
Segment(P p1,P p2):p1(p1),p2(p2) {}
};
typedef Segment Line; int GetArea(Segment l ,P p) {//计算直线l和点P所构成的平行四边形面积
return abs((l.p2 - l.p1).det(p - l.p1));
} vector<P>convex_hull(P*ps, int n) {
sort(ps, ps + n);
int k = ;
vector<P>qs( * n);
for (int i = ; i < n;i++) {
while (k > && (qs[k - ] - qs[k - ]).det(ps[i] - qs[k - ]) <= ) k--;
qs[k++] = ps[i];
}
for (int i = n - , t = k; i >= ;i--) {
while (k > t && (qs[k - ] - qs[k - ]).det(ps[i] - qs[k - ]) <= )k--;
qs[k++] = ps[i];
}
qs.resize(k-);
return qs;
}
typedef vector<P> Polygon; int GetArea_convexhull(Polygon ps) {//计算凸多边形面积
int sum = ; for (int i = ; i < ps.size();i++) {
P p1 = ps[i], p2 = ps[i-];
Segment l = Segment(p1, p2);
sum += GetArea(l, ps[]);
}
return sum;
} int main() {
while (scanf("%d",&N)&&N) {
for (int i = ; i < N;i++) {
scanf("%d%d",&p[i].x,&p[i].y);
p[i].id = i;
}
memcpy(tmp, p, sizeof(p));
int sum_max = INT_MAX;
Polygon ps = convex_hull(p, N);//要去除的点一定在凸包上
for (int i = ; i < ps.size();i++) {
memcpy(p, tmp, sizeof(tmp));
swap(p[ps[i].id], p[N - ]);//将第i个凸包上的点去除
int sum=GetArea_convexhull(convex_hull(p, N - ));
sum_max =min(sum_max, sum);
}
printf("%d%s\n",sum_max/,(sum_max&)?".50":".00");
}
return ;
}
poj 3246 Game的更多相关文章
- POJ 3246 Game(凸包)
[题目链接] http://poj.org/problem?id=3246 [题目大意] 给出一些点,请删去一个点,使得包围这些点用的线长最短 [题解] 去掉的点肯定是凸包上的点,所以枚举凸包上的点去 ...
- Poj 3246 Balanced Lineup(线段树基础)
依旧是线段树基础题 询问区间的最大值和最小值之差,只有询问,没有插入删除.继续理解基础线段树 #include <iostream> #include <algorithm> ...
- poj 3246 Balanced Lineup(线段树)
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 38942 Accepted: 18247 ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
随机推荐
- java基础—object类
一.Object类介绍
- c#自定义类型之间的转换(强制类型转换)
public class ResultModel { public string PlateNumber { get; set; } public int PlateColor { get; set; ...
- HTML5<figure>元素
HTML5<figure>元素是用来定义页面文档中独立的流内容(图像,图表,照片,代码块),figure内容与主内容有关,如果被删除,则不影响主文档流的产生. HTML5<figca ...
- Spring Boot 应用 快速发布到linux服务器的脚本代码示例
前提说明:spring boot 应用打包成jar包之后要部署到Linux服务器上面运行,我用的nohup java -jar 命令,但是代码更新之后重新部署的时候覆盖原来的项目,又要手动运行ps - ...
- 万门大学Python零基础10天进阶班视频教程
点击了解更多Python课程>>> 万门大学Python零基础10天进阶班视频教程 课程简介: 旨在通过两周的学习,让学生不仅能掌握python编程基础从而进行计算机程序的开发, 还 ...
- 如何用 CSS 和 D3 创作一个无尽的六边形空间
效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/NBvrWL 可交互视频 此视频是可 ...
- PHPCompatibility检测php版本语法兼容
直接上步骤: cd /datas/htdocs/ mkdir PHPCompatibility cd PHPCompatibility/ curl -s http://getcomposer.org/ ...
- 【php】命名空间的影响
命名空间对代码的影响 类(包含抽象类和traits) 接口 常量 函数
- Linux系统入门-Bash初识
目录 Linux系统入门-Bash初识 Bash Shell介绍 Bash Shell的作用 Bash的两种使用方式 命令提示符 shell的基础语法 shell的基本特性 命令补全 linux快捷键 ...
- cento命令之which、whereis、locate、find
[which] 查看可执行文件的位置 语法: [root@localhost ~]# which 可执行文件名称 例如: [root@localhost ~]# which passwd /usr/b ...