本文主要是介绍十四届蓝桥杯 冶炼金属(二分 / 公式),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
二分代码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;
}
这篇关于十四届蓝桥杯 冶炼金属(二分 / 公式)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!