嘻嘻嘻嘻,从读题到过题大概一个小时?

这套题题面太长了。。。就挑短的写。。

题意很简单。   给出平面上n个点,求一个面积最小的平行四边形覆盖这n个点。

显然要先求凸包。

然后枚举边就可以了。我一开始脑子抽了,只枚举了相邻的。。(今天下午四点多才吃上早饭很痛苦。感觉神智不清,昨晚补题补到3点。。。)

然后我们要 分别找出 离这两条边最远的 点吧,然后通过简单的平移操作求直线交点,再用叉积搞一下就阔以了。

虽然理论上 n^3不会t,但我还是t了。。。所以我们先预处理出来离每条边最远的点是哪一个。就阔以了。

记得特判一下没有凸包的情况,虽然不知道有没有这种数据。。。

 #include <bits/stdc++.h>
using namespace std;
typedef double db;
const db eps=1e-;
const db pi=acos(-);
int sign(db k){
if (k>eps) return ; else if (k<-eps) return -; return ;
}
int cmp(db k1,db k2){return sign(k1-k2);}
struct point{
db x,y;
point operator + (const point &k1) const{return (point){k1.x+x,k1.y+y};}
point operator - (const point &k1) const{return (point){x-k1.x,y-k1.y};}
point operator * (db k1) const{return (point){x*k1,y*k1};}
point operator / (db k1) const{return (point){x/k1,y/k1};}
db abs(){return sqrt(x*x+y*y);}
db dis(point k1){return ((*this)-k1).abs();}
point turn90(){ return point{-y,x};}
db getP()const { return sign(y)==||(sign(y)==&&sign(x)==-);}
point unit(){db w=abs(); return point{x/w,y/w};}
db abs2(){return x*x+y*y;}
bool operator < (const point k1) const{
int a=cmp(x,k1.x);
if (a==-) return ; else if (a==) return ; else return cmp(y,k1.y)==-;
}
};
db cross(point k1,point k2){ return k1.x*k2.y-k1.y*k2.x;}
db dot(point k1,point k2){ return k1.x*k2.x+k1.y*k2.y;}
db rad(point k1,point k2){ return atan2(cross(k1,k2),dot(k1,k2));}
int compareangle(point k1,point k2){
return k1.getP()<k2.getP()||(k1.getP()==k2.getP()&&sign(cross(k1,k2))>);
}
point proj(point k1,point k2,point q){ // q 到直线 k1,k2 的投影
point k=k2-k1; return k1+k*(dot(q-k1,k)/k.abs2());
}
point getLL(point k1,point k2,point k3,point k4){
db w1=cross(k1-k3,k4-k3),w2=cross(k4-k3,k2-k3);
return (k1*w2+k2*w1)/(w1+w2);
}
struct line{
point p[];
line(point k1,point k2){p[]=k1;p[]=k2;}
point &operator[](int k){ return p[k];}
int include(point k){ return sign(cross(p[]-p[],k-p[])>);}
point dir(){ return p[]-p[];}
line push(db eps){//向左手边平移eps
//const db eps=1e-6;
point delta=(p[]-p[]).turn90().unit()*eps;
return {p[]-delta,p[]-delta};
}
};
point getLL(line k1,line k2){
return getLL(k1[],k1[],k2[],k2[]);
}
int parallel(line k1,line k2){ return sign(cross(k1.dir(),k2.dir()))==;}
int sameDir(line k1,line k2){
return parallel(k1,k2)&&sign(dot(k1.dir(),k2.dir()))==;
}
int operator <(line k1,line k2){
if(sameDir(k1,k2))return k2.include(k1[]);
return compareangle(k1.dir(),k2.dir());
}
int checkpos(line k1,line k2,line k3){ return k3.include(getLL(k1,k2));}
vector<point> convexHull(vector<point>ps){
int n = ps.size();if(n<=)return ps;
sort(ps.begin(),ps.end());
vector<point> qs(n*);int k=;
for(int i=;i<n;qs[k++]=ps[i++])
while (k>&&cross(qs[k-]-qs[k-],ps[i]-qs[k-])<=)--k;
for(int i=n-,t=k;i>=;qs[k++]=ps[i--])
while (k>t&&cross(qs[k-]-qs[k-],ps[i]-qs[k-])<=)--k;
qs.resize(k-);
return qs;
}
int t,n;
vector<point> p;point s1,t1,s2,t2;
map<pair<int,int>,int> mp;
db check(int a,int b,int c,int d){
int id1=mp[make_pair(a,b)],id2=mp[make_pair(c,d)];
s1=p[id1],s2=p[id1]+p[a]-p[b];
point t1 = getLL(p[c],p[d],s1,s2);//一个交点
s1 = p[id2],s2=p[id2]+p[c]-p[d];
point t2 = getLL(p[a],p[b],s1,s2);
point bb = getLL(p[a],p[b],p[c],p[d]);
db S = abs(cross(bb-t1,bb-t2));
return S;
}
void init(){
int m = p.size();
for(int i=;i<m;i++){
db mx = ;int id=-;
for(int j=;j<m;j++){
db tmp = p[j].dis(proj(p[i],p[(i+)%m],p[j]));
if(cmp(tmp,mx)>){
mx=tmp,id=j;
}
}
mp[make_pair(i,(i+)%m)]=id;
}
}
point tmp;
int main(){
scanf("%d",&t);
for(int cas=;cas<=t;cas++){
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%lf%lf",&tmp.x,&tmp.y);
p.push_back(tmp);
}
p=convexHull(p);
if(p.size()<){
printf("Swarm %d Parallelogram Area: 0.0000\n",cas);
continue;
}
init();
db ans = 1e15;
int m = p.size();
for(int i=;i<m;i++){
for(int j=i+;j<m;j++) {
ans = min(ans,check(i, (i + ) % m, j,(j+)%m));
}
}
printf("Swarm %d Parallelogram Area: %.4f\n",cas,ans);
p.clear();mp.clear();
}
}
/**
1
4
0 0
0 1
0 2
0 3
*/

