zoukankan      html  css  js  c++  java
  • poj 3863&&Gym

    题意:给你 m 个电梯,每个电梯有两个按钮, u 和 d ,分别代表上 u 层,和下 d 层,每一次你都从第0层开始做电梯,你可以按这个电梯按钮 m 次,假设楼层无限高,问你可以到达的最低楼层是多少,0层除外?

    思路:

    我们假设按 上走 x 次, 那么下走为 (n-x) 次

    那么可以到达的楼层为 k = a*x - b*(n-x)

    另上式等于0,我们可以得到当 x'= b*n/(a+b) 时为第0层

    由于 x 必须为正整数,我们对 x' 向上取整,就得到可以到达的最低楼层

    但是现在有一个漏洞,如果 x' 就是一个正整数,那么我们向上取整后还是x'本身 

    遇到这种情况此时的x'=x'+1,也就是说我们就多上一层少下一层,就能避开到达0层了

    代码:

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <string>
    #include <map>
    #include <set>
    #include <queue>
    #include <deque>
    #include <list>
    #include <bitset>
    #include <stack>
    #define lowbit(x) (x&-x)
    using namespace std;
    int main()
    {
        freopen("business.in","r",stdin);
        freopen("business.out","w",stdout);
        long long n,m;
        while( cin>>n>>m)
        {
            long long ans = 0x3f3f3f3f3f;
            while(m--)
            {
                long long a,b;
                cin>>a>>b;
                double tmp = b*n*1.0/(a+b);
                long long x = ceil(tmp);
                long long fuck = a*x-b*(n-x);
                if(fuck==0) fuck = a*(x+1)-b*(n-x-1);
                ans=min(ans,fuck);
            }
            cout<<ans<<endl;
        }
        return 0;
    }
  • 相关阅读:
    自学Linux命令的四种方法
    linux命令学习
    设计师提高效率必备的10大在线工具
    基于CNN网络的汉字图像字体识别及其原理
    字库的产生
    开篇
    智能建筑系统集成发展目标——节能建筑
    建筑节能案例解析:拜尔的生态幼儿园
    能源管理系统(Synchro EMS)技术架构
    能源管理系统(Synchro EMS)
  • 原文地址:https://www.cnblogs.com/simplekinght/p/6679869.html
Copyright © 2011-2022 走看看