HDU 1034 Candy Sharing Game 模拟题

一个分糖游戏,找了会规律,没找到,只能直接模拟玩了。

果然0ms过了,看来数据不大,只是考编码能力罢了。

#include <stdio.h>
#include <vector>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <limits.h>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

int main()
{
	int N;
	while (~scanf("%d", &N) && N)
	{
		int *stu = (int *)malloc(sizeof(int)*N);
		for (int i = 0; i < N; i++)
		{
			scanf("%d", stu+i);
		}
		int ti = 0;
		while (true)
		{
			int last = stu[N-1];
			for (int i = 0; i < N; i++)
			{
				int t = stu[i];
				stu[i] = (stu[i]>>1) + (last>>1);
				last = t;
			}
			for (int i = 0; i < N; i++)
			{
				if (stu[i] & 1) stu[i]++;
			}
			ti++;

			int i = 1;
			last = stu[0];
			for ( ; i < N && last == stu[i]; i++);
			if (i == N) break;
		}
		printf("%d %d\n", ti, stu[0]);
		free(stu);
	}
	return 0;
}

HDU 1034 Candy Sharing Game 模拟题

时间: 2024-08-10 05:06:58

HDU 1034 Candy Sharing Game 模拟题的相关文章

hdu 1034 Candy Sharing Game

Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4942    Accepted Submission(s): 3020 Problem Description A number of students sit in a circle facing their teacher in the cente

J - Candy Sharing Game(模拟题)

主要是理解题目意思,然后就按照它说的来模拟就好了. 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 h

HDU 4925 Apple Tree(模拟题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 解题报告:给你n*m的土地,现在对每一块土地有两种操作,最多只能在每块土地上进行两种操作,第一种是种苹果树操作,第二种是施肥操作,种苹果树操作可以使得该块地 长出一个苹果,施肥操作可以使得与这块土地相邻的土地的苹果产量变为原来的两倍,问可以得到的最多的苹果数量是多少? 例如一个4*4的土地,用1表示在该土地上做第一种操作,0表示在该土地上做第二种操作,可以得到最多苹果的操作如下: 0 1 0

hdu 4119 Isabella&#39;s Message 模拟题

Isabella's Message Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4119 Description Isabella and Steve are very good friends, and they often write letters to each other. They exchange funny experiences, talk ab

HDU 2414 Chessboard Dance(模拟题,仅此纪念我的堕落)

题目 模拟题也各种wa,我最近真的堕落了,,,,,智商越来越为负数了!!!!!!!! #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; char mp[10][10]; int d=-1;//0shang,1xia,2zuo,3you int x,y;//weizhi int weizhi(int i,int j) { if(mp[i][j]=='<'){x=

HDU 1337 The Drunk Jailer--(模拟题找规律)

题意:有n个监狱,共n轮,第 i 轮警察会去编号为 i 的倍数的监狱,如果是锁的就开锁,如果是开的就锁上,求n轮过后有多少犯人会逃出来 分析:这题实际上是个模拟题,因为数据很小我直接用两重循环模拟的,如果数据很大的话,就不能直接模拟了,模拟题卡时间多半是找规律. 这题的规律是:如果一个监狱被查看了偶数次的话相当于则什么都没发生,还是锁的,也就是说找没有锁上的监狱只要n以内找因数为奇数个的数有多少个即可 代码: #include<iostream> using namespace std; in

HDU 4801 Pocket Cube(模拟题——转魔方)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4801 题面: Pocket Cube Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 882    Accepted Submission(s): 271 Problem Description Pocket Cube is a 3-D

hdu 1861 游船出租(模拟题,,水)

题意: 现有公园游船租赁处请你编写一个租船管理系统. 当游客租船时,管理员输入船号并按下S键,系统开始计时:当游客还船时,管理员输入船号并按下E键,系统结束计时. 船号为不超过100的正整数.当管理员将0作为船号输入时,表示一天租船工作结束,系统应输出当天的游客租船次数和平均租船时间. 注意:由于线路偶尔会有故障,可能出现不完整的纪录,即只有租船没有还船,或者只有还船没有租船的纪录,系统应能自动忽略这种无效纪录. 输入: 测试输入包含若干测试用例,每个测试用例为一整天的租船纪录,格式为船号(1~

HDU 4364——Matrix operation——————【模拟题】

Matrix operation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 907    Accepted Submission(s): 384 Problem Description M_0 is interested in cryptography. Recently he learned the Advanced Encryp