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

2
25
3 -30 10 -20 0 -10 10
3 10 10 20 0 30 10
25
3 -30 -10 -20 -20 -10 -10
3 10 10 20 0 30 10

Sample Output

3.536
-15.000

Source

 
 
 

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

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

 #include <bits/stdc++.h>
using namespace std; const int inf = 0x3f3f3f3f;
const double eps = 1e-;
const double pi = acos(-1.0);
const int maxn = ; int cmp(double x) {
if (fabs(x) < eps) return ;
if (x > ) return ;
return -;
} inline double sqr(double x) {
return x*x;
} struct point {
double x, y;
point() {}
point(double a, double b) : x(a), y(b) {}
void input() {
scanf("%lf%lf", &x, &y);
}
friend point operator + (const point& a, const point& b) {
return point(a.x+b.x, a.y+b.y);
}
friend point operator - (const point& a, const point& b) {
return point(a.x-b.x, a.y-b.y);
}
friend bool operator == (const point& a, const point& b) {
return cmp(a.x-b.x)== && cmp(a.y-b.y)==;
}
friend point operator * (const point& a, const double& b) {
return point(a.x*b, a.y*b);
}
friend point operator * (const double& a, const point& b) {
return point(a*b.x, a*b.y);
}
friend point operator / (const point& a, const double& b) {
return point(a.x/b, a.y/b);
}
double norm() {
return sqrt(sqr(x)+sqr(y));
}
}; double det(const point& a, const point& b) {
return a.x*b.y-a.y*b.x;
} double calv(double h, vector<point>& p, int np, int lp) {
int i = , j = np-;
double v = ;
while (i <= lp && p[i].y > h) ++i;
while (j >= lp && p[j].y > h) --j;
if (i <= j) {
point c = point{p[i].x-(p[i].x-p[i-].x)*(h-p[i].y)/(p[i-].y-p[i].y), h};
point d = point{p[j].x+(p[j+].x-p[j].x)*(h-p[j].y)/(p[j+].y-p[j].y), h};
for (int k = i; k < j; ++k)
v += det(p[k], p[k+]);
v += det(p[j], d) + det(d, c) + det(c, p[i]);
}
return fabs(v/);
} int main() {
int T;
cin >> T;
while (T--) {
int np, nq, lp, lq;
vector<point> p(maxn), q(maxn);
double a;
scanf("%lf", &a);
lp = lq = ;
scanf("%d", &np);
for (int i = ; i < np; ++i) {
p[i].input();
if (p[i].y < p[lp].y)
lp = i;
}
scanf("%d", &nq);
for (int i = ; i < nq; ++i) {
q[i].input();
if (q[i].y < q[lq].y)
lq = i;
}
double l = min(p[lp].y, q[lq].y), r = (double)inf;
r = min(p[].y, min(p[np-].y, min(q[].y, q[nq-].y)));
while (fabs(r-l) > eps) {
double m = (l + r) / ;
double v = calv(m, p, np, lp) + calv(m, q, nq, lq);
if (cmp(v-a) >= ) {
r = m;
} else {
l = m;
}
}
printf("%.3f\n", r);
}
return ;
}

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. [poj3259]Wormholes(spfa判负环)

    题意:有向图判负环. 解题关键:spfa算法+hash判负圈. spfa判断负环:若一个点入队次数大于节点数,则存在负环.  两点间如果有最短路,那么每个结点最多经过一次,这条路不超过$n-1$条边. ...

  2. Windows下安装MySQL压缩zip包

    MySQL 是最流行的关系型数据库管理系统,在WEB应用方面 MySQL 是最好的RDBMS(Relational Database Management System:关系数据库管理系统)应用软件之 ...

  3. MinimumTours TopCoder - 7620

    Problem Statement      Little Bonnie has taken a vacation to Ha Long Bay. There are a few thousand s ...

  4. 阶段3-团队合作\项目-网络安全传输系统\sprint1-传输子系统设计\第3课-加密传输优化

    对之前的传输系统进行加密,使之成为加密的网络传输系统 客户端编程模型 通过以上模型对传统的TCP传输模型进行优化 首先完成初始化工作,它是要在创建socket之前完成 主要是以上四个函数的实现,那么这 ...

  5. Java异常处理的10个最佳实践

    本文作者: ImportNew - 挖坑的张师傅 未经许可,禁止转载! 异常处理在编写健壮的 Java 应用中扮演着非常重要的角色.异常处理并不是功能性需求,它需要优雅地处理任何错误情况,比如资源不可 ...

  6. lable对picbox透明

    为了登录美观一些,就在窗体上加了个picbox.并且充满了整个窗体. 往上面放了几个lable,把lable属性设置Transparent.本想着lable不会有底色,实际上有个底,很难看. 解决办法 ...

  7. SuperSocket使用 IRequestInfo 和 IReceiveFilter 等对象实现自定义协议

    为什么你要使用自定义协议? 通信协议用于将接收到的二进制数据转化成您的应用程序可以理解的请求. SuperSocket提供了一个内置的通信协议“命令行协议”定义每个请求都必须以回车换行"\r ...

  8. 利用表达式树Expression优化反射性能

    最近做了一个.Net Core环境下,基于NPOI的Excel导入导出以及Word操作的服务封装,涉及到大量反射操作,在性能优化过程中使用到了表达式树,记录一下. Excel导入是相对比较麻烦的一块, ...

  9. PostgreSQL 务实应用(四/5)JSON

    JSON 可谓风靡互联网,在数据交换使用上,其优势特别明显,其结构简洁.可读易读.形式灵活.很多 API 接口的数据都采用 JSON 来表示. PostgreSQL 对 JSON 提供了良好的支持.具 ...

  10. C#判断字符串是否是数字最简单的正则表达式

    if (theStr!= null)//注意加非空判断,否则报错 { System.Text.RegularExpressions.Regex rex = new System.Text.Regula ...