标签:
http://lx.lanqiao.org/problem.page?gpid=T124
1 #include <stdio.h> 2 #include <algorithm> 3 #include <iostream> 4 #include <string.h> 5 #include <string> 6 #include <math.h> 7 #include <stdlib.h> 8 #include <queue> 9 #include <stack> 10 #include <set> 11 #include <map> 12 #include <list> 13 #include <iomanip> 14 #include <vector> 15 #pragma comment(linker, "/STACK:1024000000,1024000000") 16 #pragma warning(disable:4786) 17 18 using namespace std; 19 20 const int INF = 0x3f3f3f3f; 21 const int Max = 10000 + 10; 22 const double eps = 1e-8; 23 const double PI = acos(-1.0); 24 int a[1010] , b[1010]; 25 26 void run(int n , int ans) 27 { 28 int i , first = 0; 29 for(i = 0;i < n - 1;i ++) 30 if(a[i] != a[i + 1]) 31 first = 1; 32 if(first) 33 { 34 for(i = 0;i < n;i ++) 35 { 36 if(a[i] % 2 == 1) 37 { 38 a[i] ++; 39 ans ++; 40 } 41 } 42 43 for(i = 1;i < n;i ++) 44 { 45 b[i] = (a[i] + a[i - 1]) / 2; 46 } 47 48 b[0] = (a[n - 1] + a[0]) / 2; 49 50 for(i = 0;i < n;i ++) 51 { 52 a[i] = b[i]; 53 } 54 55 run(n , ans); 56 } 57 else 58 printf("%d\n",ans); 59 } 60 61 int main() 62 { 63 int n , i , j , ans = 0; 64 scanf("%d",&n); 65 for(i = 0 ;i < n;i ++) 66 scanf("%d",&a[i]); 67 68 run(n , ans); 69 70 return 0; 71 }
标签:
原文地址:http://www.cnblogs.com/jeff-wgc/p/4450910.html