题目 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),…
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…
分析题目以后得出,对于一个连续等差递增的序列,例如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…
题目链接:https://vjudge.net/problem/UVA-11384 这道题要分析得透: 如果我们手模的话,会发现:如果先将大于$\frac{n}{2}$的数都减去$\frac{n}{2}$是最优的, 这时候从$\frac{n}{2} +1$到$n$我们是不用考虑的,因为它们小于从$1$到$\frac{n}{2}$. 因此转移方程便是: $f[1]=1$ $f[i]=f[i/2]+1$ AC代码: #include<cstdio> #include<iostream>…
题意:给定一个n表示1到n的序列,让你用最小的步数把这个序列都变为0,每个操作可以从序列中选择一个或多个个,同时减掉一个正整数,求最少的步数. 析:一看这个题,感觉挺高深的,但是静下心来想想,其实挺简单.和二分思想有点像,你可把n/2到n的数减掉一个数,变成和前n/2个是一样,然后重复操作,直到全为0. 代码如下: #include <iostream> #include <cstdio> using namespace std; int f(int n){ return 1 ==…
C. How Many... in 3D! Time Limit: 1000ms Memory Limit: 131072KB 64-bit integer IO format: %lld      Java class name: Main Submit                 Status                 PID: 20864               [PDF Link] Problem C: How Many... in 3D! Given a 2x2xN bo…
UVA 1513 - Movie collection option=com_onlinejudge&Itemid=8&page=show_problem&category=502&problem=4259&mosmsg=Submission+received+with+ID+13965699" target="_blank" style="">题目链接 题意:有一些光盘,一開始是n-1叠上去的(1最顶),如今…
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3141 题意 一个1到n的排列,每次随机删除一个,问删除前的逆序数 思路 综合考虑,对每个数点,令value为值,pos为位置,time为出现时间(总时间-消失时间),明显是统计value1 > value2, pos1 < pos2, time1 < time2的个…