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 ...
随机推荐
- PAT (Basic Level) Practise (中文)- 1013. 数素数 (20)
http://www.patest.cn/contests/pat-b-practise/1013 令Pi表示第i个素数.现任给两个正整数M <= N <= 104,请输出PM到PN的所有 ...
- RenderBody,RenderPage和RenderSection
1. RenderBody 在Razor引擎中没有了“母版页”,取而代之的是叫做“布局”的页面(_Layout.cshtml)放在了共享视图文件夹中.在这个页面中,会看到<body>标签里 ...
- debian常用指令
查看软件xxx安装内容 dpkg -L xxx 查找软件 apt-cache search 正则表达式 查找文件属于哪个包 dpkg -S filename apt-file search filen ...
- 修改broadcom 4322无线网卡ID教程,不再显示第三方无线网卡
本帖最后由 hellokingabc 于 2016-1-11 03:07 编辑 黑苹果已经基本完美,但是无线网卡总是出现问题,经常断网,经过搜索,原因在于无线网卡在OSX系统下显示为第三方无线网卡,只 ...
- tensorflow目标检测API安装及测试
1.环境安装配置 1.1 安装tensorflow 安装tensorflow不再仔细说明,但是版本一定要是1.9 1.2 下载Tensorflow object detection API 下载地址 ...
- DELL PowerEdge R620安装Windows server(你想将windows安装在何处”找不到任何本地磁盘,“找不到驱动器”)已解决!
你可能碰到过DELL服务器上安装Windows server系列系统时无法识别或找不到硬盘的问题,对于DELL PowerEdge11-14代机器的,大家可以采用DELL的Lifecycle cont ...
- python 项目中包中__init__.py文件的作用
开发python项目时,我遇到了一个这样的现象,当我新建一个pythonpackage时,总会自动地生成一个空的__init__.py文件,因为是python新手,所以很不了解这个空文件的作用是什么, ...
- HDU - 5884 Sort (二分答案+贪心)
有n个数字,你需要把这n个数字合成一个数字,每次只能把k个数字合并成一个,花费为这k个数字的和. 给一个最大花费,问不超过这个最大花费的情况下,k的最小值. Sample Input 1 5 25 1 ...
- poj 3280 回文字符串问题 dp算法
题意:给一个字符串,构成回文(空也是回文) 其中增删都需要代价.问:代价最少? 思路:把字符串s变空 dp[i][j]表示变成回文的最小代价 for(i=m-1;i>=0;--i) ...
- 如何锁定Android系统CPU的频率
接触到了Android系统的Performance测试,所以有锁定CPU的需求: 由于要首先读取到此系统所支持的CPU频率,之后再所支持的频率中选取你想要的频率,之后进行锁定. 这个过程,手动也是可以 ...