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…
题目 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),…
分析题目以后得出,对于一个连续等差递增的序列,例如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…
题意:给定一个n表示1到n的序列,让你用最小的步数把这个序列都变为0,每个操作可以从序列中选择一个或多个个,同时减掉一个正整数,求最少的步数. 析:一看这个题,感觉挺高深的,但是静下心来想想,其实挺简单.和二分思想有点像,你可把n/2到n的数减掉一个数,变成和前n/2个是一样,然后重复操作,直到全为0. 代码如下: #include <iostream> #include <cstdio> using namespace std; int f(int n){ return 1 ==…
题目链接: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>…
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…
本来抱着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…
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,.…
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…
题目链接:https://vjudge.net/problem/UVA-11384 题意:给定正整数 n,用最少的操作把序列 1,2,,,n 全部变成 0: 操作是:每次可以从序列中选择一个或者多个,同时减去一个相同的数. 其实是一个递归分治的思想,把一部分数字选出来,同时一减,结果就变成了前面没有减过的了,数量不影响结果,反正可以一次拿出很多来操作. 那么怎么选择,使得 n 到 x 的时候 x 最小呢? 经过尝试,发现,减后面一半是最好的,f(n) = f(n/2) + 1; f(1) = 1…
题目: 给你1到n,现在让你将每个数变成0,每一步操作可以选取任意数一起减去一个整数,减完了不能为负数!问你最少需要几步? 巨水的题,然而为什么要写博客呢?提醒自己要记得递归函数,不要傻傻的开数组硬比较 公式:f(n)=f(n/2)+1; 代码如下: #include <bits/stdc++.h> using namespace std; int f (long long int n) { ) ; else )+; } int main() { long long int n; while…
A Different Task The (Three peg) Tower of Hanoi problem is a popular one in computer science. Briefly the problem is to transfer all the disks from peg-A to peg-C using peg-B as intermediate one in such a way that at no stage a larger disk is above a…
著名的折纸问题:给你一张很大的纸,对折以后再对折,再对折……每次对折都是从右往左折,因此在折了很多次以后,原先的大纸会变成一个窄窄的纸条.现在把这个纸条沿着折纸的痕迹打开,每次都只打开“一半”,即把每个痕迹做成一个直角,那么从纸的一端沿着和纸面平行的方向看过去,会看到一条美妙的曲线. 就是一个分形,规定一下,纸的朝向,然后不难发现规律. 实现方面,可以迭代也可递归. 在图形输出方面,存下x和y坐标,然后下标排个序,或者用map. //Rey 2015.8.3 #include<bits/stdc…
每周日更新 2016.05.29 UVa中国麻将(Chinese Mahjong,Uva 11210) UVa新汉诺塔问题(A Different Task,Uva 10795) NOIP2012同余方程 NOIP2007统计数字 NOIP2013火柴排队 NOIP2013花匠 2016.06.05 Uva 组装电脑 12124 - Assemble Uva 派 (Pie,NWERC 2006,LA 3635) 2016.06.19 Uva 网络(Network,Seoul 2007,LA 39…
Quadtrees 四分树就是一颗一个结点只有4个儿子或者没有儿子的树 [题目链接]UVa 297 Quadtrees [题目类型]树的递归 &题意: 一个图片,像素是32*32,给你两个先序递归的字符串,要你把他俩合起来输出面积.p代表结点,f代表黑色,e代表白色. &题解: 用字符串来模拟buf32*32的数组,递归模拟出模型,黑色的涂成1,白色的不处理(也就是0),最后输出1的个数就好了 &代码: #include <bits/stdc++.h> using na…
Android-Binder原理浅析 学习自 <Android开发艺术探索> 写在前头 在上一章,我们简单的了解了一下Binder并且通过 AIDL完成了一个IPC的DEMO.你可能会好奇为什么,上一章说是介绍Binder大的IPC通信呢,为什么又扯到AIDL了,通过本章就可以解除我们的疑惑. IBookManager 在上一章中,说到了使用AIDL成功编译后会生成一个.Java的文件,我们的Dome中生成的文件是 IBookManager.java 下面我们来看一下其中的源码,如下所示(生成…
UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is the same written forwards and backwards. For example, ‘racecar’ is a palindrome, but ‘fastcar’ is not. A partition of a sequence of characters is a lis…
题目链接: 传送门 Copying Books Time Limit: 3000MS     Memory Limit: 32768 KB Description Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so called scribers. The scriber had b…
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=46  Meta-Loopless Sorts  Background Sorting holds an important place in computer science. Analyzing and implementing various so…
Fast Food Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 662 Appoint description:  System Crawler  (2015-08-27) Description   The fastfood chain McBurger owns several restaurants along a highway. Rec…
Scheduling Lectures Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 607 Appoint description:  System Crawler  (2015-08-26) Description   You are teaching a course and must cover n ( ) topics. The leng…
Matrix Chain Multiplication Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 442 Appoint description:  System Crawler  (2015-08-25) Description   Suppose you have to evaluate an expression like A*B*C*D…
UVa 10006 - Carmichael Numbers An important topic nowadays in computer science is cryptography. Some people even think that cryptography is the only important field in computer science, and that life would not matter at all without cryptography. Alvar…
"Waiting for orders we held in the wood, word from the front never came By evening the sound of the gunfire was miles away Ah softly we moved through the shadows, slip away through the trees Crossing their lines in the mists in the fields on our hand…
Uva 11729  Commando War (简单贪心) There is a war and it doesn't look very promising for your country. Now it's time to act. You have a commando squad at your disposal and planning an ambush on an important enemy camp located nearby. You have N soldiers…
UVa 10382 - Watering Grass n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each sprinkler is installed at the horizontal center line of the strip. For each sprinkler we are given its position as the distance…