Connected Gheeves
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 1008   Accepted: 368

Description

Gheeves (plural of gheef) are some objects similar to funnels. We define a gheef as a two dimensional object specified by a sequence of points (p1p2, ..., pn) with the following conditions:

  • 3 ≤ n ≤ 1000
  • If a point pi is specified by the coordinates (xiyi), there is an index 1 < c < n such that y1 > y2 > ... > yc and yc < yc+1 < yc+2 < ... < ynpc is called the cusp of the gheef.
  • For all 1 ≤ i < cxi < xc and for all c < i ≤ nxi > xc.
  • For 1 < i < c, the amount of rotation required to rotate pi-1 around pi in clockwise direction to become co-linear with pi and pi+1, is greater than 180 degrees. Likewise, for c < i < n, the amount of rotation required to rotate pi-1 around pi in clockwise rotation to become co-linear with pi and pi+1, is greater than 180 degrees.
  • The set of segments joining two consecutive points of the sequence intersect only in their endpoints.

For example, the following figure shows a gheef of six points with c = 4:

We call the sequence of segments (p1p2p2p3, ..., pn-1pn), the body of the gheef. In this problem, we are given two gheeves P = (p1p2, ..., pn) and Q = (q1q2, ..., qm), such that all x coordinates of pi are negative integers and all x coordinates of qi are positive integers. Assuming the cusps of the two gheeves are connected with a narrow pipe, we pour a certain amount of water inside the gheeves. As we pour water, the gheeves are filled upwards according to known physical laws (the level of water in two gheeves remains the same). Note that in the gheef P, if the level of water reaches min(y1yn), the water pours out of the gheef (the same is true for the gheef Q). Your program must determine the level of water in the two gheeves after pouring a certain amount of water. Since we have defined our problem in two dimensions, the amount of water is measured in terms of area it fills. Note that the volume of pipe connecting cusps is considered as zero.

Input

The first number in the input line, t is the number of test cases. Each test case is specified on three lines of input. The first line contains a single integer a (1 ≤ a ≤ 100000) which specifies the amount of water poured into two gheeves. The next two lines specify the two gheeves P and Q respectively, each of the form k x1 y1 x2 y2 ... xk yk where k is the number of points in the gheef (n for P and m for Q), and the xiyi sequence specify the coordinates of the points in the sequences.

Output

The output contains t lines, each corresponding to an input test case in that order. The output line contains a single integer L indicating the final level of water, expressed in terms of y coordinates rounded to three digits after decimal points.
 

Sample Input

  1. 2
  2. 25
  3. 3 -30 10 -20 0 -10 10
  4. 3 10 10 20 0 30 10
  5. 25
  6. 3 -30 -10 -20 -20 -10 -10
  7. 3 10 10 20 0 30 10

Sample Output

  1. 3.536
  2. -15.000

Source

 
 
 

题意:给定两个凹形的水槽,一个在y轴左半边,一个在右半边。水槽有个最低点,其中最低点左半边y坐标严格递减,右半边严格递增。两个水槽最低点有水管相连。给你a升水,全部灌入水槽后,水面高度为多少?

题解:二分最终高度,判断面积与a大小关系即可。怎么算高度为h时的面积呢?对于每个水槽,找出y=h与水槽边界两个交点,然后与y=h下方的顶点组成一个多边形,叉积算面积即可。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int inf = 0x3f3f3f3f;
  5. const double eps = 1e-;
  6. const double pi = acos(-1.0);
  7. const int maxn = ;
  8.  
  9. int cmp(double x) {
  10. if (fabs(x) < eps) return ;
  11. if (x > ) return ;
  12. return -;
  13. }
  14.  
  15. inline double sqr(double x) {
  16. return x*x;
  17. }
  18.  
  19. struct point {
  20. double x, y;
  21. point() {}
  22. point(double a, double b) : x(a), y(b) {}
  23. void input() {
  24. scanf("%lf%lf", &x, &y);
  25. }
  26. friend point operator + (const point& a, const point& b) {
  27. return point(a.x+b.x, a.y+b.y);
  28. }
  29. friend point operator - (const point& a, const point& b) {
  30. return point(a.x-b.x, a.y-b.y);
  31. }
  32. friend bool operator == (const point& a, const point& b) {
  33. return cmp(a.x-b.x)== && cmp(a.y-b.y)==;
  34. }
  35. friend point operator * (const point& a, const double& b) {
  36. return point(a.x*b, a.y*b);
  37. }
  38. friend point operator * (const double& a, const point& b) {
  39. return point(a*b.x, a*b.y);
  40. }
  41. friend point operator / (const point& a, const double& b) {
  42. return point(a.x/b, a.y/b);
  43. }
  44. double norm() {
  45. return sqrt(sqr(x)+sqr(y));
  46. }
  47. };
  48.  
  49. double det(const point& a, const point& b) {
  50. return a.x*b.y-a.y*b.x;
  51. }
  52.  
  53. double calv(double h, vector<point>& p, int np, int lp) {
  54. int i = , j = np-;
  55. double v = ;
  56. while (i <= lp && p[i].y > h) ++i;
  57. while (j >= lp && p[j].y > h) --j;
  58. if (i <= j) {
  59. point c = point{p[i].x-(p[i].x-p[i-].x)*(h-p[i].y)/(p[i-].y-p[i].y), h};
  60. point d = point{p[j].x+(p[j+].x-p[j].x)*(h-p[j].y)/(p[j+].y-p[j].y), h};
  61. for (int k = i; k < j; ++k)
  62. v += det(p[k], p[k+]);
  63. v += det(p[j], d) + det(d, c) + det(c, p[i]);
  64. }
  65. return fabs(v/);
  66. }
  67.  
  68. int main() {
  69. int T;
  70. cin >> T;
  71. while (T--) {
  72. int np, nq, lp, lq;
  73. vector<point> p(maxn), q(maxn);
  74. double a;
  75. scanf("%lf", &a);
  76. lp = lq = ;
  77. scanf("%d", &np);
  78. for (int i = ; i < np; ++i) {
  79. p[i].input();
  80. if (p[i].y < p[lp].y)
  81. lp = i;
  82. }
  83. scanf("%d", &nq);
  84. for (int i = ; i < nq; ++i) {
  85. q[i].input();
  86. if (q[i].y < q[lq].y)
  87. lq = i;
  88. }
  89. double l = min(p[lp].y, q[lq].y), r = (double)inf;
  90. r = min(p[].y, min(p[np-].y, min(q[].y, q[nq-].y)));
  91. while (fabs(r-l) > eps) {
  92. double m = (l + r) / ;
  93. double v = calv(m, p, np, lp) + calv(m, q, nq, lq);
  94. if (cmp(v-a) >= ) {
  95. r = m;
  96. } else {
  97. l = m;
  98. }
  99. }
  100. printf("%.3f\n", r);
  101. }
  102. return ;
  103. }

