EOJ-1708//POJ3334
题意:
有一个连通器,由两个漏斗组成(关于漏斗的描述见描述)。
现向漏斗中注入一定量的水,问最终水的绝对位置(即y轴坐标)
思路:
总体来说分为3种情况。
1.两个漏斗可能同时装有水。
2.只可能a漏斗有水。
3.只可能b漏斗有水。
于是可以二分枚举y的坐标。
关键在于对于某个y坐标来说,要求出新的交点,再求面积。
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <math.h>
- #include <algorithm>
- #include <iostream>
- using namespace std;
- const int maxn = ;
- const double eps = 1e-;
- const double inf = 999999999.99;
- struct Point{
- double x,y;
- }a[ maxn ],b[ maxn ],res[ maxn ],amid,bmid;
- double xmult( Point a,Point b,Point c ){
- double ans = (a.x-c.x)*(b.y-c.y) - (a.y-c.y)*(b.x-c.x);
- return ans;
- }
- int cmp( Point a,Point b ){
- if( a.x!=b.x ) return a.x<b.x;
- else return a.y>b.y;
- }
- double area( Point pnt[],int n ){
- double ans = ;
- for( int i=;i<n-;i++ ){
- ans += xmult( pnt[],pnt[i],pnt[i+] );
- }
- return fabs( 0.5*ans );
- }
- int main(){
- //freopen("out.txt","w",stdout);
- int T;
- scanf("%d",&T);
- while( T-- ){
- double aim;
- double ansY = ;
- scanf("%lf",&aim);
- int n1,n2;
- scanf("%d",&n1);
- double ymax = inf;
- int flag1 = -;
- for( int i=;i<n1;i++ ){
- scanf("%lf%lf",&a[i].x,&a[i].y);
- if( ymax>a[i].y ){
- ymax = a[i].y;
- flag1 = i;
- }
- }
- amid = a[ flag1 ];
- scanf("%d",&n2);
- ymax = inf;
- int flag2 = -;
- for( int i=;i<n2;i++ ){
- scanf("%lf%lf",&b[i].x,&b[i].y);
- if( ymax>b[i].y ){
- ymax = b[i].y;
- flag2 = i;
- }
- }
- bmid = b[ flag2 ];
- //input
- double aYmin = min( a[].y,a[n1-].y );
- double bYmin = min( b[].y,b[n2-].y );
- //printf("aYmin = %lf bYmin = %lf\n",aYmin,bYmin);
- double abYmax = max( aYmin,bYmin );
- double abYmin = min( amid.y,bmid.y );
- double L ,R ;
- //printf("L = %lf , R = %lf \n",L,R);
- int special = -;
- if( aYmin<=bmid.y )//a is lower
- {
- special = ;
- }
- else if( bYmin<=amid.y )
- {
- special = ;
- }
- if( special==- ){
- L = abYmin;
- R = min( aYmin,bYmin );
- while( L<R ){
- double mid = (L+R)/2.0;
- double sumArea = ;
- /*******solve b******/
- //printf("mid = %lf\n",mid);
- if( mid>bYmin ){
- int cnt = ;
- double newY = bYmin;
- int f = -;
- for( int i=;i<n2;i++ ){
- if( b[i].y<=newY ){
- res[ cnt++] = b[ i ];
- f = i;
- }
- else break;
- }
- if( f==- ){}
- else{
- Point tmp;
- tmp.y = newY;
- tmp.x = (b[ f+ ].x-b[ f ].x)*(newY-b[f].y)/(b[f+].y-b[f].y) + b[f].x;
- res[ cnt++ ] = tmp;
- }
- sumArea += area( res,cnt );
- }
- else if( mid<=bmid.y ){}
- else{
- //printf("here\n");
- int cnt = ;
- int f = -;
- for( int i=;i<n2;i++ ){
- if( b[i].y<=mid ){
- f = i;
- break;
- }
- }
- //printf("f = %d\n",f);
- Point tmp;
- tmp.y = mid;
- tmp.x = b[f].x-( (b[f].x-b[f-].x)*(mid-b[f].y)/(b[f-].y-b[f].y) );
- res[ cnt++] = tmp;
- for( int i=f;i<n2;i++ ){
- if( b[i].y<mid ){
- res[ cnt++ ] = b[i];
- f = i;
- }
- else break;
- }
- tmp.y = mid;
- tmp.x = (b[ f+ ].x-b[ f ].x)*(mid-b[f].y)/(b[f+].y-b[f].y) + b[f].x;
- res[ cnt++ ] = tmp;
- //printf("cnt = %d\n",cnt);
- sumArea += area( res,cnt );
- }
- //printf("sumarea = %lf \n",sumArea);
- /********solve a *****/
- if( mid>aYmin ){
- int cnt = ;
- double newY = aYmin;
- int f = -;
- for( int i=;i<n1;i++ ){
- if( a[i].y<=newY ){
- res[ cnt++] = a[ i ];
- f = i;
- }
- else break;
- }
- if( f==- ){}
- else{
- Point tmp;
- tmp.y = newY;
- tmp.x = (a[ f+ ].x-a[ f ].x)*(newY-a[f].y)/(a[f+].y-a[f].y) + a[f].x;
- res[ cnt++ ] = tmp;
- }
- sumArea += area( res,cnt );
- }
- else if( mid<=amid.y ){}
- else{
- int cnt = ;
- int f = -;
- for( int i=;i<n1;i++ ){
- if( a[i].y<=mid ){
- f = i;
- break;
- }
- }
- Point tmp;
- tmp.y = mid;
- tmp.x = a[f].x-( (a[f].x-a[f-].x)*(mid-a[f].y)/(a[f-].y-a[f].y) );
- res[ cnt++] = tmp;
- for( int i=f;i<n1;i++ ){
- if( a[i].y<mid ){
- res[ cnt++ ] = a[i];
- f = i;
- }
- else break;
- }
- tmp.y = mid;
- tmp.x = (a[ f+ ].x-a[ f ].x)*(mid-a[f].y)/(a[f+].y-a[f].y) + a[f].x;
- res[ cnt++ ] = tmp;
- sumArea += area( res,cnt );
- }
- //printf("sumarea2 = %lf\n\n\n",sumArea);
- if( fabs(sumArea-aim)<=eps ){
- ansY = mid;
- break;
- }
- else if( sumArea>aim ){
- R = mid-eps;
- }
- else {
- L = mid+eps;
- ansY = mid;
- }
- }
- }//ab可能都同时都有水
- else{
- //printf("special = %d\n",special);
- double sumArea = ;
- if( special== ){//‘1’表示只有a会有水
- double L = amid.y;
- double R = aYmin;
- while( L<R ){
- double mid = (L+R)/2.0;
- //printf("mid = %lf\n",mid);
- int cnt = ;
- int f = -;
- for( int i=;i<n1;i++ ){
- if( a[i].y<=mid ){
- f = i;
- break;
- }
- }
- Point tmp;
- tmp.y = mid;
- tmp.x = a[f].x-( (a[f].x-a[f-].x)*(mid-a[f].y)/(a[f-].y-a[f].y) );
- res[ cnt++] = tmp;
- for( int i=f;i<n1;i++ ){
- if( a[i].y<mid ){
- res[ cnt++ ] = a[i];
- f = i;
- }
- else break;
- }
- tmp.y = mid;
- tmp.x = (a[ f+ ].x-a[ f ].x)*(mid-a[f].y)/(a[f+].y-a[f].y) + a[f].x;
- res[ cnt++ ] = tmp;
- sumArea += area( res,cnt );
- //printf("cnt = %d\n",cnt);
- //printf("sumarea = %lf\n",sumArea);
- if( fabs(sumArea-aim)<=eps ){
- ansY = mid;
- break;
- }
- else if( sumArea>aim ) {
- R = mid-eps;
- }
- else {
- L = mid + eps;
- ansY = L;
- }
- }
- }
- else{//'2'表示只有b会有水
- double L = bmid.y;
- double R = bYmin;
- //printf("L = %lf,R = %lf\n",L,R);
- while( L<R ){
- double mid = (L+R)/2.0;
- //printf("mid = %lf\n",mid);
- int cnt = ;
- int f = -;
- for( int i=;i<n2;i++ ){
- if( b[i].y<=mid ){
- f = i;
- break;
- }
- }
- Point tmp;
- tmp.y = mid;
- tmp.x = b[f].x-( (b[f].x-b[f-].x)*(mid-b[f].y)/(b[f-].y-b[f].y) );
- res[ cnt++] = tmp;
- for( int i=f;i<n2;i++ ){
- if( b[i].y<mid ){
- res[ cnt++ ] = b[i];
- f = i;
- //printf("add : i = %d\n",i);
- }
- else break;
- }
- tmp.y = mid;
- tmp.x = (b[ f+ ].x-b[ f ].x)*(mid-b[f].y)/(b[f+].y-b[f].y) + b[f].x;
- res[ cnt++ ] = tmp;
- //printf("cnt = %d\n",cnt);
- sumArea += area( res,cnt );
- if( fabs(sumArea-aim)<=eps ){
- ansY = mid;
- break;
- }
- else if( sumArea>aim ) {
- R = mid-eps;
- }
- else {
- L = mid + eps;
- ansY = L;
- }
- }
- }
- }
- printf("%.3lf\n",ansY);
- }
- return ;
- }
EOJ-1708//POJ3334的更多相关文章
- BZOJ 1708: [Usaco2007 Oct]Money奶牛的硬币( dp )
背包dp.. -------------------------------------------------------------------------------- #include< ...
- BZOJ 1708: [Usaco2007 Oct]Money奶牛的硬币
1708: [Usaco2007 Oct]Money奶牛的硬币 Description 在创立了她们自己的政权之后,奶牛们决定推广新的货币系统.在强烈的叛逆心理的驱使下,她们准备使用奇怪的面值.在传统 ...
- 1708: [Usaco2007 Oct]Money奶牛的硬币
1708: [Usaco2007 Oct]Money奶牛的硬币 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 544 Solved: 352[Submi ...
- EOJ Monthly 2019.2 题解(B、D、F)
EOJ Monthly 2019.2 题解(B.D.F) 官方题解:https://acm.ecnu.edu.cn/blog/entry/320/ B. 解题 单测试点时限: 2.0 秒 内存限制: ...
- EOJ #276
题面 感觉是个套路题,不是特别难(然而卡常 直接做不可做,改成算每个数的贡献 暴力的想法是容斥,即记录每个数在每行里的出现情况,从总方案中扣掉每一行都没选到这个数的方案,复杂度$O(n^3)$ 我们发 ...
- EOJ Monthly 2018.8 D. Delivery Service-树上差分(边权/边覆盖)(边权转点权)(模板题)
D. Delivery Service 单测试点时限: 2.5 秒 内存限制: 512 MB EOJ Delivery Service Company handles a massive amount ...
- EOJ Problem #3249 状态压缩+循环周期+反向递推
限量供应 Time limit per test: 4.0 seconds Time limit all tests: 4.0 seconds Memory limit: 256 megabytes ...
- EOJ Monthly 2018.7
准备继续大学acm啦 又要开始愉快的码码码啦 第一次在华东师大OJ上面做题 看来EOJ上的积分体质是假的,我怎么一把上红??? A.数三角形 神tm的防AK题放在A,出题人很不友好啊... 先写了个暴 ...
- EOJ Monthly 2018.4
A. ultmaster 的小迷妹们 Time limit per test: 2.0 seconds Memory limit: 256 megabytes ultmaster 男神和他的小迷妹们准 ...
- EOJ Monthly 2018.4 (E.小迷妹在哪儿(贪心&排序&背包)
ultmaster 男神和小迷妹们玩起了捉迷藏的游戏. 小迷妹们都希望自己被 ultmaster 男神发现,因此她们都把自己位置告诉了 ultmaster 男神,因此 ultmaster 男神知道了自 ...
随机推荐
- MyEclipse SVN 插件
一.下载SVN插件subclipse 下载地址:http://subclipse.tigris.org/servlets/ProjectDocumentList?folderID=2240 在打开的网 ...
- 第五篇、微信小程序-swiper组件
常用属性: 效果图: swiper.wxml添加代码: <swiper indicator-dots="{{indicatorDots}}" autoplay="{ ...
- HTML+CSS学习笔记(1) - Html介绍
HTML+CSS学习笔记(1) - Html介绍 1.代码初体验,制作我的第一个网页 <!DOCTYPE HTML> <html> <head> <meta ...
- Exploit搭建
1,三连下小水管真是慢.去洗澡先. 2,环境变量Path里添加Python安装目录.直接cd到git下来的目录运行sqlmap.py 更新sqlmap,sqlmap.py –update 或 git ...
- 引用、return
C语言中没有引用,引用(reference)是c++对c语言的重要扩充.通俗点说,引用就是“起别名”.比如变量data,和它的引用 RefData.虽然名字不同,但是操作他们的时候,都操作的是相同的内 ...
- GDB 进行调试 使用心得
GDB 进行调试 使用心得 转 1: 对于在应用程序中加入参数进行调试的方法: 直接用 gdb app -p1 -p2 这样进行调试是不行的. 需要像以下这样使用: #gdb app ...
- 在.NET连接MySQL以及封装好的MySQLHelper.cs
1.首先上MySQL网站下驱动:http://www.mysql.com/products/connector/ 2.安装下载的安装包 3.我们在Visual Studio里创建一个Web Appli ...
- 长安CS15_手动——16款
一.输入数据 1.CAN总线描述:位置,颜色,速率,总线类型 1)位置:OBD 2)颜色:3) 速率:500k 4)总线类型:HSCAN 5)测试时间:2016.5.4 2.车辆特征 1)排量:1.5 ...
- mysql 的 存储结构(储存引擎)
1 MyISAM:这种引擎是mysql最早提供的.这种引擎又可以分为静态MyISAM.动态MyISAM 和压缩MyISAM三种: 静态MyISAM:如果数据表中的各数据列的长度都是预先固定好的, ...
- 统计网卡TX(发送)RX(接受)流量脚本
显示网卡流量的方法蛮多,一般我们可以通过dstat来查看,但dstat不一定所有的机器都有安装.而我们知道,通过ifconfig可以看到某一网卡发送与接收的字节数,所以我们可以写一个脚本来统计一下. ...