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. 菜鸟级的Git与GitHub使用总结(转)

    菜鸟级的Git与GitHub使用总结 原创 2016年12月01日 14:58:30 1792 前言 这几天一直在折腾学习Git和GitHub的使用.几天下来,在网上查阅了大量的资料,总算有一些成果. ...

  2. Flask03 路由控制(转换器)、反转、请求方法控制

    1 提出问题 如何实现前端传过去的路径时动态的(即:多个url对应一个url视图函数) 例如: 浏览器中输入 http://127.0.0.1:5000/test/good/ 或者 http://12 ...

  3. hadoop主节点(NameNode)备份策略以、恢复方法、操作步骤

    一.dits和fsimage      首先要提到两个文件edits和fsimage,下面来说说他们是做什么的. 集群中的名称节点(NameNode)会把文件系统的变化以追加保存到日志文件edits中 ...

  4. 朴素贝叶斯算法分析及java 实现

    1. 先引入一个简单的例子 出处:http://www.ruanyifeng.com/blog/2013/12/naive_bayes_classifier.html 一.病人分类的例子 让我从一个例 ...

  5. miRNA

    MicroRNA (miRNA)  是一类内生的.长度约为20-24个核苷酸的小 RNA,其在细胞内具有多种重要的调节作用.每个 miRNA 可以有多个靶基因的表达,而几个 miRNA 也可以调节同一 ...

  6. 怀旧系列(3)----Pascal

    Pascal语言是高中时代2000年左右为了参加计算机竞赛学习的一门语言(Turbo Pascal7.0).据说这么语言的结构化非常好,非常适合青少年形成一定的编程思想.但是现在的角度想想都是扯淡,现 ...

  7. Ubuntu12.04 上使用perl snmpwalk问题

    今天在Ubuntu12.04上使用perl来获取snmp数据,运行时出现下列问题.解决方法安装一下libnet-snmp-perl即可.命令行运行:sudo apt-get install libne ...

  8. VS插件开发(生成实体类)

    写了N年的代码,回头过来看,其中有80%代码都是重复的代码,深入研究VS插件开发,应用到工作中,让自己减少基础的代码开发,增加开发效率 1.新增解决方案: Extensiblity->VSIX ...

  9. java学习笔记——基于Robot类的屏幕分享

    直接上代码,具体看注释: package robot; import java.awt.AWTException; import java.awt.Dimension; import java.awt ...

  10. ALSA声音编程

    1. ALSA设备驱动将ALSA设备描述分为四层,从上到下为: default default:0 plughw:0,0 hw:0,0 不同的层次,对设备的控制权限不同,比如hardware para ...