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. BZOJ 2301: [HAOI2011]Problem b( 数论 )

    和POI某道题是一样的...  http://www.cnblogs.com/JSZX11556/p/4686674.html 只需要二维差分一下就行了. 时间复杂度O(MAXN + N^1.5) - ...

  2. Struts学习之手动验证

    * 首先要从页面中获取对应的标签name属性的值,在动作类action中声明同名的属性,提供get和set方法    * 要继承ActionSupport类或者实现Validateable接口     ...

  3. js判断微信内置浏览器

    做了一个h5页面来下载app,但如果页面是用微信扫一扫打开的,点击下载按钮下载不了app,原因是微信内置浏览器屏蔽了下载链接.所以增加了检测,如果用户是用微信浏览器打开的,则提示用户使用浏览器打开.那 ...

  4. java 数组插入元素

    import java.util.Arrays; public class AddArray { public static void main(String[] args) { int[] arr ...

  5. 获取新浪天气api显示天气情况(转)

    直接上一个html的demo <!doctype html> <html class="no-js fixed-layout"> <head> ...

  6. 汉化testlink

    testlink版本:1.9.13 1.登录testlink后,打开my setting(左上角小人人) 2.Locale 选择chinese,然后点击save 3.over,汉化完毕

  7. 各种排序算法(C语言)

    #include <stdlib.h> #include <stdio.h> void DataSwap(int* data1, int* data2) { int temp ...

  8. 什么是LED锡膏?

    LED锡膏熔点172℃,俗称中温锡膏,其合金为Sn64Bi35Ag1,此类产品是含Bi类的低熔点无铅锡膏,加入Ag改变了SnBi合金的焊点的机械强度.大幅度提高焊点可靠性,适用于高频调谐器系列产品的贴 ...

  9. //Build/ 2014 开发者大会Azure重点整理

     寓教于乐,轻松掌握 Windows Apps和 Cloud //Build/ 2014开发者大会第二天重点整理 (上) //Build/ 2014开发者大会第二天的主题演讲主要包含两部分:Mic ...

  10. SPOJ 220 Relevant Phrases of Annihilation(后缀数组+二分答案)

    [题目链接] http://www.spoj.pl/problems/PHRASES/ [题目大意] 求在每个字符串中出现至少两次的最长的子串 [题解] 注意到这么几个关键点:最长,至少两次,每个字符 ...