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 ...
随机推荐
- Servlet编程实例
---------------siwuxie095 登录实例: 从 login.jsp 提交登录信息到 LoginServlet,在 LoginServlet 中打印登录信息 工程结构目录如下: Lo ...
- [MySQL] Data too long for column 'title' at row 1
李刚轻量级JavaEE第六章的坑..艹李刚自己有没试过这些代码的啊,6.4这一份HqlQuery.java里需要的表,根本就跟他提供的sql脚本对不上啊..坑爹啊,而且字符编码集也有问题. 出现这个原 ...
- Asp.net Core 使用 EntityFrameworkCore 1.1
前言 相比大家也在开发中是非常喜欢用ORM的.今天就来介绍一下EntityFrameworkCore的使用方法. 自从EF Core升级到1.1之后,确实变化挺大的.如果没试过真的不知道坑是挺多的.今 ...
- 23. CTF综合靶机渗透(十六)
靶机说明: VM Name: JIS-CTF : VulnUpload Difficulty: Beginner Description: There are five flags on this m ...
- 使用form 组件写一个用户注册,并用 bootstrap渲染
需求:使用form组件,写一个用户注册系统,包含用户名, 密码, 确认密码,手机号,性别,爱好,注册.并用bootsrap渲染,成果如下: 首先创建一个django 项目.然后在连接pymysql数据 ...
- bash字符串匹配
#!/bin/shfoo(){ local basedir=$1 local all_entries=`ls -c` for entry in $all_entries do ...
- hdu 1576 A/B (求逆元)
题目链接 Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1). Inpu ...
- gitlab私服搭建
1.什么是gitlab: gitlab 是一个用于仓库管理系统的开源项目,它以git为代码管理工具,因此代码可以管到它上边来.搭建私服gitlab可以方便我们有条不紊的管理我们的代码.闲话不说,上代码 ...
- vue -- 插件的开发与使用
开发插件 插件通常会为 Vue 添加全局功能.插件的范围没有限制--一般有下面几种: 1.添加全局方法或者属性,如: vue-custom-element. 2.添加全局资源:指令/过滤器/过渡等,如 ...
- bzoj 4974: [Lydsy八月月赛]字符串大师
4974: [Lydsy八月月赛]字符串大师 Time Limit: 1 Sec Memory Limit: 256 MBSubmit: 371 Solved: 190[Submit][Statu ...