Codeforces Gym 100286A. Aerodynamics 计算几何 求二维凸包面积
Problem A. Aerodynamics
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86821#problem/A
Description
Bill is working in a secret laboratory. He is developing missiles for national security projects. Bill is the head of the aerodynamics department. One surprising fact of aerodynamics is called Whitcomb area rule. An object flying at high-subsonic speeds develops local supersonic airflows and the resulting shock waves create the effect called wave drag. Wave drag does not depend on the exact form of the object, but rather on its cross-sectional profile.
Consider a coordinate system with OZ axis pointing in the direction of object’s motion. Denote the area of a section of the object by a plane z = z0 as S(z0). Cross-sectional profile of the object is a function S that maps z0 to S(z0). There is a perfect aerodynamic shape called Sears-Haack body. The closer cross-sectional profile of an object to the cross-sectional profile of Sears-Haack body, the less wave drag it introduces. That is an essence of Whitcomb area rule.
Bill’s department makes a lot of computer simulations to study missile’s aerodynamic properties before it is even built. To approximate missile’s cross-sectional profile one takes samples of S(z0) for integer arguments z0 from zmin to zmax.
Your task is to find the area S(z0) for each integer z0 from zmin to zmax, inclusive, given the description of the missile. The description of the missile is given to you as a set of points. The missile is the minimal convex solid containing all the given points. It is guaranteed that there are four points that do not belong to the same plane.
Input
The first line of the input file contains three integer numbers: n, zmin and zmax (4 ≤ n ≤ 100, 0 ≤ zmin ≤ zmax ≤ 100). The following n lines contain three integer numbers each: x, y, and z coordinates of the given points. All coordinates do not exceed 100 by their absolute values. No two points coincide. There are four points that do not belong to the same plane.
Output
For each integer z0 from zmin to zmax, inclusive, output one floating point number: the area S(z0). The area must be precise to at least 5 digits after decimal point.
Sample Input
9 0 5
0 0 5
-3 0 2
0 -1 2
3 0 2
0 1 2
2 2 0
2 -2 0
-2 -2 0
-2 2 0
Sample Output
16.00000
14.92000
10.08000
4.48000
1.12000
0.00000
HINT
题意
给你一个由n个点构成的三维凸包,让你输出从zmin到zmax的所有截面的面积
题解:
对于每一个截面,我们n^2暴力出在这个截面上的所有点,然后直接套版求这个凸包的面积就好了
代码:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 100010
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** struct node
{
double x,y,z;
};
bool cmp(node a,node b)
{
return a.z<b.z;
}
struct POINT
{
double x;
double y;
POINT(double a=, double b=) { x=a; y=b;} //constructor };
POINT operator - (POINT A,POINT B){return POINT(A.x-B.x,A.y-B.y);}
bool cmp1(POINT a,POINT b)
{
if(fabs(a.x-b.x)<eps)
return a.y<b.y;
return a.x<b.x;
}
node a[];
node c[];
int tot=;
POINT kiss[];
double Cross(POINT a,POINT b)
{
return a.x*b.y-a.y*b.x;
}
int CH(POINT* p,int n,POINT* ch)
{
sort(p,p+n,cmp1);
int m=;
for(int i=;i<n;i++)
{
while(m>&&Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=)m--;
ch[m++]=p[i];
}
int k=m;
for(int i=n-;i>=;i--)
{
while(m>k&&Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=)m--;
ch[m++]=p[i];
}
if(n>)m--;
return m;
}
double area_of_polygon(int vcount,POINT polygon[])
{
int i;
double s;
if(vcount<)
return ;
s=polygon[].y*(polygon[vcount-].x-polygon[].x);
for (i=;i<vcount;i++)
s+=polygon[i].y*(polygon[(i-)].x-polygon[(i+)%vcount].x);
return s/;
}
vector<node>Q1;
vector<node>Q2;
POINT ki[];
int main()
{
freopen("aerodynamics.in","r",stdin);
freopen("aerodynamics.out","w",stdout);
int n=read(),zmin=read(),zmax=read();
for(int i=;i<n;i++)
cin>>a[i].x>>a[i].y>>a[i].z;
sort(a,a+n,cmp);
int j=;
for(int i=zmin;i<=zmax;i++)
{
Q1.clear();
Q2.clear();
memset(kiss,,sizeof(kiss));
memset(ki,,sizeof(ki));
tot=;
double ii=i*1.0;
while((a[j].z-ii)<-eps&&j<n)
j++;
for(int k=;k<n;k++)
{
if(a[k].z<i)
Q1.push_back((node){a[k].x,a[k].y,a[k].z});
else if(a[k].z>i)
Q2.push_back((node){a[k].x,a[k].y,a[k].z});
else
kiss[tot].x=a[k].x,kiss[tot++].y=a[k].y;
}
for(int k=;k<Q1.size();k++)
{
for(int t=;t<Q2.size();t++)
{
kiss[tot].x=(Q2[t].x-Q1[k].x)*(ii-Q1[k].z)/(Q2[t].z-Q1[k].z)+Q1[k].x;
kiss[tot++].y=(Q2[t].y-Q1[k].y)*(ii-a[k].z)/(Q2[t].z-Q1[k].z)+Q1[k].y;
}
} /*
if(i==4)
{
cout<<"--------------------------"<<endl;
for(int kk=0;kk<j;kk++)
cout<<a[kk].x<<" "<<a[kk].y<<" "<<a[kk].z<<endl;
cout<<"--------------------------"<<endl;
for(int kk=j;kk<n;kk++)
cout<<a[kk].x<<" "<<a[kk].y<<" "<<a[kk].z<<endl;
cout<<"--------------------------"<<endl;
for(int kk=0;kk<tot;kk++)
cout<<kiss[kk].x<<" "<<kiss[kk].y<<endl;
cout<<"--------------------------"<<endl;
}
*/
int ttt=CH(kiss,tot,ki);
printf("%.5lf\n",area_of_polygon(ttt,ki));
}
}
Codeforces Gym 100286A. Aerodynamics 计算几何 求二维凸包面积的更多相关文章
- 【计算几何】二维凸包——Graham's Scan法
凸包 点集Q的凸包(convex hull)是指一个最小凸多边形,满足Q中的点或者在多边形边上或者在其内.右图中由红色线段表示的多边形就是点集Q={p0,p1,...p12}的凸包. 一组平面上的点, ...
- 使用Graham扫描法求二维凸包的一个程序
#include <iostream> #include <cstring> #include <cstdlib> #include <cmath> # ...
- Andrew算法求二维凸包-学习笔记
凸包的概念 首先,引入凸包的概念: (有点窄的时候...图片右边可能会被吞,拉开图片看就可以了) 大概长这个样子: 那么,给定一些散点,如何快速地求出凸包呢(用在凸包上的点来表示凸包) Andrew算 ...
- Educational Codeforces Round 41 967 E. Tufurama (CDQ分治 求 二维点数)
Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama (CDQ分治 求 二维点数) time limit per test 2 ...
- 求二维数组最大子数组的和。郭林林&胡潇丹
求二维数组子数组的最大值,开始思路不太清晰.先从最简单的开始. 以2*2的简单数组为例找规律, 假设最大数为a[0][0],则summax=a[0][0],比较a[0][0]+a[0][1].a[0] ...
- BOI2007 Mokia | cdq分治求二维点数模板
题目链接:戳我 也没什么,其实主要就是为了存一个求二维坐标上矩形内点的个数的模板.为了之后咕咕咕地复习使用 不过需要注意的一点是,树状数组传x的时候可千万不要传0了!要不然会一直死循环的...qwqw ...
- Problem N: 求二维数组中的鞍点【数组】
Problem N: 求二维数组中的鞍点[数组] Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2764 Solved: 1728[Submit][S ...
- 计算几何 二维凸包问题 Andrew算法
凸包:把给定点包围在内部的.面积最小的凸多边形. Andrew算法是Graham算法的变种,速度更快稳定性也更好. 首先把全部点排序.依照第一keywordx第二keywordy从小到大排序,删除反复 ...
- Luogu P2742 模板-二维凸包
Luogu P2742 模板-二维凸包 之前写的实在是太蠢了.于是重新写了一个. 用 \(Graham\) 算法求凸包. 注意两个向量 \(a\times b>0\) 的意义是 \(b\) 在 ...
随机推荐
- 只用css实现“每列四行,加载完一列后数据自动填充到下一列”的效果
只用css实现“每列四行,加载完一列后数据自动填充到下一列”的效果.这个题目用图表示如下: 如果将题目换成“只用css实现每行四列,加载完一行后数据自动填充到下一行”,那这个问题就简单多了,相信大家都 ...
- Jin Ge Jin Qu hao
题意: n首歌和一首经典歌已知其长度,一首歌开始唱必须唱完,现在已知剩余时间,求最多能唱歌的个数并保证唱歌时间总长最大 分析: 留最后一个时间唱经典,然后对剩下的时间用背包求出最大个数,并求出总长最大 ...
- IOS Swizzle(hook)
/////////////////////////////////////////////////////////////////////////////////////////////////// ...
- 【剑指offer 面试题17】合并两个排序的链表
思路: 比较两个链表端点值的大小,通过递归的方式排列. #include <iostream> using namespace std; struct ListNode { int val ...
- linux 配置 Samba 服务器实现文件共享
1. 下载samba yum install samba 2. 启动samba 服务 service smb start 3.配置samba 打开/etc/samba/smb.conf 写入一下内容 ...
- andriod的简单用法2
1.在Activity中使用menu //创建菜单项 public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this ...
- qqmap 的一些操作
; var mapcontorl = "mapContainer"; var fullscreen = false; function qqMap(options) { var t ...
- 关于Noise and Error主题的一些小知识
(一)Noise会不会对VC bound产生影响? 此笔记源于台湾大学林轩田老师<机器学习基石><机器学习技法> 答案是不会. 当信号中加入了Noise,其实对我们之前学过的内 ...
- Hbase Basic Prerequisites
Table 2. Java HBase Version JDK 6 JDK 7 JDK 8 1.0 Not Supported yes Running with JD ...
- Hbase物理模型
Hbase 一种高可靠,面向列,可伸缩,事实读写的分布式数据库. 利用HDFS作为其文件存储系统. MapReduce处理数据. Zookeeper分布式协同服务. 数据结构 Row Key:行 ...