zoj 1814 Candy Sharing Game

zoj 1814 Candy Sharing Game,第1张

zoj 1814 Candy Sharing Game
#include <queue>#include <stack>#include <math.h>#include <stdio.h>#include <stdlib.h>#include <iostream>#include <limits.h>#include <string.h>#include <algorithm>using namespace std;int a[101];int b[101];int n;int findmax(){int m = 0;for(int i=0; i<n; i++)if( a[i] > m )m = a[i];return m;}int findmin(){int m = INT_MAX;for(int i=0; i<n; i++)if( a[i] < m )m = a[i];return m;}int main(){int ans1,ans2,count;while( ~scanf("%d",&n) && n ){for(int i=0; i<n; i++)scanf("%d",&a[i]);count = 0;ans1 = findmax();ans2 = findmin();if( ans1 == ans2 ){printf("0 %dn",a[0]);continue;}while(1){memcpy(b,a,sizeof(a));for(int i=0; i<n; i++){a[i] /= 2;if( i == n-1 ){a[i] += b[0]/2;break;}a[i] += b[i+1]/2;}for(int i=0; i<n; i++){if( a[i] % 2 == 1 )a[i]++;}count++;ans1 = findmax();ans2 = findmin();if( ans1 == ans2 )break;}printf("%d %dn",count,a[0]);}return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4909593.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存