Pie[二分]

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Qer_computerscience/article/details/77601097

题意:过生日大家分饼吃?m+1个人分饼,每个人要分一样的面积(高度为1),饼可以切但是不能拼。问最大能人均多少。
思路:二分面积就好啦。先算出每个饼的面积,由于check需要O(n)复杂度,所以套一层二分面积就好。
二分的单调性: 如果能够均分每人得到S的饼,那么对于任意的Si<S都满足能够分得。
二分的 check(mid):对于给定的均分量mid,看每个饼能出几份,然后加起来看是否大于等于m+1即可。

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<cstdlib>
#include<list>
#include<stack>
#include<cmath>
#include<iomanip>
using namespace std;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
void debug() {cout << "ok running!" << endl;}
const double PI = acos(-1.0);
int n, m;
double a[10005];
bool check(double x)
{
    int sum = 0;
    for(int i = 0; i < n; ++i)
        sum += (int)(a[i]/x);
    if(sum >= m)
        return 1;
    else return 0;
}
int main()
{
    ios::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif // ONLINE_JUDGE
    int t;
    cin >> t;
    while(t--)
    {
        cin >> n >> m;
        m++;
        for(int i = 0; i < n; ++i)
        {
             int x;
             cin >> x;
             a[i] = x*x*PI;
        }
        //cout << a[0] << endl;
        double l = 0, r = 10005*10005*PI;
        double ans = -1;
        while(r - l > 0.000001)
        {
            //cout << l << " " << r << endl;
            double mid = (l+r)/2;
            //cout << mid << endl;
            if(check(mid))
            {
                ans = mid;
                l = mid;
            }
            else r = mid;
        }
        ios::fixed;
        //cout << ans << endl;
        cout << fixed << setprecision(4) << ans << endl;
    }
    return 0;
}
展开阅读全文

pie

10-20

DescriptionnMy birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of them gets a piece of pie. This should be one piece of one pie, not several small pieces since that looks messy. This piece can be one whole pie though. nnMy friends are very annoying and if one of them gets a bigger piece than the others, they start complaining. Therefore all of them should get equally sized (but not necessarily equally shaped) pieces, even if this leads to some pie getting spoiled (which is better than spoiling the party). Of course, I want a piece of pie for myself too, and that piece should also be of the same size. nnWhat is the largest possible piece size all of us can get? All the pies are cylindrical in shape and they all have the same height 1, but the radii of the pies can be different. n nInputnOne line with a positive integer: the number of test cases. Then for each test case: n---One line with two integers N and F with 1 <= N, F <= 10 000: the number of pies and the number of friends. n---One line with N integers ri with 1 <= ri <= 10 000: the radii of the pies. n nOutputnFor each test case, output one line with the largest possible volume V such that me and my friends can all get a pie piece of size V. The answer should be given as a floating point number with an absolute error of at most 10^(-3).n nSample Inputn3n3 3n4 3 3n1 24n5n10 5n1 4 2 3 4 5 6 5 4 2n nSample Outputn25.1327n3.1416n50.2655 问答

Pie

11-12

Problem DescriptionnMy birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of them gets a piece of pie. This should be one piece of one pie, not several small pieces since that looks messy. This piece can be one whole pie though.nnMy friends are very annoying and if one of them gets a bigger piece than the others, they start complaining. Therefore all of them should get equally sized (but not necessarily equally shaped) pieces, even if this leads to some pie getting spoiled (which is better than spoiling the party). Of course, I want a piece of pie for myself too, and that piece should also be of the same size. nnWhat is the largest possible piece size all of us can get? All the pies are cylindrical in shape and they all have the same height 1, but the radii of the pies can be different.nInputnOne line with a positive integer: the number of test cases. Then for each test case:n---One line with two integers N and F with 1 <= N, F <= 10 000: the number of pies and the number of friends.n---One line with N integers ri with 1 <= ri <= 10 000: the radii of the pies.nOutputnFor each test case, output one line with the largest possible volume V such that me and my friends can all get a pie piece of size V. The answer should be given as a floating point number with an absolute error of at most 10^(-3).nSample Inputn3n3 3n4 3 3n1 24n5n10 5n1 4 2 3 4 5 6 5 4 2nSample Outputn25.1327n3.1416n50.2655 问答

Pie Bridge

08-23

It is the Valentine's day! Yue Lao decides to have a meeting for the magpies to construct the pie bridge(magpie bridge). There are N magpies in the sky. In order to hold a meeting, Yue Lao should make all the magpies at the same place in the same time.nnA magpie can be consider as a dot in the 2d-plane. Initially, all the magpies stay still in some place. The only instruction Yue Lao can do is to push a magpie. Yue Lao can push a magpie in any direction. After Yue Lao pushs a magpie, the magpie starts moving in that direction with a constant speed. Yue Lao's power is limited, so there is a limit for the speed of the magpie: the horizontal speed can't exceed vx and the vertical speed can't exceed vy.nnYue Lao can push a magpie at most once. Besides, Yue Lao can't push magpies too often. After a push, he needs to rest at least t seconds for the next push. When two magpies meet at the same point, they will not collide with each other and will stay moving or stay still.nnNow the question is, what is the minumum time it needs to take for Yue Lao to achieve his goal (make all the magpies moves to the same place at the same time)?nnInputnnThere are multiple test cases. There are two parts for each case. The first part is one line with four integers N, vx, vy and t (2 <= N <= 9, 0 < vx, vy <= 100, 0 <= t <= 100), represent the number of magpies, the horizontal speed limit, the vertical speed limit, and the time interval Yue Lao needs to rest between two pushes. The second part consists with N lines. Each line consists of two integers xi and yi (-1000000 <= xi, yi <= 1000000), represent the coordinate for the ith magpie. There will not be two different magpies in the same point initially.nnOutputnnThe output of each test case should be a single line, the minimum time for Yue Lao to achieve his goal. All result that have relative or absolute error less than 1E-6 will be accepted.nnSample Inputnn2 1 1 1n0 0n0 7nSample Outputnn4.000000000000000 问答

没有更多推荐了,返回首页