ZOJ 3913 Bob wants to pour water

ZOJ Monthly, October 2015 K题

二分答案+验证

#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<math.h>
using namespace std;

const double pi=3.1415926535898;
const int maxn=100000+10;
struct cuboids
{
    double z;
    double width,length,height;
}c[maxn];
struct sphere
{
    double r;
    double z;
}s[maxn];
double W,L,V;
int T,m,n;
double Min,Max,Mid;
double qiu(double r1,double h)
{
    return pi/6*h*(3*(r1*r1+r1*r1-h*h)+h*h);
}
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lf%lf%lf",&W,&L,&V);
        scanf("%d%d",&m,&n);
        double vNow=0;
        for(int i=1;i<=m;i++)
            scanf("%lf%lf%lf%lf",&c[i].z,&c[i].width,&c[i].length,&c[i].height);
        for(int i=1;i<=n;i++)
            scanf("%lf%lf",&s[i].z,&s[i].r);

        Min=0;
        Max=V;
        for(int i=1;i<=m;i++)
            Max=Max+c[i].width*c[i].length*c[i].height;
        for(int i=1;i<=n;i++)
            Max=Max+4.0/3.0*pi*s[i].r*s[i].r*s[i].r;
        Max=Max/(W*L);
        Mid=(Min+Max)/2.0;
        int t=500;
        while(t--)
        {
            vNow=W*L*Mid;

            for(int i=1;i<=m;i++)
            {
                if(c[i].z-c[i].height/2>=Mid)
                    continue;
                else if(c[i].z+c[i].height/2<=Mid)
                    vNow=vNow-c[i].width*c[i].length*c[i].height;
                else
                    vNow=vNow-c[i].width*c[i].length*(Mid-(c[i].z-c[i].height/2));
            }
            for(int i=1;i<=n;i++)
            {
                if(Mid<=s[i].z-s[i].r) continue;
                else if(Mid>=s[i].z+s[i].r)
                    vNow=vNow-4.0/3.0*pi*s[i].r*s[i].r*s[i].r;
                else if(Mid>s[i].z-s[i].r&&Mid<=s[i].z)
                {
                    vNow-=pi*s[i].r*s[i].r*s[i].r*4/3/2;
                    vNow+=qiu(s[i].r,s[i].z-Mid);
                }
                else
                {
                    vNow-=pi*s[i].r*s[i].r*s[i].r*4/3/2;
                    vNow-=qiu(s[i].r,Mid-s[i].z);
                }
            }
            if(Max-Mid<1e-8) break;
            if(vNow>V)
            {
                Max=Mid;
                Mid=(Min+Max)/2.0;
            }
            else
            {
                Min=Mid;
                Mid=(Min+Max)/2.0;
            }
        }
        printf("%.6lf\n",Mid);
    }
    return 0;
}
时间: 2024-07-29 15:19:02

ZOJ 3913 Bob wants to pour water的相关文章

[LeetCode] Pour Water 倒水

We are given an elevation map, heights[i] representing the height of the terrain at that index. The width at each index is 1. After V units of water fall at index K, how much water is at each index? Water first drops at index K and rests on top of th

zoj 2974 Just Pour the Water矩阵快速幂

Just Pour the Water Time Limit: 2 Seconds      Memory Limit: 65536 KB Shirly is a very clever girl. Now she has two containers (A and B), each with some water. Every minute, she pours half of the water in A into B, and simultaneous pours half of the

ZOJ 1973 Just Pour the Water(矩阵快速幂)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1973 Shirly is a very clever girl. Now she has two containers (A and B), each with some water. Every minute, she pours half of the water in A into B, and simultaneous pours half of the w

[dp] zoj 3740 Water Level

题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5122 Water Level Time Limit: 2 Seconds      Memory Limit: 65536 KB Hangzhou is a beautiful city, especially the West Lake. Recently, the water level of the West Lake got lower and lower

Leetcode: Water and Jug Problem &amp;&amp; Summary: GCD求法(辗转相除法 or Euclidean algorithm)

You are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactly z litres using these two jugs. If z liters of water is measurable, you must

ZOJ 5579 Stean

Stean Time Limit: 1 Second      Memory Limit: 65536 KB      Special Judge Tom is good at making stean, he can make steans of various color and shape. Now he want to know how many water it can contain, and how many material he need to making a stean.

【leetcode】365. Water and Jug Problem

题目描述: You are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactly zlitres using these two jugs. Operations allowed: Fill any of the jugs

365. Water and Jug Problem

You are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactly z litres using these two jugs. If z liters of water is measurable, you must

ZOJ Monthly, July 2012

zoj 3622.Magic Number   水题 先找规律生成区间[1,1<<32-1]内的所有Magic Number,计算出来只有40多个,然后就随便YY了. void init() { int a[5] = { 1,2,5,25,125 }; ll Max = (1ll<<32)-1; for(ll tmp =1; tmp<=Max; tmp *=10) { for(int i=0; i<5; ++i){ ll t = tmp * a[i]; if(t>