二分代码1:
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;int get(int a, int b){int l=1;r=1e9+1;while(l<r){int mid = l+r >>1;if(a / mid <= b){r = mid;}else l = mid + 1;}return l;
} int main()
{int n;scanf("%d",&n);int minn = 1,maxx = 1e9;while(n--){int a,b;scanf("%d%d",&a,&b);minn = max(minn,get(a,b));maxx = min(maxx,get(a,b-1) - 1);}cout<<minn<<" "<<maxx<<endl;return 0;
}
误打误撞代码2:
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n;//设最小是minn,最大是maxx,最大的情况就是除,一个也没浪费 int v[10010];int x[10010];int minn = -1;int maxx = 1000000000;
int main()
{scanf("%d",&n);for(int i = 0;i < n; i ++){scanf("%d%d",&v[i],&x[i]);maxx = min(v[i]/x[i], maxx); minn = max(v[i]/(x[i]+1)+1, minn);}//cout<<xx<<" "<<vv<<endl; cout<<minn<<" "<<maxx<<endl;return 0;
}