标签:ring view nbsp blog gif one type algorithm end
题意是这样的有n个同学做游戏(Mafia),在一轮游戏中有一名同学不会参加(当监护人),给出
每名同学想要参与的次数,求最少要进行的游戏的轮数,设想要参与的最多的游戏次数为maxx,则ans一定大于或等于maxx,
对maxx-a[i]求和res,当数值res>=maxx是满足,如果maxx++的话会TLE,所以二分maxx
1 # include <cstdio> 2 # include <iostream> 3 # include <cstring> 4 # include <algorithm> 5 using namespace std; 6 7 typedef long long LL; 8 const int maxn=1e5+5,INF=0x7fffffff; 9 LL a[maxn]; 10 int n; 11 LL maxx; 12 13 bool C(LL x){ 14 LL sum=0; 15 for(int i=1;i<=n;i++) 16 sum+=(x-a[i]); 17 return sum>=x; 18 } 19 20 int main(){ 21 while(scanf("%d",&n)!=EOF){ 22 maxx=0; 23 for(int i=1;i<=n;i++) { 24 scanf("%I64d",&a[i]); 25 maxx=max(maxx,a[i]); 26 } 27 LL ls=maxx-1,rs=INF; 28 while(rs-ls>1){ 29 LL mid=(ls+rs)/2; 30 //cout<<mid<<endl; 31 if(C(mid)) rs=mid; 32 else ls=mid; 33 } 34 printf("%I64d\n",rs); 35 } 36 return 0; 37 }
标签:ring view nbsp blog gif one type algorithm end
原文地址:http://www.cnblogs.com/lintanxi/p/7135930.html