标签:
Time Limit: 20 Sec
Memory Limit: 256 MB
http://codeforces.com/gym/100637/problem/F
A new swimming pool has been built in Kazan for the forthcoming Water Sports World Championship. The pool has N lanes. Some of the lanes are already occupied by swimmers. Tatar scientists have divided the lanes into the lucky and unlucky ones. The unlucky lanes are those with the maximum amount of swimmers. That is, there is no other lane where there would be more swimmers than on unlucky one. The unlucky lanes make swimmers unhappy. The rest of the lanes are considered to be lucky. The lucky lanes make people happy. The scientists took a decision to make more people happy. In order to do this they had an agreement with the pool manager saying they can move a single person from any lane to the one neighboring if it was necessary. The swimmer from the first lane can only be moved to the second lane, and the swimmer from the last lane –– to the one before last.
Input
The first line contains an integer N — the amount of lanes in the pool (3 ≤ N ≤ 105). The second line contains N integers pi separated with spaces, describing distribution of swimmers between the lanes where pi is the amount of swimmers on i-th lane (0 ≤ pi ≤ 105).
Output
Output a single number — minimal possible number of unhappy swimmers.
Sample Input
3
1 3 5
Sample Output
5
题意
泳池,人最多的不快乐,可以将一个人随意移动到相邻泳池,问不快乐的人最少是多少
题解:
我只能说考虑多种情况,暴力就好
代码
1 #include <cstdio> 2 #include <cmath> 3 #include <cstring> 4 #include <ctime> 5 #include <iostream> 6 #include <algorithm> 7 #include <set> 8 #include <vector> 9 #include <sstream> 10 #include <queue> 11 #include <typeinfo> 12 #include <fstream> 13 #include <map> 14 #include <stack> 15 typedef __int64 ll; 16 using namespace std; 17 inline ll read() 18 { 19 ll x=0,f=1; 20 char ch=getchar(); 21 while(ch<‘0‘||ch>‘9‘) 22 { 23 if(ch==‘-‘)f=-1; 24 ch=getchar(); 25 } 26 while(ch>=‘0‘&&ch<=‘9‘) 27 { 28 x=x*10+ch-‘0‘; 29 ch=getchar(); 30 } 31 return x*f; 32 } 33 //************************************************************************************** 34 int hash[200005]; 35 int n; 36 ll a[200005]; 37 int main() 38 { 39 40 scanf("%d",&n); 41 for(int i=1; i<=n; i++) 42 { 43 scanf("%I64d",&a[i]); 44 hash[a[i]]++; 45 } 46 ll maxx; 47 for(int i=100000; i>=0; i--) 48 if(hash[i]) 49 { 50 maxx=i; 51 break; 52 } 53 if(maxx==0) 54 { 55 printf("0\n"); 56 return 0; 57 } 58 a[0]=0; 59 a[n+1]=0; 60 if(hash[maxx]!=1) 61 { 62 ll ans=hash[maxx]*maxx; 63 for(int i=1; i<=n; i++) 64 { 65 if(a[i]==maxx) 66 { 67 if(a[i+1]||a[i-1]) 68 { 69 ans=min(ans,maxx+1); 70 } 71 if(a[i+1]<maxx-1&&i+1<=n) 72 { 73 ans=min((hash[maxx]-1)*(maxx),ans); 74 //return 0; 75 } 76 if(a[i-1]<maxx-1&&i-1>=1) 77 { 78 ans=min((hash[maxx]-1)*(maxx),ans); 79 //return 0; 80 } 81 } 82 } 83 printf("%I64d\n",ans); 84 } 85 else 86 { 87 for(int i=1; i<=n; i++) 88 { 89 if(a[i]==maxx) 90 { 91 if(a[i+1]<maxx-2&&i+1<=n&&hash[maxx-1]==0) 92 { 93 printf("%I64d\n",maxx-1); 94 return 0; 95 } 96 if(a[i-1]<maxx-2&&i-1>=1&&hash[maxx-1]==0) 97 { 98 printf("%I64d\n",maxx-1); 99 return 0; 100 } 101 } 102 } 103 printf("%I64d\n",maxx); 104 } 105 106 return 0; 107 }
Gym 100637F F. The Pool for Lucky Ones
标签:
原文地址:http://www.cnblogs.com/zxhl/p/4675129.html