zoukankan      html  css  js  c++  java
  • C

    ceil有毒啊。。用ceil一直错。

    思路就是模拟吧,设当前的答案是ansx和ansy。

    如果比例是小于ansx的,那么就要乘以一个倍数k1,使得a * k1 >= ansx的。

    所以就用ceil(ansx / a)嘛。。然后一直wa。

    ansy的同理,最后选一个倍数大的去乘就行了。

    搞不清楚为什么用ceil会wa

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    #define inf (0x3f3f3f3f)
    typedef long long int LL;
    
    #include <iostream>
    #include <sstream>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <string>
    
    void work() {
        int n;
        cin >> n;
        LL ansx = 1, ansy = 1;
        for (int i = 1; i <= n; ++i) {
            LL a, b;
            cin >> a >> b;
            LL k1 = 1;
            if (a < ansx) {
    //            k1 = max(k1, (LL)ceil(1.0 * ansx / a)); ceil有毒?
                k1 = ansx / a;
                if (ansx % a != 0) k1++;
            }
            if (b < ansy) {
    //            k1 = max(k1, (LL)ceil(1.0 * ansy / b));
                LL t = ansy / b;
                if (ansy % b != 0) t++;
                k1 = max(k1, t);
            }
            ansx = a * k1;
            ansy = b * k1;
        }
        cout << ansx + ansy << endl;
    }
    
    int main() {
    #ifdef local
        freopen("data.txt","r",stdin);
    #endif
        work();
        return 0;
    }
    View Code
  • 相关阅读:
    xml配置文件使用-读取、转换
    .NET 4.0 缓存
    jQuery分页插件pagination.js 笔记
    Spring源码
    Shell编程(字符串篇)
    Linux DNS 相关
    Shell将命令执行结果写入文件
    Linux安装GCC
    Linux网络安全
    产品经理基础
  • 原文地址:https://www.cnblogs.com/liuweimingcprogram/p/5965496.html
Copyright © 2011-2022 走看看