Aquarium Tank(csu1634+几何+二分)Contest2087 - 湖南多校对抗赛(2015.05.24)-G
Aquarium Tank
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 15 Solved: 4
[Submit][Status][Web Board]
Description
You just bought an “artistic” aquarium tank that has an interesting shape, and you poured L litres of water into the tank. How high is the water in the tank?
When you look at this tank from one side, it has the shape of a convex polygon. This polygon has exactly two vertices on the table (y-coordinates are 0), and all other vertices have positive y-coordinates. There are also exactly two vertices with maximum y-coordinates, and water is poured into the opening between these two vertices. This aquarium tank has a depth of D centimetres. The tank is glued to the table, so no matter what shape it has, it keeps its position and does not tip over. All coordinates and lengths in this problem are given in centimetres. It should be noted that each cubic metre is equivalent to 1 000 litres.
An illustration showing the configuration of the tank of the first sample input is given below:
Input
The input consists of a single test case. The first line contains an integer N (4 ≤ N ≤ 100) giving the number of vertices in the polygon. he next line contains two integers D and L, where 1 ≤ D ≤ 1000 is he depth of the aquarium tank and 0 L 2 000 is the number of litres f water to pour into the tank. The next N lines each contains two integers, giving the (x, y) coordinates of the vertices of the convex polygon in counterclockwise order. The absolute values of x and y are at most 1 000. You may assume that the tank has a positive capacity, and you never pour more water than the tank can hold.
Output
Print the height of the water (in centimetres) in the aquarium tank on a line to 2 decimal places.
Sample Input
- 4
- 30 50
- 20 0
- 100 0
- 100 40
- 20 40
Sample Output
- 20.83
HINT
Source
题意:有一个横放是多边形的棱柱。问L升水,注入其中,容器的深度是多少。
思路:棱柱的体积等于底面积成高,so、、、我可以二分多边形的高度(用平行与X轴的直线求切割多边形)取下半部分是面积;
坑!比赛的时候,我以为第一组边一定是在x轴上的。。。o(︶︿︶)o 唉,结果是一定有一组边在x轴上,但不一定是第一组!。。。
转载请注明出处:
寻找&星空の孩子
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1634
比较乱,没整理!
- #include<cstdio>
- #include<cmath>
- #include<iostream>
- #define PI acos(-1.0)
- using namespace std;
- struct Point
- {
- double x,y;
- Point(double x=,double y=):x(x),y(y) {}
- };
- double hmax;
- double D,L;
- typedef Point Vector;//Vector只是Point的别名
- //向量+向量=向量; 向量+点=点
- Vector operator + (Vector A,Vector B)
- {
- return Vector(A.x+B.x,A.y+B.y);
- }
- //点-点=向量
- Vector operator - (Point A,Point B)
- {
- return Vector(A.x-B.x,A.y-B.y);
- }
- //向量*数=向量
- Vector operator * (Vector A,double p)
- {
- return Vector(A.x*p,A.y*p);
- }
- //向量/数=向量
- Vector operator / (Vector A,double p)
- {
- return Vector(A.x/p,A.y/p);
- }
- //
- bool operator < (const Point& a,const Point& b)
- {
- return a.x<b.x||(a.x==b.x && a.y<b.y);
- }
- //
- const double eps = 1e-;
- //三态函数
- int dcmp(double x)
- {
- if(fabs(x)<eps)return ;
- else return x < ? - : ;
- }
- //相等
- bool operator == (const Point& a,const Point& b)
- {
- return dcmp(a.x-b.x)== && dcmp(a.y-b.y)==;
- }
- double Dot(Vector A,Vector B)
- {
- return A.x*B.x+A.y*B.y;
- }
- double length(Vector A)
- {
- return sqrt(Dot(A,A));
- }
- double Angle(Vector A,Vector B)
- {
- return acos(Dot(A,B)/length(A)/length(B));
- }
- double Cross(Vector A,Vector B)
- {
- return A.x*B.y-B.x*A.y;
- }
- double Area2(Point A,Point B,Point C)
- {
- return Cross(B-A,C-A);
- }
- double PArea(Point *p,int n)
- {
- double area=;
- for(int i=; i<n; i++)
- {
- area+=Cross(p[i],p[(i+)%n]);
- // printf("area=%f\n",area);
- }
- return fabs(area/);
- }
- /*******两直线交点*******/
- //调用前确保两条直线P+tv和Q+tv有唯一交点,当且仅当Cross(v,w)非0;
- Point GetLineIntersection(Point P,Vector v,Point Q,Vector w)
- {
- Vector u=P-Q;
- // printf("P=(%f,%f),v=(%f,%f),Q=(%f,%f),w=(%f,%f)\n",P.x,P.y,v.x,v.y,Q.x,Q.y,w.x,w.y);
- // if(Cross(v,w))
- // {
- // double t=Cross(w,u)/Cross(v,w);//精度高的时候,考虑自定义分数类
- // return P+v*t;
- // }
- // else
- // return ;
- //printf("t= %lf\t%lf",Cross(w,u),Cross(v,w));
- return P+v*Cross(w,u)/Cross(v,w);
- }
- //输入函数
- Point read_point(Point &P)
- {
- scanf("%lf%lf",&P.x,&P.y);
- hmax=max(hmax,P.y);
- return P;
- }
- Point get_point(Point a, Point b, double y0)
- {
- if(fabs(a.x - b.x) < eps) return Point(a.x, y0);
- double bi = (y0 - a.y) / (b.y - a.y);
- return Point(a.x + bi * (b.x - a.x), a.y + bi * (b.y - a.y));
- }
- int main()
- {
- Point po[],Q[];
- int T,n,q,i;
- // freopen("debug//secret-tank-03.in","r",stdin);
- while(scanf("%d",&n)!=EOF)
- {
- scanf("%lf%lf",&D,&L);
- hmax=;
- for(i=; i<n; i++)
- {
- read_point(po[i]);
- // printf("----[%lf]\n",po[i]);
- }
- // po[n]=po[0];
- // po[n+1]=po[1];
- // Q[0]=po[0];
- // Q[1]=po[1];
- // printf("Q[%d]=%lf\n\n",1,po[1]);
- double d=,h=hmax;
- while(h-d>eps)
- {
- q=;
- int per=n-;
- double m=(d+h)/;
- // printf("m=%lf\n",m);
- // getchar();
- Point M(,m);
- Vector w(,);
- for(int i=; i<n; i++)
- {
- // if(i==0&&(m-po[i].y)>eps){Q[q++]=po[i];continue;}
- // else if((m-po[i].y)==eps)
- // {
- // Q[q++]=po[i];
- // }
- if((m-po[i].y)*(m-po[per].y)<eps)
- {
- // printf("------------------------------------------------------\n");
- // Vector PP=po[i]-po[per];
- // Q[q++]=GetLineIntersection(po[per],PP,M,w);
- Q[q++]=get_point(po[i],po[per],m);
- }
- if((m-po[i].y)>eps)
- {
- // if(i==1) Q[q++]=po[i-1];
- Q[q++]=po[i];
- }
- per=i;
- // printf("Q[%d]=(%f,%f)\n",q-1,Q[q-1].x,Q[q-1].y);
- }
- // Q[q]=Q[0];
- // if(m==20)
- // for(int i=0;i<q;i++)
- // {
- // printf("Q[%d]=(%f,%f)\n",i,Q[i].x,Q[i].y);
- // }
- double area=PArea(Q,q);
- // printf("L=%f\tV=%lf\tm=%lf\n",L*1000,area*D,m);
- if(L*-area*D>eps) d=m;
- else h=m;
- }
- printf("%.2f\n",d);
- }
- return ;
- }
- /**************************************************************
- Problem: 1634
- User: aking2015
- Language: C++
- Result: Accepted
- Time:0 ms
- Memory:1496 kb
- ****************************************************************/
好吧。发个整理过的。
- #include<cstdio>
- #include<cmath>
- #include<iostream>
- #define PI acos(-1.0)
- using namespace std;
- struct Point
- {
- double x,y;
- Point(double x=,double y=):x(x),y(y) {}
- };
- double hmax;
- double D,L;
- typedef Point Vector;
- Vector operator + (Vector A,Vector B)
- {
- return Vector(A.x+B.x,A.y+B.y);
- }
- Vector operator - (Point A,Point B)
- {
- return Vector(A.x-B.x,A.y-B.y);
- }
- Vector operator * (Vector A,double p)
- {
- return Vector(A.x*p,A.y*p);
- }
- Vector operator / (Vector A,double p)
- {
- return Vector(A.x/p,A.y/p);
- }
- bool operator < (const Point& a,const Point& b)
- {
- return a.x<b.x||(a.x==b.x && a.y<b.y);
- }
- const double eps = 1e-;
- int dcmp(double x)
- {
- if(fabs(x)<eps)return ;
- else return x < ? - : ;
- }
- bool operator == (const Point& a,const Point& b)
- {
- return dcmp(a.x-b.x)== && dcmp(a.y-b.y)==;
- }
- double Dot(Vector A,Vector B)
- {
- return A.x*B.x+A.y*B.y;
- }
- double length(Vector A)
- {
- return sqrt(Dot(A,A));
- }
- double Angle(Vector A,Vector B)
- {
- return acos(Dot(A,B)/length(A)/length(B));
- }
- double Cross(Vector A,Vector B)
- {
- return A.x*B.y-B.x*A.y;
- }
- double Area2(Point A,Point B,Point C)
- {
- return Cross(B-A,C-A);
- }
- double PArea(Point *p,int n)
- {
- double area=;
- for(int i=; i<n; i++)
- {
- area+=Cross(p[i],p[(i+)%n]);
- }
- return fabs(area/);
- }
- Point GetLineIntersection(Point P,Vector v,Point Q,Vector w)
- {
- Vector u=P-Q;
- return P+v*Cross(w,u)/Cross(v,w);
- }
- Point read_point(Point &P)
- {
- scanf("%lf%lf",&P.x,&P.y);
- hmax=max(hmax,P.y);
- return P;
- }
- Point get_point(Point a, Point b, double y0)
- {
- if(fabs(a.x - b.x) < eps) return Point(a.x, y0);
- double bi = (y0 - a.y) / (b.y - a.y);
- return Point(a.x + bi * (b.x - a.x), a.y + bi * (b.y - a.y));
- }
- int main()
- {
- Point po[],Q[];
- int T,n,q,i;
- while(scanf("%d",&n)!=EOF)
- {
- scanf("%lf%lf",&D,&L);
- hmax=;
- for(i=; i<n; i++)
- {
- read_point(po[i]);
- }
- double d=,h=hmax;
- while(h-d>eps)
- {
- q=;
- int per=n-;
- double m=(d+h)/;
- Point M(,m);
- Vector w(,);
- for(int i=; i<n; i++)
- {
- if((m-po[i].y)*(m-po[per].y)<eps)
- {
- Vector PP=po[i]-po[per];
- Q[q++]=GetLineIntersection(po[per],PP,M,w);
- // Q[q++]=get_point(po[i],po[per],m);
- }
- if((m-po[i].y)>eps)
- {
- Q[q++]=po[i];
- }
- per=i;
- }
- double area=PArea(Q,q);
- if(L*-area*D>eps) d=m;
- else h=m;
- }
- printf("%.2f\n",d);
- }
- return ;
- }
- /**************************************************************
- Problem: 1634
- User: aking2015
- Language: C++
- Result: Accepted
- Time:0 ms
- Memory:1500 kb
- ****************************************************************/
Aquarium Tank(csu1634+几何+二分)Contest2087 - 湖南多校对抗赛(2015.05.24)-G的更多相关文章
- Contest2071 - 湖南多校对抗赛(2015.03.28)
Contest2071 - 湖南多校对抗赛(2015.03.28) 本次比赛试题由湖南大学ACM校队原创 http://acm.csu.edu.cn/OnlineJudge/contest.php?c ...
- Contest2073 - 湖南多校对抗赛(2015.04.06)
Contest2073 - 湖南多校对抗赛(2015.04.06) Problem A: (More) Multiplication Time Limit: 1 Sec Memory Limit: ...
- 湖南多校对抗赛(2015.05.03)Problem A: Twenty-four point
给四个数 问能不能算出24点...我的方法比较烂...920ms 差点TLE.应该有更好的方法. #include<stdio.h> #include<string.h> #i ...
- 湖南多校对抗赛(2015.05.03)Problem B: War
并查集.从后往前加边. #include<stdio.h> #include<string.h> #include<math.h> #include<algo ...
- Contest2089 - 湖南多校对抗赛(2015.05.31) Swipe(csu1648)
Problem E: Swipe Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 100 Solved: 15[Submit][Status][Web ...
- Heaps(Contest2080 - 湖南多校对抗赛(2015.05.10)(国防科大学校赛决赛-Semilive)+scu1616)
Problem H: Heaps Time Limit: 2 Sec Memory Limit: 128 MBSubmit: 48 Solved: 9[Submit][Status][Web Bo ...
- Clock Pictures(kmp + Contest2075 - 湖南多校对抗赛(2015.04.26))
Problem H: Clock Pictures Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 73 Solved: 18[Submit][Stat ...
- CSU 2136 ——湖南多校对抗赛 I
2136: 统帅三军! Submit Page Summary Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 55 ...
- hdu6097[二分+解析几何] 2017多校6
/*hdu6097[二分+解析几何] 2017多校6*/ #include <bits/stdc++.h> using namespace std; ; struct node{ doub ...
随机推荐
- Virtual Networking
How the virtual networks used by guests work Networking using libvirt is generally fairly simple, an ...
- Visual Studio 开发(一):安装配置Visual Studio Code
一.为何使用Visual Studio Code 在学习音视频开发的时候,使用到了C和C++,在回顾复习C和C++的知识的时候,需要编写一些代码来加强理解. 虽然,有在线的语言编辑工具https:// ...
- eclipse使用和快捷键
一.快捷键 - ctrl + shift + o 导包 - ctrl + shift + t 快速查找某个类 - 先按ctrl + 2 ,再点L, 创建变量并命名 - ctrl + o , 在当前类中 ...
- 在 React、Vue项目中使用 SVG
在一些现代的扁平化设计网站,特别是移动端网站,经常会包含许多简单而清晰的小图标,例如网站图标.用户的默认头像.移动端网页首页底部固定的切换栏等,这些小图标一般都是由美工做好,可能会放到精灵图上,前端再 ...
- linux mint 安装 opencv2.4
Download opencv https://github.com/opencv/opencv/tree/2.4 安装必要的依赖 sudo apt-get install build-essenti ...
- 破解第三课 关键跳和关键CALL
课前自泼凉水: 前两课的介绍的方法,不管是NOP填充还是JUM的无条件跳转,其实都有极大的局限性. 甚至单纯就效果而言,几乎无用. 且不说利用OD搜索关键字本身就很难搜得到. 就现在的软件保护而言,也 ...
- chrome强制刷新,非ctrl+f5
开发时,经常有ctrl+f5无法做到真正的强制刷新,以下可以帮到你 Ctrl+Shift+Del 清除Google浏览器缓存的快捷键 Ctrl+Shift+R 重新加载当前网页而不使用缓存内容
- C# 多线程锁之ReaderWriterLockSlim
1.简介 .NET 3.5 开始 ReaderWriterLockSlim登上舞台,ReaderWriterLockSlim 可以看做是 ReaderWriterLock 的升级版. 由于 Reade ...
- mysql 导入 CSV文件命令行 ERROR 13 (HY000): Can't get stat of
一定要查看好CSV字段结构是否和文件的表结构字段一致 load data local infile 'F:/MySqlData/test1.csv' --CSV文件存放路径 into table st ...
- 基于Electron+.NET Core的前后端分离的跨平台桌面应用
Web做界面比原生桌面界面开发速度真心要快很多,而且组件也多. 分析: 1..NET Core和Electron都是跨平台的. 2.NET Core做后端很方便,但是没有GUI,Electron做桌面 ...