poj3334(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 (p1, p2, ..., pn) with the following conditions:
- 3 ≤ n ≤ 1000
- If a point pi is specified by the coordinates (xi, yi), there is an index 1 < c < n such that y1 > y2 > ... > yc and yc < yc+1 < yc+2 < ... < yn. pc is called the cusp of the gheef.
- For all 1 ≤ i < c, xi < xc and for all c < i ≤ n, xi > 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 (p1p2, p2p3, ..., pn-1pn), the body of the gheef. In this problem, we are given two gheeves P = (p1, p2, ..., pn) and Q = (q1, q2, ..., 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(y1, yn), 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)的更多相关文章
- poj 3334 Connected Gheeves (Geometry + BInary Search)
3334 -- Connected Gheeves 题意是,给出两个尖形的相连的容器,要求向其中灌水.它们具有日常的物理属性,例如两个容器中水平面高度相同以及水高于容器顶部的时候就会溢出.开始的时候打 ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 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), ...
- PTA Strongly Connected Components
Write a program to find the strongly connected components in a digraph. Format of functions: void St ...
- poj 1737 Connected Graph
// poj 1737 Connected Graph // // 题目大意: // // 带标号的连通分量计数 // // 解题思路: // // 设f(n)为连通图的数量,g(n)为非连通图的数量 ...
- LeetCode Number of Connected Components in an Undirected Graph
原题链接在这里:https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/ 题目: Giv ...
- Windows Phone 8 解锁提示IpOverUsbSvc问题——IpOverUsbEnum返回No connected partners found解决方案
我的1520之前总是无法解锁,提示:IpOverUsbSvc服务没有开启什么的. 根据网上网友的各种解决方案: 1. 把手机时间设置为当前时间,并且关闭“自动设置” 2. 确保手机接入了互联网 3.确 ...
- POJ1737 Connected Graph
Connected Graph Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3156 Accepted: 1533 D ...
- [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 ...
随机推荐
- viewstate的基本用法
转自:http://www.cnblogs.com/ooip/p/4743536.html 在web窗体将控件属性设置为runat=server时,这个控件会被添加一个隐藏属性_ViewState,_ ...
- socket消息发送
expressClient.html <html><head><meta http-equiv="Content-Type" content=&quo ...
- AngularJs(Part 11)--自定义Directive
先对自定义Directive有一个大体的映像 myModule.directive('myDirective',function(injectables){ var directiveDefiniti ...
- 《精通Spring4.X企业应用开发实战》读后感第五章(通过编码方式动态添加Bean)
- p2341&bzoj1051 受欢迎的牛
传送门(洛谷) 传送门(bzoj) 题目 每一头牛的愿望就是变成一头最受欢迎的牛.现在有N头牛,给你M对整数(A,B),表示牛A认为牛B受欢迎. 这 种关系是具有传递性的,如果A认为B受欢迎,B认为C ...
- 截止JDK1.8版本,java并发框架支持锁包括?
读写锁 自旋锁 乐观锁
- Software - 创建程序打包项目
通常的步骤 准备一个 Visual Studio Installer 的项目模板 利用该模板,在解决方案中新建一个 Visual Studio Installer 项目 设置项目属性,配置文件系统 生 ...
- python下一个转码的问题
我想把一个quoted的字符串经过unquote处理后,打印出来.被unquote处理后的字串应该是utf-8的,因此还需要按照utf-8再做一次解码,代码如下: import urllib im ...
- 2017-10-19 NOIP模拟赛
Count(哈格朗日插值) 题解: 有个定理,另sum(x)表示小于等于x的数中与x互质的数的和 sum(x)=φ(x)*x/2 最后可知f(x)=x (f(1)=2) 当然打表能知道. 然 ...
- 2017-10-17 NOIP模拟赛2
a [问题描述]你是能看到第一题的 friends 呢.——hja何大爷对字符串十分有研究,于是天天出字符串题虐杀 zhx.何大爷今天为字符串定义了新的权值计算方法.一个字符串由小写字母组成,字符串的 ...