loj6063 Shadow
题解:
显然凸多面体投下来一定是个凸多边形。
对于$30$分,直接投到$x-y$平面上即可。
对于$100$分,考虑搞出平面的一般式方程$ax+by+cz+d=0$。
给出平面上三个点$A,B,C$,那么求$(B-A)$^$(C-A)$,得到向量$(a,b,c)$,
然后随便带一个点把$d$求出来即可。
接下来把所有凸多边形顶点投影到平面上,接下来向$x-y$投影。
$x-y$平面上算出的面积与所求面积成比例。
比值即为$S(A,B,C)/S(A_0,B_0,C_0)$,计算三角形面积用海伦公式即可。
没卡我精度好爽。
代码:
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const double eps = 1e-;
double A,B,C,D;
struct SPoint
{
double x,y,z;
SPoint(){}
SPoint(double x,double y,double z):x(x),y(y),z(z){}
SPoint operator - (const SPoint&a)const{return SPoint(x-a.x,y-a.y,z-a.z);}
SPoint operator ^ (const SPoint&a)const{return SPoint(y*a.z-z*a.y,z*a.x-x*a.z,x*a.y-y*a.x);}
void read(){scanf("%lf%lf%lf",&x,&y,&z);}
}a,b,c,a0,b0,c0;
struct Point
{
double x,y;
Point(){}
Point(double x,double y):x(x),y(y){}
bool operator < (const Point&a)const{return x!=a.x?x+eps<a.x:y+eps<a.y;}
Point operator - (const Point&a)const{return Point(x-a.x,y-a.y);}
double operator ^ (const Point&a)const{return x*a.y-y*a.x;}
}p[],v1[],v2[];
void init()
{
a.read(),b.read(),c.read();
a0=a,b0=b,c0=c;
a0.z=b0.z=c0.z=;
SPoint tmp = (b-a)^(c-a);
A=tmp.x,B=tmp.y,C=tmp.z;
D=-1.0*(A*a.x+B*a.y+C*a.z);
}
int n,t1,t2;
double xx,yy,zz;
void mov(double&x,double&y,double&z)
{
double dx = xx-x,dy = yy-y,dz = zz-z;
double k = -1.0*(A*x+B*y+C*z+D)/(A*dx+B*dy+C*dz);
x = x+k*dx;
y = y+k*dy;
z = z+k*dz;
}
double S(double a,double b,double c)
{
double P = (a+b+c)/2.0;
return sqrt(P*(P-a)*(P-b)*(P-c));
}
double sq(double x){return x*x;}
double L(SPoint a,SPoint b)
{
return sqrt(sq(a.x-b.x)+sq(a.y-b.y)+sq(a.z-b.z));
}
double K()
{
return S(L(a,b),L(a,c),L(b,c))/S(L(a0,b0),L(a0,c0),L(b0,c0));
}
int main()
{
init();
scanf("%lf%lf%lf",&xx,&yy,&zz);
scanf("%d",&n);
double x,y,z;
for(int i=;i<=n;i++)
{
scanf("%lf%lf%lf",&x,&y,&z);
mov(x,y,z);
p[i]=Point(x,y);
}
sort(p+,p++n);
for(int i=;i<=n;i++)
{
while(t1>&&((v1[t1]-v1[t1-])^(p[i]-v1[t1]))>=)t1--;
v1[++t1]=p[i];
while(t2>&&((v2[t2]-v2[t2-])^(p[i]-v2[t2]))<=)t2--;
v2[++t2]=p[i];
}
double ans = ;
for(int i=;i<=t1;i++)ans-=((v1[i-]-v1[])^(v1[i]-v1[i-]));
for(int i=;i<=t2;i++)ans+=((v2[i-]-v2[])^(v2[i]-v2[i-]));
printf("%.2lf\n",K()*ans/2.0);
return ;
}
loj6063 Shadow的更多相关文章
- 【shadow dom入UI】web components思想如何应用于实际项目
回顾 经过昨天的优化处理([前端优化之拆分CSS]前端三剑客的分分合合),我们在UI一块做了几个关键动作: ① CSS入UI ② CSS作为组件的一个节点而存在,并且会被“格式化”,即选择器带id前缀 ...
- iOS 2D绘图 (Quartz2D)之阴影和渐变(shadow,Gradient)
原博地址:http://blog.csdn.net/hello_hwc/article/details/49507881 Shadow Shadow(阴影) 的目的是为了使UI更有立体感,如图 sha ...
- CSS3 笔记三(Shadow/Text/Web Fonts)
CSS3 Shadow Effects text-shadow box-shadow 1> text-shadow The text-shadow property adds shadow to ...
- Tutorial - Deferred Rendering Shadow Mapping 转
http://www.codinglabs.net/tutorial_opengl_deferred_rendering_shadow_mapping.aspx Tutorial - Deferred ...
- linux用户和组管理,/etc/passwd 、/etc/shadow和/etc/group 文件内容解释
与用户相关的系统配置文件主要有/etc/passwd 和/etc/shadow,其中/etc/shadow是用户资讯的加密文件,比如用户的密码口令的加密保存等: /etc/passwd 和/etc/s ...
- OpenGL阴影,Shadow Volumes(附源程序,使用 VCGlib )
实验平台:Win7,VS2010 先上结果截图: 本文是我前一篇博客:OpenGL阴影,Shadow Mapping(附源程序)的下篇,描述两个最常用的阴影技术中的第二个,Shadow Volu ...
- OpenGL阴影,Shadow Mapping(附源程序)
实验平台:Win7,VS2010 先上结果截图(文章最后下载程序,解压后直接运行BIN文件夹下的EXE程序): 本文描述图形学的两个最常用的阴影技术之一,Shadow Mapping方法(另一种是Sh ...
- /etc/passwd&/etc/shadow文件分析
/etc/passwd该目录存储的是操作系统用户信息,该文件为所有用户可见.给linux系统添加一个帐号:useradd -g mysql -d /home/test -m test(:新建一个用户t ...
- shadow Dom(shadowRoot) 访问
示例 gtx.shadowRoot.getElementById("translation") gtx为host对象 起因 抓去chorome谷歌翻译插架的内容.有信息的内容div ...
随机推荐
- Codeforces - 1117E - Crisp String - 进制 - 交互
https://codeforces.com/problemset/problem/1117/E 就用abc表示数字来给每个数编码,编完直接问出移动的结果,反构造就行了,比C和D还简单. #inclu ...
- vector理解一波~~~
Vector: 头文件: #include<vector> using namespacestd; 定义: vector<类型>q;//类同于 "类型 q[];&q ...
- P1211 街道赛跑
又是一下午的杠题,累啊~~~ 这道题第一问很简单,只需去掉一个点,判断能不能到达终点就行了: 第二问其实仔细想想也不难,就是判断去掉一个点后是否形成两个图:首先要知道是建立在第一问的基础上的:在加边的 ...
- Linux 命令行光标操作
转自: https://blog.csdn.net/leo_618/article/details/53003111 看一个真正的专家操作命令行绝对是一种很好的体验-光标在单词之间来回穿梭,命令行不同 ...
- 继续(3n+1)猜想 (25)
#include <algorithm> #include <iostream> using namespace std; int main(){ ] = { }; ], nu ...
- hdu 3172 Virtual Friends (字符串的并查集)
一开始一直wa,因为第一个数字t也是多组输入. 然后一直超时,因为我用的是C++里面的cin,所以非常耗时,几乎比scanf慢了10倍,但是加上了一个语句后: std::ios::sync_with_ ...
- 交表(Send a Table)
#include<stdio.h> #include<string.h> #define N 50010 int phi[N],n,sum[N]; void phi_table ...
- EXBSGS
http://210.33.19.103/problem/2183 参考:https://blog.csdn.net/frods/article/details/67639410(里面代码好像不太对) ...
- BestCoder Round #54 (div.2) 1003 Geometric Progression
题目传送门 题意:判断是否是等比数列 分析:高精度 + 条件:a[i] * a[i+2] == a[i+1] * a[i+1].特殊情况:0 0 0 0 0是Yes的,1 2 0 9 2是No的 代码 ...
- magento性能分析插件
两个好用的插件: http://connect20.magentocommerce.com/community/MagnetoDebughttp://connect20.magentocommerce ...