uva 11384 Help is needed for Dexter(模拟)

uva 11384 Help is needed for Dexter

Dexter is tired of Dee Dee. So he decided to keep Dee Dee busy in a game. The game he planned for her is quite easy to play but not easy to win at least not for Dee Dee. But Dexter does not have time to spend on this silly task, so he wants your help.

There will be a button, when it will be pushed a random number N will be chosen by computer. Then on screen there will be numbers from 1 to N. Dee Dee can choose any number of numbers from the numbers on the screen, and then she will command computer to
subtract a positive number chosen by her (not necessarily on screen) from the selected numbers. Her objective will be to make all the numbers 0.

For example if N = 3, then on screen there will be 3 numbers on screen: 1, 2, 3. Say she now selects 1 and 2. Commands to subtract 1, then the numbers on the screen will be: 0, 1, 3. Then she selects 1 and 3 and commands to subtract 1. Now the numbers are
0, 0, 2. Now she subtracts 2 from 2 and all the numbers become 0.

Dexter is not so dumb to understand that this can be done very easily, so to make a twist he will give a limit L for each N and surely L will be as minimum as possible so that it is still possible to win within L moves. But Dexter does not have time to think
how to determine L for each N, so he asks you to write a code which will take N as input and give L as output.

Input and Output:

Input consists of several lines each with N such that 1 ≤ N ≤ 1,000,000,000. Input will be terminated by end of file. For each N output L in separate lines.


SAMPLE INPUT


OUTPUT FOR SAMPLE INPUT


1

2

3


1

2

2

题目大意:给出n个连续的整数,可从中选中一个或多个整数,同时减去一个相同的正整数,最终要将所有的数都变为0,求最少的操作数。

解题思路:模拟几遍。

#include<stdio.h>
int f(int n) {
	if (n == 1) return 1;
	else return f(n / 2) + 1;
}
int main() {
	int n;
	while (scanf("%d", &n) == 1) {
		printf("%d\n", f(n));
	}
	return 0;
}
时间: 2024-08-05 10:05:07

uva 11384 Help is needed for Dexter(模拟)的相关文章

UVA - 11384 - Help is needed for Dexter (找规律!!)

UVA - 11384 Help is needed for Dexter Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem H Help is needed for Dexter Time Limit: 3 Second Dexter is tired of Dee Dee. So he decided to keep Dee Dee b

UVA 11384 Help is needed for Dexter

#include<iostream> using namespace std; int n; int dfs(int n){return n == 1 ? 1 : dfs(n / 2) + 1;} int main() { while (cin >> n) cout << dfs(n) << endl; return 0; }

UVa 11384 Help in needed for Dexter 正整数序列

序列太简单了,每次对于后面一半进行操作,使之变成前一半就行了. i个数需要操作的次数 f(i)=f(i/2)+1 代码如下: #include<cstdio> using namespace std; int f(int n){ return n==1?1:f(n/2)+1; } int main(){ int n; while(scanf("%d",&n)==1) printf("%d\n",f(n)); return 0; } 原文地址:ht

uva------Help is needed for Dexter(11384)

Problem H Help is needed for Dexter Time Limit: 3 Second Dexter is tired of Dee Dee. So he decided to keep Dee Dee busy in a game. The game he planned for her is quite easy to play but not easy to win at least not for Dee Dee. But Dexter does not hav

【UVA11384】Help is needed for Dexter(数学题。。。)

Problem H Help is needed for Dexter Time Limit: 3 Second Dexter is tired of Dee Dee. So he decided to keep Dee Dee busy in a game. The game he planned for her is quite easy to play but not easy to win at least not for Dee Dee. But Dexter does not hav

UVA 10815-Andy&#39;s First Dictionary(字符串模拟+排序+重复删除)

Andy's First Dictionary Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description Problem B: Andy's First Dictionary Time limit: 3 seconds Andy, 8, has a dream - he wants to produce his very own dictionary. This

UVA 11776 - Oh Your Royal Greediness! - [贪心/模拟]

题目链接:https://cn.vjudge.net/problem/UVA-11776 题意: 给出数字n(0<=n<=1000),代表有n个农民,接下来有n行,每行两个数字S和E代表这个农民工作时间为[S,E]: 每个农民工作时,需要有一个enforcer来监督,且每个enforcer一次只能监督一个农民: 求最少需要多少个enforcer. 题解: 这道题我也不太清楚算贪心还是算模拟,可能两者都有一点吧. 首先我们根据正常思维,既然要模拟分配监工去监督农民,那么肯定先给第一个开始做的农民

UVa 210 Concurrency Simulator (双端队列+模拟)

题意:给定n个程序,每种程序有五种操作,分别为 var = constant(赋值),print var (打印), lock, unlock,end. 变量用小写字母表示,初始化为0,为程序所公有(一个程序里对某个变量修改可以会影响其他程序里的这个变量), 常数小于100(也就是说最多两位数). 每个时刻都只能有一个程序处于运行状态,其他的都在等待,上述五种操作用时分别是t1, t2, t3, t4, t5.运行中的程序, 每次最多能运行q个时间,当q个时间被用完后,它会被放在等待队列的尾部,

UVA 11384 正序数排列

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2379 http://7xjob4.com1.z0.glb.clouddn.com/33af24c925ae62df4c094b22a2ba7e37 题意:给定1-n的数,可选多个数减去同一整数,求最小的操作次数 思路:保留1~n/2,剩下全减去n/2+1,得1,2...,n/2,0,1,.