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 ...
随机推荐
- Dialog 自定义使用3(回调点击事件)
1 , Dialog布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns ...
- 树莓派 Learning 002 装机后的必要操作 --- 02 解决中文问题
树莓派 装机后的必要操作 - 解决中文问题 我的树莓派型号:Raspberry Pi 2 Model B V1.1 装机系统:NOOBS v1.9.2 每一块树莓派,装机后都应该执行的步骤 刚装机后, ...
- hadoop job 重要性能参数
name 说明 mapred.task.profile 是否对任务进行profiling,调用java内置的profile功能,打出相关性能信息 mapred.task.profile.{maps|r ...
- HDU 5862 Counting Intersections (离散化+扫描线+树状数组)
题意:给你若干个平行于坐标轴的,长度大于0的线段,且任意两个线段没有公共点,不会重合覆盖.问有多少个交点. 析:题意很明确,可是并不好做,可以先把平行与x轴和y轴的分开,然后把平行y轴的按y坐标从小到 ...
- java多线程系列:ThreadPoolExecutor
ThreadPoolExecutor自定义线程池 开篇一张图(图片来自阿里巴巴Java开发手册(详尽版)),后面全靠编 好了要开始编了,从图片中就可以看到这篇博文的主题了,ThreadPoolExec ...
- vs2013使用git报错
之前使用的是个人git账号,先转换为公司git账号,在同步时报Response status code does not indicate success: 403 (Forbidden) 上述问题是 ...
- 最短路——弗洛伊德算法(floyd)
模板: #include <bits/stdc++.h> using namespace std; ][]; int n,m,x,z,y; <<; int main() { c ...
- Codeforces 92C【二分】
意: 求最少需要几个s1串拼接存在子串s2 (1≤|s1|≤1e4,1≤|s2|≤1e6). 思路(感谢ZQC): 每个字母的出现位置存个vector. 假设你当前已经用了A串的前x个字符,现在想要匹 ...
- 洛谷P1373 小a和uim之大逃离
P1373 小a和uim之大逃离 题目背景 小a和uim来到雨林中探险.突然一阵北风吹来,一片乌云从北部天边急涌过来,还伴着一道道闪电,一阵阵雷声.刹那间,狂风大作,乌云布满了天空,紧接着豆大的雨点从 ...
- android--系统路径获取
Environment 常用方法: * 方法:getDataDirectory()解释:返回 File ,获取 Android 数据目录.* 方法:getDownloadCacheDirectory( ...