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 ...
随机推荐
- [HDU3037]Saving Beans,插板法+lucas定理
[基本解题思路] 将n个相同的元素排成一行,n个元素之间出现了(n-1)个空档,现在我们用(m-1)个“档板”插入(n-1)个空档中,就把n个元素隔成有序的m份,每个组依次按组序号分到对应位置的几个元 ...
- GET POST区别不同情况
相信大家在面试的时候经常会被问到:GET与POST有什么区别吧?你是怎么回答的呢?POST比GEt安全?GET有URL的长度限制而POST没有或者很大?GET通过URL或者Cookie传参数,POST ...
- Entity Framework Code-First(9.11):DataAnnotations - InverseProperty Attribute
DataAnnotations - InverseProperty Attribute: We have seen in the Code-First Convention section that ...
- 3. Shodan新手入坑指南
什么是 Shodan? 首先,Shodan 是一个搜索引擎,但它与 Google 这种搜索网址的搜索引擎不同,Shodan 是用来搜索网络空间中在线设备的,你可以通过 Shodan 搜索指定的设备,或 ...
- SQL查询 若为空显示默认值
COALESCE(a.end_,now()) SELECT COALESCE(NULL,NULL,3,4,5) FROM
- @Html.AntiForgeryToken() 源码分析,表单防伪码的生成
源码来自MVC4@Html.AntiForgeryToken() 源码分析 public MvcHtmlString AntiForgeryToken() { return new MvcHtmlSt ...
- 图的最小切隔问题Minimum Cuts
前提条件是这样的:输入一个图(可以是有向图,也可以是无向图,允许平行边存在),我们要做的事情是将这个图切割成两个子图,(切割的定义:将图中的所有顶点分为两个集合A和B,要求这两个集合非空)假设这个图中 ...
- Python 生成个性二维码
1.1 实验内容 本课程通过调用MyQR接口来实现生成个人所需二维码,并可以设置二维码的大小.是否在现有图片的基础上生成.是否生成动态二维码. 本课程主要面向Python3初学者. 1.2 知识点 P ...
- Java实例——基于jsoup的简单爬虫实现(从智联获取工作信息)
这几天在学习Java解析xml,突然想到Dom能不能解析html,结果试了半天行不通,然后就去查了一些资料,发现很多人都在用Jsoup解析html文件,然后研究了一下,写了一个简单的实例,感觉还有很多 ...
- go语言web开发框架_Iris框架讲解(六):Session的使用和控制
在实际的项目开发中,我们会经常有业务场景使用到Session功能.在iris框架中,也为我们提供了方便使用,功能齐全的Session模块.Session模块的源码目录为kataras/iris/ses ...