Air【省选模拟赛】

立体几何中的贪心

阅读全文大概需要 1分钟
本文总阅读量
Posted by yjjr's blog on March 11, 2018

标签:计算几何

题目

这里写图片描述

分析

棱柱的体积正比于底面面积和三个支柱的高度和

把贡献的系数算出来,排序

贪心即可

code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
#define lson (x<<1)
#define rson (x<<1|1)
#define mid ((l+r)>>1)
#define pi acos(-1)
#define mp make_pair
#define pb push_back
#define pa pair<int,int>
#define fi first
#define se second
#define lowbit(x) ((x)&(-x))
using namespace std;
inline ll read(){
	ll f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline ll getgcd(ll x,ll y){return !x?y:getgcd(y%x,x);}
inline ll getlcm(ll x,ll y){return x/getgcd(x,y)*y;}
inline ll qpow(int x,int y,int p){
	ll re=1;
	while(y){
	   	if(y&1)re=(re*x)%p;
		y>>=1,x=(x*x)%p;
	}
	return re;
}
//**********head by yjjr**********
const int maxn=1e4+6;
struct point{double x,y;}p[maxn];
inline point operator + (point a,point b){return (point){a.x+b.x,a.y+b.y};}
inline point operator - (point a,point b){return (point){a.x-b.x,a.y-b.y};}
inline double operator * (point a,point b){return a.x*b.y-a.y*b.x;}
inline bool cmp(point a,point b){return atan2l(a.y,a.x)<atan2l(b.y,b.x);}
double val[maxn],h[maxn],ans;
int n,T;
int main()
{
	T=read();
	while(T--){
		n=read();mem(p,0);mem(h,0);mem(val,0);
		rep(i,1,n){
			int X=read(),Y=read();
			p[i].x=(double)X,p[i].y=(double)Y;
		}
		sort(p+1,p+1+n,cmp);
		p[++n]=p[1];p[0]=p[n-1];
		rep(i,1,n-1)val[0]+=p[i]*p[i+1]/6;
		rep(i,1,n-1)val[i]=(p[i-1]*p[i]+p[i]*p[i+1])/6;
		rep(i,0,n-1)h[i]=read();
		sort(val,val+n);sort(h,h+n);
		ans=0;
		rep(i,0,n-1)ans+=h[i]*val[i];
		printf("%.8lf\n",ans);
	}
	return 0;
}
本文可以转载,但必须附上原文链接,否则你会终生找不到妹子!!!欢迎关注我的CSDN: ahyjjr