P8647 [蓝桥杯 2017 省 AB] 分巧克力

P8647 [蓝桥杯 2017 省 AB] 分巧克力_第1张图片

#include 

#define endl '\n'
using ll = long long;
typedef unsigned long long ull;
using namespace std;
void GordenGhost();
int n,k,m=0;
vectora,b;
bool cmp(int x){
    int sum=0;
    for (int i = 0; i < n; ++i) {
        sum+=(a[i]/x)*(b[i]/x);
    }
    return sum>=k;
}
signed main() {
#ifdef Gorden
    freopen("in.txt", "rt", stdin);
    freopen("out.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    GordenGhost();
    return 0;
}

void GordenGhost() {
    cin>>n>>k;
    for (int i = 0; i < n; ++i) {
        int o,l;
        cin>>o>>l;
        m= max(m, max(o,l));
        a.push_back(o);
        b.push_back(l);
    }
    int l=1,r=m;
    while (l>1;
        if (cmp(mid)){
            l=mid;
        }else{
            r=mid-1;
        }
    }
    cout<

你可能感兴趣的:(蓝桥杯,c++,二分,算法)