首页 > 代码库 > C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report

C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report

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

 

C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report