牛客小白月赛12 392
E 签到题 二分答案
#include <iostream> #include <cstring> #include <cstdio> #include <string> #include <queue> #include <list> #include <map> #include <set> #include <cmath> #include <bitset> #include <vector> #include <iomanip> #include <sstream> #include <cstdlib> #include <algorithm> using namespace std; typedef long long ll; #define mem(A, X) memset(A, X, sizeof A) #define foreach(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e) #define fori(i,l,u) for(ll (i)=(ll)(l);(i)<=(ll)(u);++(i)) #define ford(i,l,u) for(ll (i)=(ll)(l);(i)>=(ll)(u);--(i)) ll n,k; int a[200005]; bool check(int len){ ll cnt=0; fori(i,1,n) cnt+=a[i]/len; return cnt>=k; } void solve(){ int l=0,r=1e9+10; //符和(某种情况)的最大值 while(l<r) { int m=(l+r+1)/2; if(check(m)) l=m; else r=m-1; } cout<<l<<endl; } int main() { ios::sync_with_stdio(false); //freopen("local.in","r",stdin); while(cin>>n>>k){ fori(i,1,n) cin>>a[i]; solve(); } return 0; }
G 可以证明,答案是gcd(n,m)
#include <iostream> #include <cstring> #include <cstdio> #include <string> #include <queue> #include <list> #include <map> #include <set> #include <cmath> #include <bitset> #include <vector> #include <iomanip> #include <sstream> #include <cstdlib> #include <algorithm> using namespace std; typedef long long ll; #define mem(A, X) memset(A, X, sizeof A) #define foreach(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e) #define fori(i,l,u) for(ll (i)=(ll)(l);(i)<=(ll)(u);++(i)) #define ford(i,l,u) for(ll (i)=(ll)(l);(i)>=(ll)(u);--(i)) ll gcd(ll x, ll y){ return y? gcd(y,x%y) : x;} ll a,b; string s; int main() { ios::sync_with_stdio(false); //freopen("local.in","r",stdin); while(cin>>a>>b>>s){ cout<<gcd(a,b)<<endl; } return 0; }