本来抱着wa一发的心态写写,没想到过了. 算是一种二分吧. 也就是说,减数取太大和太小都不好,怎样是最好的呢?当然是,每次减去一个数之后新形成的序列和前面的序一样是最好的 这样的话,本来想写个二分,但是直接写了下面的代码:开心 #include<iostream> using namespace std; int n, ans, l, r, mid; int main(){ while(cin>>n){ ans=; ;} cout<<ans<<endl; }…
题目描述 Description 给定正整数n,你的任务是用最少的操作次数把序列1, 2, …, n中的所有数都变成0.每次操作可从序列中选择一个或多个整数,同时减去一个相同的正整数.比如,1,2,3可以把2和3同时减小2,得到1,0,1.输入包含多组数据.每组仅一行,为正整数n(n≤109).输入结束标志为文件结束符(EOF).对于每组数据,输出最少操作次数.  输入输出格式 Input/output 输入格式:输入包含多组数据,每组仅一行,为正整数n(n≤109),输入结束标志为文件结束符E…
UVA.11384 Help is needed for Dexter (思维题) 题意分析 同样水题一道,这回思路对了. 给出数字n,面对一个1,2,3,4--n的数字序列,你可以对他们的部分或者全部减去一个相同数字,最后使得这个序列变为全0的序列,求这样操作的次数最小值. 一开始着手想的是两两分组,既然能两两分组,为什么不三三分组呢?既然能三三分组,为什么不能四四分组呢?不难联想到二分法,即折半分组,看如下的例子: n = 9 1,2,3,4,5,6,7,8,9 折半后 1,2,3,4 5,…
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 have time to…
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 have time to…
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…
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2379 题意 [1, .., n],每次可以减一个1-n之间的数,问至少多少次能将全部数字减为0(减为0后不再变化) 思路 如刘书思路. 想到1...n,就会想到树状数组分bit存储的思想,进而就会觉得分bit减是一个想法.因为log2(n) <= (x - 1)logx(n),…
题意:给定一个n表示1到n的序列,让你用最小的步数把这个序列都变为0,每个操作可以从序列中选择一个或多个个,同时减掉一个正整数,求最少的步数. 析:一看这个题,感觉挺高深的,但是静下心来想想,其实挺简单.和二分思想有点像,你可把n/2到n的数减掉一个数,变成和前n/2个是一样,然后重复操作,直到全为0. 代码如下: #include <iostream> #include <cstdio> using namespace std; int f(int n){ return 1 ==…
分析题目以后得出,对于一个连续等差递增的序列,例如1,2,3,4,5,6,每次选择其中后一半,减去能减的最大数,则是最优操作. 上述序列经过一次操作后变为1,2,3,0,1,2,此时可抛弃后一半(已经能和前一半一起处理了),操作前三个数的后两个,以此类推,总共三次操作可把所有数减成0 分析得到递推式:设n为序列长度,ans(n)=ans(n/2)+1 于是代码变得很简单了: #include<bits/stdc++.h> using namespace std; int a; int r(in…
给定一个正整数 n ,你的任务使用最少的操作次数把序列 1, 2, 3, -- , n 中的所有数都变成 0 .每次操作可以从序列中选择一个或者多个数,同时减去一个相同的正整数.比如,1, 2, 3 可以把 2 和 3 同时减小 2 ,得到 1, 0, 1 . 模拟几次就能看出做法了. 例如当 n = 6 的时候 0      -----      1  2  3  4  5  6 1      -----      1  2  3  0  1  2 2      -----      1  0…