码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 1666

时间:2015-06-10 17:14:28      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:

#include<iostream>
using namespace std;
int main()
{
    int num_stu;
    int i;
    int time=0;
    do{
    time=0;
    cin>>num_stu;
    if(num_stu==0)
        break;
    int * counts=new int[num_stu];
    int * count=new int[num_stu];
    for(i=0;i<num_stu;i++){
        cin>>counts[i];
        count[i]=counts[i];
    }
       
    
    while(++time)
    {
        for(i=0;i<num_stu-1;i++)
        {
            count[i+1]=counts[i]/2+counts[i+1]/2;
            if(count[i+1]%2!=0)
                count[i+1]++;
        }
        count[0]=counts[num_stu-1]/2+counts[0]/2;
        if(count[0]%2!=0)
            count[0]++;
        for(i=0;i<num_stu;i++)
            counts[i]=count[i];
        for(i=0;i<num_stu-1;i++)
            if(counts[i]!=counts[i+1])
                break;
        if(i==num_stu-1)
            break;
    }
    cout<<time<<" "<<counts[0]<<endl;
    delete []counts;
    delete []count;
    }while(1);

}

 

POJ 1666

标签:

原文地址:http://www.cnblogs.com/gavinsp/p/4566505.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!