Candy Sharing Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4425    Accepted Submission(s): 2698

Problem Description
A number of students sit in a circle facing their teacher in the center. Each student initially has an even number of pieces of candy. When the teacher blows a whistle, each student simultaneously gives half of his or her candy to the neighbor on the right. Any student, who ends up with an odd number of pieces of candy, is given another piece by the teacher. The game ends when all students have the same number of pieces of candy.  Write a program which determines the number of times the teacher blows the whistle and the final number of pieces of candy for each student from the amount of candy each child starts with.
 
Input
The input may describe more than one game. For each game, the input begins with the number N of students, followed by N (even) candy counts for the children counter-clockwise around the circle. The input ends with a student count of 0. Each input number is on a line by itself.
 
Output
For each game, output the number of rounds of the game followed by the amount of candy each child ends up with, both on one line.
 
Sample Input
6
36
2
2
2
2
2
11
22
20
18
16
14
12
10
8
6
4
2
4
2
4
6
8
0
 
Sample Output
15 14
17 22
4 8

题解:深搜一下。。。关键要开两个数组;因为自己给下一个一半的时候自己变了,所以再开个数组记录上一状态;

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define P_ printf(" ")
#define T_T while(T--)
typedef long long LL;
const int INF=0x3f3f3f3f;
int N;
int m[110],n[110];
int ans;
void dfs(int t){
if(ans)return;
if(*max_element(m,m+N)==*min_element(m,m+N)){
ans=1;
printf("%d %d\n",t,m[0]);
return ;
}
for(int i=1;i<N;i++){
m[i]=(n[i-1]+n[i])/2;
if(m[i]&1)m[i]++;
// if(m[i]&1)m[i]++;
}
m[0]=(n[0]+n[N-1])/2;
if(m[0]&1)m[0]++;
for(int i=0;i<N;i++)n[i]=m[i];
// if(m[0]&1)m[0]++;
//for(int i=0;i<N;i++)printf("%d ",m[i]);puts("");
//getchar();
dfs(t+1);
}
int main(){
while(SI(N),N!=0){
for(int i=0;i<N;i++)scanf("%d",&n[i]),m[i]=n[i];
ans=0;
dfs(0);
}
return 0;
}

  

Candy Sharing Game(模拟搜索)的更多相关文章

  1. HDU 1034 Candy Sharing Game (模拟)

    题目链接 Problem Description A number of students sit in a circle facing their teacher in the center. Ea ...

  2. HDU-1034 Candy Sharing Game 模拟问题(水题)

    题目链接:https://cn.vjudge.net/problem/HDU-1034 水题 代码 #include <cstdio> #include <algorithm> ...

  3. POJ - 1666 Candy Sharing Game

    这道题只要英语单词都认得,阅读没有问题,就做得出来. POJ - 1666 Candy Sharing Game Time Limit: 1000MS Memory Limit: 10000KB 64 ...

  4. hdu 1034 Candy Sharing Game

    Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  5. 【LOJ6254】最优卡组 堆(模拟搜索)

    [LOJ6254]最优卡组 题面 题解:常用的用堆模拟搜索套路(当然也可以二分).先将每个卡包里的卡从大到小排序,然后将所有卡包按(最大值-次大值)从小到大排序,并提前处理掉只有一张卡的卡包. 我们将 ...

  6. 【BZOJ4524】[Cqoi2016]伪光滑数 堆(模拟搜索)

    [BZOJ4524][Cqoi2016]伪光滑数 Description 若一个大于1的整数M的质因数分解有k项,其最大的质因子为Ak,并且满足Ak^K<=N,Ak<128,我们就称整数M ...

  7. 【BZOJ4345】[POI2016]Korale 堆(模拟搜索)

    [BZOJ4345][POI2016]Korale Description 有n个带标号的珠子,第i个珠子的价值为a[i].现在你可以选择若干个珠子组成项链(也可以一个都不选),项链的价值为所有珠子的 ...

  8. JavaScript在表格中模拟搜索多关键词搜索和筛选

    模拟搜索需要实现以下功能: 1.用户的模糊搜索不区分大小写,需要小写字母匹配同样可以匹配到该字母的大写单词. 2.多关键词模糊搜索,假设用户关键词以空格分隔,在关键词不完整的情况下仍然可以匹配到包含该 ...

  9. 九度OJ 1145:Candy Sharing Game(分享蜡烛游戏) (模拟)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:248 解决:194 题目描述: A number of students sit in a circle facing their teac ...

随机推荐

  1. C++_基础_类和对象3

    内容: (1)析构函数 (2)拷贝构造和拷贝赋值 (3)静态成员 (4)成员指针 (5)输入输出运算符重载 1.析构函数 当一个对象被创建时,自动调用构造函数进行初始化 当一个对象被销毁时,自动调用析 ...

  2. 小测试 php代理,nginx代理,直接访问对比

    #php proxy total sent request num: 507 total handle read times: 506 506 fetches, 2 max parallel, 2.7 ...

  3. JavaScript中的闭包理解

    原创文章,转载请注明:JavaScript中的闭包理解  By Lucio.Yang 1.JavaScript闭包 在小学期开发项目的时候,用node.js开发了服务器,过程中遇到了node.js的第 ...

  4. linux杂记(七)linux档案与目录管理指令

    1.目录的相关操作:cd,pwd,mkdir,rmdir 路径(PATH): 绝对路径:路径的写法[一定由根目录/写起],例如/usr/share/doc这个目录 相对路径:路径的写法[不是由/写起] ...

  5. PHP上传图片

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. character-RNN模型介绍以及代码解析

    RNN是一个很有意思的模型.早在20年前就有学者发现了它强大的时序记忆能力,另外学术界以证实RNN模型属于Turning-Complete,即理论上可以模拟任何函数.但实际运作上,一开始由于vanis ...

  7. windows server system32下常见快捷指令

    win+R       命令行窗口 cmd        dos命令窗口 mstsc      远程登录输入窗口 calc         快速打卡计算器 control     打开控制面板 eve ...

  8. spring+springMVC集成(annotation方式)

    spring+springMVC集成(annotation方式) SpringMVC+Spring4.0+Hibernate 简单的整合 MyBatis3整合Spring3.SpringMVC3

  9. Azure 网站上的 Java

     编辑人员注释:本文章由Windows Azure 网站团队的项目经理Chris Compy 撰写. Microsoft 已推出针对 Azure 网站上基于 Java 的网站的支持.此功能旨在通过 ...

  10. Git安装及基本使用

    准备: Git软件,github账号. Git安装: 直接百度搜git下载,windows和mac不同平台的.官网上的下载地址很慢或者根本下不了. 默认配置安装. github: 网址:https:/ ...