zoukankan      html  css  js  c++  java
  • CodeForces 163B Lemmings 二分

    Lemmings

    题目连接:

    http://codeforces.com/contest/163/problem/B

    Descriptionww.co

    As you know, lemmings like jumping. For the next spectacular group jump n lemmings gathered near a high rock with k comfortable ledges on it. The first ledge is situated at the height of h meters, the second one is at the height of 2h meters, and so on (the i-th ledge is at the height of i·h meters). The lemmings are going to jump at sunset, and there's not much time left.

    Each lemming is characterized by its climbing speed of vi meters per minute and its weight mi. This means that the i-th lemming can climb to the j-th ledge in minutes.

    To make the jump beautiful, heavier lemmings should jump from higher ledges: if a lemming of weight mi jumps from ledge i, and a lemming of weight mj jumps from ledge j (for i < j), then the inequation mi ≤ mj should be fulfilled.

    Since there are n lemmings and only k ledges (k ≤ n), the k lemmings that will take part in the jump need to be chosen. The chosen lemmings should be distributed on the ledges from 1 to k, one lemming per ledge. The lemmings are to be arranged in the order of non-decreasing weight with the increasing height of the ledge. In addition, each lemming should have enough time to get to his ledge, that is, the time of his climb should not exceed t minutes. The lemmings climb to their ledges all at the same time and they do not interfere with each other.

    Find the way to arrange the lemmings' jump so that time t is minimized.

    Input

    The first line contains space-separated integers n, k and h (1 ≤ k ≤ n ≤ 105, 1 ≤ h ≤ 104) — the total number of lemmings, the number of ledges and the distance between adjacent ledges.

    The second line contains n space-separated integers m1, m2, ..., mn (1 ≤ mi ≤ 109), where mi is the weight of i-th lemming.

    The third line contains n space-separated integers v1, v2, ..., vn (1 ≤ vi ≤ 109), where vi is the speed of i-th lemming.

    Output

    Print k different numbers from 1 to n — the numbers of the lemmings who go to ledges at heights h, 2h, ..., kh, correspondingly, if the jump is organized in an optimal way. If there are multiple ways to select the lemmings, pick any of them.

    Sample Input

    5 3 2

    1 2 3 2 1

    1 2 1 2 10

    Sample Output

    5 2 4

    Hint

    题意

    给你n个袋鼠,然后袋鼠要跳楼梯,你需要选出k个袋鼠出来,跳k个楼梯

    第一个楼梯的高度为h,第二个为2h,第三个为3h,第n个为nh

    每个袋鼠有两个属性,体重和速度,要求如果i的体重大于j的话,i只能跳比j高的楼梯

    你需要使得k个袋鼠跳的最慢的袋鼠的时间最小,然后让你把方案输出

    题解:

    二分最后的时间,然后贪心的去选就好了

    袋鼠按照体重为第一关键字,速度第二关键字从小到大排序

    贪心去选

    注意:精度有毒,最好就不要用eps这玩意儿。。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 1e6;
    pair<pair<int,int>,int>p[maxn];
    int ans[maxn];
    int n,k,h;
    int check(double x)
    {
        int tot = 1;
        for(int i=1;i<=n;i++)
        {
            if(1.0*tot*h<=p[i].first.second*x)
            {
                ans[tot]=p[i].second;
                tot++;
                if(tot>k)return 1;
            }
        }
        return 0;
    }
    int main()
    {
        scanf("%d%d%d",&n,&k,&h);
        for(int i=1;i<=n;i++)
            scanf("%d",&p[i].first.first);
        for(int i=1;i<=n;i++)
            scanf("%d",&p[i].first.second);
        for(int i=1;i<=n;i++)
            p[i].second=i;
        sort(p+1,p+1+n);
        double l = 0.0,r = 1000000000.0;
        for(int i=1;i<=100;i++)
        {
            double mid = (l+r)/2.0;
            if(check(mid))r=mid;
            else l=mid;
        }
        check(r);
        for(int i=1;i<=k;i++)
            printf("%d ",ans[i]);
        printf("
    ");
    }
  • 相关阅读:
    Android 绑定Service的实现方法二:使用Messenger
    Android 利用SurfaceView进行图形绘制
    Android 垂直SeekBar
    Android Camera(一) 调用系统相机应用
    Android Camera(二) Camera程序编写
    算法题009 电梯调度算法
    Git基础使用教程:第一个Git项目
    Android上的GPS程序报错:Fail to find provider info for com.google.android.gsf.gservices
    JUnit4:多组数据的单元测试:用JUnit4做参数化测试
    Git基础:添加与提交
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5149368.html
Copyright © 2011-2022 走看看