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. Labview中引用,属性节点,局部变量之间的区别

    Labview中引用,属性节点,局部变量之间的区别        在Labview中我们经常会碰到这样几个概念,那就是控件的引用,属性节点以及局部变量,他们之间到底有哪些区别呢?        首先谈 ...

  2. 在ProgressBar上加文字----显示百分比的进度条

    http://www.cnblogs.com/3dant/archive/2011/04/25/2026776.html

  3. TJU 2944 Mussy Paper 最大权闭合子图

    传送门 给你一些东西,  每个东西有一个值,有正有负. 在给一些关系, 选了其中一个物品, 和他有关系的也必须全都选上, 关系是单向的. 问最后的最大价值是多少, 如果小于0输出“   **** ”( ...

  4. Linux下C编程通过宏定义打开和关闭调试信息

    GCC支持宏定义 gcc -Dmacro,将macro定义为1,我们可以利用这点在我们的代码中加入宏定义开关. #ifdef DEBUG #define pdebug(format, args...) ...

  5. SQL Server 数据库所有者

    1. 数据库所有者应当永远是 sa 用户 2. 改变数据库的所有者 alter authorization on database :: databaseName to sa; -- 这一句话把数据库 ...

  6. XHProf 初探

    XHProf是一个分层PHP性能分析工具.它报告函数级别的请求次数和各种指标,包括阻塞时间,CPU时间和内存使用情况.一个函数的开销,可细分成调用者和被调用者的开销,XHProf数据收集阶段,它记录调 ...

  7. cluster maintain manager Software群集管理软件

    1,ocfs2 2,crmsh(cluster management shell,)==crm shell [pacemaker OpenAIS,heartbeat,corosync,crmsh] 3 ...

  8. Quick Tip: Outline Elements on Hover

    How to get the xpath by clicking an html element How to get the xpath by clicking an html element Qu ...

  9. codeforces #261 C题 Pashmak and Buses(瞎搞)

    题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...

  10. [C# 基础知识系列]专题六:泛型基础篇——为什么引入泛型

    引言: 前面专题主要介绍了C#1中的2个核心特性——委托和事件,然而在C# 2.0中又引入一个很重要的特性,它就是泛型,大家在平常的操作中肯定会经常碰到并使用它,如果你对于它的一些相关特性还不是很了解 ...