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 计算几何 求二维凸包面积的更多相关文章

  1. 【计算几何】二维凸包——Graham's Scan法

    凸包 点集Q的凸包(convex hull)是指一个最小凸多边形,满足Q中的点或者在多边形边上或者在其内.右图中由红色线段表示的多边形就是点集Q={p0,p1,...p12}的凸包. 一组平面上的点, ...

  2. 使用Graham扫描法求二维凸包的一个程序

    #include <iostream> #include <cstring> #include <cstdlib> #include <cmath> # ...

  3. Andrew算法求二维凸包-学习笔记

    凸包的概念 首先,引入凸包的概念: (有点窄的时候...图片右边可能会被吞,拉开图片看就可以了) 大概长这个样子: 那么,给定一些散点,如何快速地求出凸包呢(用在凸包上的点来表示凸包) Andrew算 ...

  4. Educational Codeforces Round 41 967 E. Tufurama (CDQ分治 求 二维点数)

    Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama (CDQ分治 求 二维点数) time limit per test 2 ...

  5. 求二维数组最大子数组的和。郭林林&胡潇丹

    求二维数组子数组的最大值,开始思路不太清晰.先从最简单的开始. 以2*2的简单数组为例找规律, 假设最大数为a[0][0],则summax=a[0][0],比较a[0][0]+a[0][1].a[0] ...

  6. BOI2007 Mokia | cdq分治求二维点数模板

    题目链接:戳我 也没什么,其实主要就是为了存一个求二维坐标上矩形内点的个数的模板.为了之后咕咕咕地复习使用 不过需要注意的一点是,树状数组传x的时候可千万不要传0了!要不然会一直死循环的...qwqw ...

  7. Problem N: 求二维数组中的鞍点【数组】

    Problem N: 求二维数组中的鞍点[数组] Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 2764  Solved: 1728[Submit][S ...

  8. 计算几何 二维凸包问题 Andrew算法

    凸包:把给定点包围在内部的.面积最小的凸多边形. Andrew算法是Graham算法的变种,速度更快稳定性也更好. 首先把全部点排序.依照第一keywordx第二keywordy从小到大排序,删除反复 ...

  9. Luogu P2742 模板-二维凸包

    Luogu P2742 模板-二维凸包 之前写的实在是太蠢了.于是重新写了一个. 用 \(Graham\) 算法求凸包. 注意两个向量 \(a\times b>0\) 的意义是 \(b\) 在 ...

随机推荐

  1. TCP/IP详解学习笔记(3)-IP协议,ARP协议,RARP协议

    把这三个协议放到一起学习是因为这三个协议处于同一层,ARP协议用来找到目标主机的Ethernet网卡Mac地址,IP则承载要发送的消息.数据链路层可以从ARP得到数据的传送信息,而从IP得到要传输的数 ...

  2. border-radius 在安卓手机竟然不完美支持

    如果给图片加了width:50px;height:50px;border-radius:25px;-webkit-border-radius:25px;border:3px solid #fff; 在 ...

  3. linux中waitpid及wait的用法

    wait(等待子进程中断或结束) 表头文件      #include<sys/types.h>      #include<sys/wait.h> 定义函数 pid_t wa ...

  4. oracle返回多结果集

    kavy 原文 oracle返回多结果集 Oracle存储过程: create or replace procedure P_Sel_TopCount2(in_top in number, out_c ...

  5. [转] ArcGIS engine中气泡标注的添加、修改

    小生 原文 ArcGIS engine中气泡标注的添加.修改! 你微微地笑着,不同我说什么话.而我觉得,为了这个,我已等待得久了.                                   ...

  6. 七中滤波方法测试matlab实现

    http://blog.163.com/xiaheng0804@126/blog/static/1205282120132129471816/ 创建两个混合信号,便于更好测试滤波器效果.同时用七中滤波 ...

  7. Spring 定时任务的实现<转>

    本人暂时用到的实现定时任务的方式有2种 一.注解方式实现,简单方便 1:在applicationContext.xml中加入下面的配置, 这是spring的组件扫描,保证含有定时任务的类,能被spri ...

  8. 关于Windows 7的64位系统不兼容某些控件的问题

    我的问题是vsflex7.ocx 不能在64位系统下运行,导致软件的一个涉及到这个控件的功能出错.如下: 解决的办法基本思路是把这个控件注册一下.然后就可以了.就是这个控件: 目录中没有自己下载个. ...

  9. ARM处理机模式--内部寄存器

    处理器模式 用户模式(user)简称usr 快速中断模式(FIQ)简称fiq 外部中断模式(IRQ)简称irq 特权模式(supervisor)简称sve 数据访问终止模式(abort)简称abt 未 ...

  10. hive UDAF

    java 程序 package com.ibeifeng.udaf; import org.apache.hadoop.hive.ql.exec.UDAF; import org.apache.had ...