gym101657 C的更多相关文章

随机推荐

  1. Caused by: java.security.InvalidKeyException: Illegal key size or default parameters

    How to remove the key size restriction in Java JDK? Are you developing your beautiful application us ...

  2. 超详细动手搭建一个Vuepress站点及开启PWA与自动部署

    超详细动手搭建一个Vuepress站点及开启PWA与自动部署 五一之前就想写一篇关于Vuepress的文章,结果朋友结婚就不了了之了. 记得最后一定要看注意事项! Vuepress介绍 官网:http ...

  3. git stash命令详解

    git stash命令用于将更改储藏在脏工作目录中. 使用语法 git stash list [<options>] git stash show [<stash>] git ...

  4. Velocity日期格式化

    1.pom.xml添加依赖 <dependency> <groupId>velocity-tools</groupId> <artifactId>vel ...

  5. virltualbox 升级之后 苹果虚拟机报The installed support driver doesn't match the version of the user解决方案

    1.反安装virtualbox后,不要重启 2.删除virtualbox的安装目录 3.进入%userprofile% 目录 (比如: C:\users\me) 删除 .VirtualBox Virt ...

  6. Java高并发和多线程系列 - 1. 线程基本概念

    1. 什么是线程? 线程和进程的区别 在了解线程的概念前,我们应该先知道什么是进程? 进程是操作系统的基本概念之一, 它是正在执行的程序实例. * 下面的一些进程的基本概念你可以了解下 ------- ...

  7. gmock

    https://www.cnblogs.com/welkinwalker/archive/2011/11/29/2267225.html http://www.cnblogs.com/jycboy/p ...

  8. CentOS7 安装FastDFS分布式文件系统

    CentOS7 安装FastDFS分布式文件系统 最近要用到fastDFS,所以自己研究了一下,在搭建FastDFS的过程中遇到过很多的问题,为了能帮忙到以后搭建FastDFS的同学,少走弯路,与大家 ...

  9. isPrototypeOf 与 instanceof区别

    1.代码 <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF- ...

  10. C#模拟客户端发送数据示例

      在给一些客户端做服务器端支持时,发现他们提交上来的数据大都不是http请求格式,因而使用Request.Form获取不到内容,今天用C#做下模拟,并演示下数据接收. 1.发送文本 1).客户端发送 ...