【2011 Greater New York Regional 】Problem I :The Golden Ceiling
一道比较简单但是繁琐的三维计算几何,找错误找的我好心酸,没想到就把一个变量给写错了 = =;
题目的意思是求平面切长方体的截面面积+正方体顶部所遮盖的面积;
找出所有的切点,然后二维凸包一下直接算面积即可!
发个代码纪念一下!
代码:
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define eps 1e-8
using namespace std; inline int sig(double x){return (x>eps)-(x<-eps);}
double w,l,hh,aa,bb,cc,dd;
int num1,num2;
struct point
{
double x,y,z;
point(double x=,double y=,double z=):x(x),y(y),z(z) { }
bool operator < (const point &t)const
{
if(sig(x-t.x)==)
{
return y<t.y;
}
else return x<t.x;
}
point operator+(const point&b)const{return point(x+b.x,y+b.y,z+b.z);}
point operator-(const point&b)const{return point(x-b.x,y-b.y,z-b.z);}
point operator*(double p){return point(x*p,y*p,z*p);}
point operator/(double p){return point(x/p,y/p,z/p);}
} ve[],tu[],vv[],tt[]; void intersection(point a,point b)
{
double t=(aa*a.x+bb*a.y+cc*a.z+dd)/(aa*(a.x-b.x)+bb*(a.y-b.y)+cc*(a.z-b.z));
if(t>=-eps&&t<=1.00000+eps)
{
point v=a+(b-a)*t;
ve[num1++]=v;
if(sig(v.z-hh)==)
tu[num2++]=v;
}
}
double lenth(point a){return sqrt(a.x*a.x+a.y*a.y+a.z*a.z);}
point cross(point a,point b){return point(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x);}
double area(point a,point b,point c){return lenth(cross(b-a,c-a))/2.0;}
double cross2(point a,point b){return a.x*b.y-a.y*b.x;}
bool check(point a)
{
if(sig(aa*a.x+bb*a.y+cc*a.z+dd)<)
return ;
return ;
} int convexhull(point *p,int n,point* ch)
{
sort(p,p+n);
int m=;
for(int i=;i<n;i++)
{
while(m>&&cross2(ch[m-]-ch[m-],p[i]-ch[m-])<=eps)m--;
ch[m++]=p[i];
}
int k=m;
for(int i=n-;i>=;i--)
{
while(m>k&&cross2(ch[m-]-ch[m-],p[i]-ch[m-])<=eps)m--;
ch[m++]=p[i];
}
if(n>)m--;
return m;
} int main()
{
int t,ca;
scanf("%d",&t);
while(t--)
{
memset(tu,,sizeof tu);
memset(ve,,sizeof ve);
memset(vv,,sizeof vv);
memset(tt,,sizeof tt);
scanf("%d",&ca);
printf("%d ",ca);
scanf("%lf%lf%lf%lf%lf%lf%lf",&l,&w,&hh,&aa,&bb,&cc,&dd);
num1=num2=;
dd=-dd;
point a(0.0,0.0,0.0);
point b(l,0.0,0.0);
point c(l,w,0.0);
point d(0.0,w,0.0);
point e(0.0,0.0,hh);
point f(l,0.0,hh);
point g(l,w,hh);
point h(0.0,w,hh);
intersection(a,b);
intersection(b,c);
intersection(c,d);
intersection(d,a);
intersection(a,e);
intersection(b,f);
intersection(c,g);
intersection(d,h);
intersection(e,f);
intersection(f,g);
intersection(g,h);
intersection(h,e);
if(check(e)==)tu[num2++]=e;
if(check(f)==)tu[num2++]=f;
if(check(g)==)tu[num2++]=g;
if(check(h)==)tu[num2++]=h;
int x=convexhull(ve,num1,vv);
int y=convexhull(tu,num2,tt);
double ans=;
for(int i=;i<x;i++)
ans+=area(vv[],vv[i-],vv[i]);
for(int i=;i<y;i++)
ans+=area(tt[],tt[i-],tt[i]);
printf("%.0lf\n",ceil(ans));
}
return ;
}
【2011 Greater New York Regional 】Problem I :The Golden Ceiling的更多相关文章
- 【2011 Greater New York Regional 】Problem G: Rancher's Gift
计算几何的题目,很简单: 自己随手敲了个,纪念下! #include<cstdio> #include<cmath> using namespace std; struct p ...
- 【2011 Greater New York Regional 】Problem H: Maximum in the Cycle of 1
也是一个数学题: 主要用到的是排列组合的知识,推推公式就行了,挺简单的: 唯一要注意的是A(0,0)=1: 在这个上面WA了几次,= = 代码: #include<stdio.h> #de ...
- 【2011 Greater New York Regional 】Problem B The Rascal Triangle
一个简单的规律题,每一列都是一个等差数列: 代码: #include<cstdio> #define ll long long using namespace std; int main( ...
- Poj(2407),Greater New York Regional 2015 (D)
题目链接:http://poj.org/problem?id=2407 Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- 【2011集训贾志鹏】Crash 的数字表格
题面 题目分析 (默认\(n<m\)) 题目要求\(\sum\limits_{i=1}^n\sum\limits_{j=1}^mlcm(i,j)\). 由\(lcm(i,j)=\frac{i\c ...
- [NOIp 1998 提高组]Probelm 2 连接多位数【2011百度实习生笔试题】
/*====================================================================== [NOIp 1998 提高组]Probelm 2 连接 ...
- 【贪心+中位数】【新生赛3 1007题】 Problem G (K)
Problem G Time Limit : 4000/2000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Sub ...
- 【2011图灵奖得主】我眼中的Judea Pearl
[2011图灵奖得主]我眼中的Judea Pearl 来源: 叶星遥的日志 2011年的图灵奖花落UCLA计算机系的Judea Pearl教授.图灵奖是计算领域的最高奖,由于近年来这个领域的兴盛也算是 ...
- 【BZOJ2998】Problem A(动态规划)
[BZOJ2998]Problem A(动态规划) 题面 BZOJ 题解 一个人的成绩范围可以确定为一个区间 这样就变成了 选择若干区间,不重合, 每个区间有个权值,求最大权值和 这样就可直接\(dp ...
随机推荐
- 转:FORM:客制化Form的菜单栏和右鍵菜單
Oracle EBS还允许客制化Form的菜单栏. 用户最多可以定义45个form-level的trigger,名称必须为SPECIALn, 其中SPECIAL1 to SPECIAL15属于Tool ...
- js 一个关于图片onload加载的事
前几天一个项目让我头疼了很久,一个关于图片加载时的loading效果,因为不是太懂js,所以在网上各种找资料,但还是不理想,无赖苦心研究,终于有了一点眉目了,虽然个中还有一些道理不懂,至少目的达到了; ...
- Meta http-equiv属性
http-equiv顾名思义,相当于http的文件头作用,它可以向浏览器传回一些有用的信息,以帮助正确和精确地显示网页内容,与之对应的属性值为content,content中的内容其实就是各个参数的变 ...
- 转载---SQL Server XML基础学习<3>之--FOR XML EXPLICIT
--使用 RAW 和 AUTO 模式不能很好地控制从查询结果生成的 XML 的形状.--但是,对于要从查询结果生成 XML,EXPLICIT 模式会提供非常好的灵活性. --必须以特定的方式编写 EX ...
- hpple 简单使用
最近项目使用到hpple,简单说一下使用方式,做做笔记 let responseData = response as! NSData let utf8Html = responseData.strin ...
- IOS之沙盒(Sandbox)机制
IOS中每个App应用程序都有一个单独封闭的文件夹,这个文件夹称为沙盒,并且苹果规定,任何App都无权访问其他App的沙盒 沙盒目录通过 FOUNDATION_EXPORT NSString *NSH ...
- 线程池读取List<T>实例
private static readonly Object ThisLock = new object(); private static readonly AutoResetEvent AutoR ...
- 2014年12月23日00:42:54——PS4
http://tieba.baidu.com/p/3415598015?see_lz=1&pn=1 http://tieba.baidu.com/p/3188981817 http://tie ...
- CentOS7设置IP地址
root权限下cd到/etc/sysconfig/network-scripts, vi ifcig-em1 TYPE=Ethernet BOOTPROTP=static NAME=em1 UUID= ...
- mini2440移植uboot-2008.10 (一)
今天是我申请此博客的第一天,从现在开始养成每次学完新东西,都要写博客进行总结的习惯!!!Come on! 首先就从这两天学的uboot开始吧,这两天学这个东西郁闷死了,不知道该怎么去学,尤其是到nan ...