poj3334(Connected Gheeves)的更多相关文章

  1. poj 3334 Connected Gheeves (Geometry + BInary Search)

    3334 -- Connected Gheeves 题意是,给出两个尖形的相连的容器,要求向其中灌水.它们具有日常的物理属性,例如两个容器中水平面高度相同以及水高于容器顶部的时候就会溢出.开始的时候打 ...

  2. ACM计算几何题目推荐

    //第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...

  3. [LeetCode] Number of Connected Components in an Undirected Graph 无向图中的连通区域的个数

    Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...

  4. PTA Strongly Connected Components

    Write a program to find the strongly connected components in a digraph. Format of functions: void St ...

  5. poj 1737 Connected Graph

    // poj 1737 Connected Graph // // 题目大意: // // 带标号的连通分量计数 // // 解题思路: // // 设f(n)为连通图的数量,g(n)为非连通图的数量 ...

  6. LeetCode Number of Connected Components in an Undirected Graph

    原题链接在这里:https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/ 题目: Giv ...

  7. Windows Phone 8 解锁提示IpOverUsbSvc问题——IpOverUsbEnum返回No connected partners found解决方案

    我的1520之前总是无法解锁,提示:IpOverUsbSvc服务没有开启什么的. 根据网上网友的各种解决方案: 1. 把手机时间设置为当前时间,并且关闭“自动设置” 2. 确保手机接入了互联网 3.确 ...

  8. POJ1737 Connected Graph

    Connected Graph Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3156   Accepted: 1533 D ...

  9. [LintCode] Find the Weak Connected Component in the Directed Graph

      Find the number Weak Connected Component in the directed graph. Each node in the graph contains a ...

随机推荐

  1. Wannafly 锁

    题意: 现在有 $n$ 个人,每个人有一个已然给定的重要度 $a_i$,现有 K 个锁,每个锁有若干钥匙,分配给一些人,要求一群人能够打开全部 $K$ 把锁, 当且仅当他们重要度的和大于等于 $m$, ...

  2. nodejs 操作文件系统读取写入文件

    我们通过fs这个模块来对文件系统进行操作,对于文件系统操作一般都有同步.异步方法,两者区别,同步等有返回结果时候,在继续执行后面的代码,异步是不等返回结果,直接执行后面的代码,待有返回结果时候,通过回 ...

  3. ubuntu安装配置ApachePhpMysql

    1.安装之前先sudo源 sudo apt update 2.安装Apache2 sudo apt install apache2 3.更改默认目录: vi /etc/apache2/apache2. ...

  4. Flask15 远程开发环境搭建、安装虚拟机、导入镜像文件、创建开发环境、pycharm和远程开发环境协同工作

    1 安装VM虚拟机 待更新... 2 导入镜像文件 待更新... 3 启动虚拟机 4 远程连接虚拟机 4.1 安装xShell软件 待更新... 4.2 创建一个新的连接 4.2.1 在虚拟机中获取虚 ...

  5. 高性能服务器设计(Jeff Darcy's notes on high-performance server design

    高性能服务器设计(Jeff Darcy's notes on high-performance server design 我想通过这篇文章跟大家共享一下我多年来怎样开发“服务器”这类应用的一些想法和 ...

  6. 如何使用visual studio 2017创建C语言项目

    使用visual studio 2017创建一个C语言项目,步骤如下: (1)打开Visual Studio 2017环境后出现欢迎界面,如图1所示. 图1  Visual Studio 2017欢迎 ...

  7. .Net Core 扩展使用Refit

    .Net Core 扩展使用Refit 标签(空格分隔): 未分类 在.net core 2.1当中,目前可以是用HttpClientFactory进行Http的调用,它的使用方法我不再多说,具体参见 ...

  8. 程序员笔记|详解Eureka 缓存机制

    引言 Eureka是Netflix开源的.用于实现服务注册和发现的服务.Spring Cloud Eureka基于Eureka进行二次封装,增加了更人性化的UI,使用更为方便.但是由于Eureka本身 ...

  9. CSS 框模型概述

    在 CSS 中,width 和 height 指的是内容区域的宽度和高度. 增加内边距.边框和外边距不会影响内容区域的尺寸,但是会增加元素框的总尺寸. 假设框的每个边上有 10 个像素的外边距和 5 ...

  10. 我的省选 Day -13

    Day -13 10:18:46 早上360浏览器的网站一直显示 证书错误! 打开洛谷,一脸懵逼,网页根本不能正常显示.(一直到刚刚改了一下系统时间才恢复正常) 好在已经把昨天那道矩阵乘法的题目做完了 ...