欢迎访问我的个人网站==》 jiashubing.cn

随笔分类 -  OJ_UVA

摘要:Headmaster's Headachehe headmaster of Spring Field School is considering employing some new teachers for certain subjects. There are a number of teachers applying for the posts. Each teacher is able to teach one or more subjects. The headmaster wants to select applicants so that each subject is 阅读全文
posted @ 2013-08-28 03:58 贾树丙 阅读(634) 评论(1) 推荐(0) 编辑
摘要:Hackers’ CrackdownMiracle Corporations has a number of system services running in a distributed computer system which is a prime target for hackers. The system is basically a set ofNcomputer nodes with each of them running a set ofNservices. Note that, the set of services running on every node is sa 阅读全文
posted @ 2013-08-21 16:11 贾树丙 阅读(968) 评论(2) 推荐(0) 编辑
摘要:String to Palindrome题目大意:给出一个字符串s,现在可以进行3种操作(添加字母,删除字母,替换字母),将其变成回文串,求出最少的操作次数。比如abccda,可以用删除操作,删除b,d两步可变成回文;但如果用替换操作,把b换成d则只需要1步。分析:刚开始我一直考虑它是否具有最优子结构性质,直到现在,还是不明白为什么可以用动态规划来做,大神若是看见,还望指教。 由于添加字母和删除字母的效果是一样的,因此我们这里就只进行删除和替换操作。令dp[i][j]表示从第 i 到第 j 个字母变成回文所需要最少的操作数。 转移方程为:当是s[i]==s[j]时,dp[i][j] = d.. 阅读全文
posted @ 2013-07-26 18:22 贾树丙 阅读(759) 评论(0) 推荐(0) 编辑
摘要:题目大意:输入一个由小写字母组成的字符串,你的任务是把它划分成尽量少的回文串。比如racecar本身就是回文串;fastcar只能分成7个单字母的回文串;aaadbccb最少可分成3个回文串:aaa、d、bccb。字符串的长度不超过1000。分析:令dp[i]表示从第1个到第 i 个字符所组成的最少回文串数。 我们考虑如果前k个字符构成了1个回文,那么前k+1个字符最多构成2个回文,如果这些字符都相同,那么也只是1个回文串。所以如果第 j 个字母到第 i 个字母能构成回文,那么dp[i] = min(dp[i],dp[j-1]+1);初始条件是:dp[i]=i;代码如下: 1 # inclu. 阅读全文
posted @ 2013-07-26 16:38 贾树丙 阅读(344) 评论(0) 推荐(0) 编辑
摘要:CALCULATOR CONUNDRUMAlice got a hold of an old calculator that can displayndigits. She was bored enough to come up with the following time waster.She enters a numberkthen repeatedly squares it until the result overflows. When the result overflows, only thenmostsignificant digits are displayed on the 阅读全文
posted @ 2013-07-20 19:02 贾树丙 阅读(662) 评论(2) 推荐(1) 编辑
摘要:Open Credit SystemIn an open credit system, the students can choose any course they like, but there is a problem. Some of the students are more senior than other students. The professor of such a course has found quite a number of such students who came from senior classes (as if they came to attend 阅读全文
posted @ 2013-07-20 18:49 贾树丙 阅读(348) 评论(1) 推荐(1) 编辑
摘要:Age SortYou are given the ages (in years) of all people of a country with at least 1 year of age. You know that no individual in that country lives for 100 or more years. Now, you are given a very simple task of sorting all the ages in ascending order.InputThere are multiple test cases in the input 阅读全文
posted @ 2013-07-20 18:12 贾树丙 阅读(513) 评论(1) 推荐(0) 编辑
摘要:Help is needed for DexterTime Limit: 3 SecondDexter 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.Ther 阅读全文
posted @ 2013-07-20 15:25 贾树丙 阅读(423) 评论(1) 推荐(0) 编辑
摘要:Easy Problem from Rujia Liu?Though Rujia Liu usually sets hard problems for contests (for example, regional contests like Xi'an 2006, Beijing 2007 and Wuhan 2009, or UVa OJ contests like Rujia Liu's Presents 1 and 2), he occasionally sets easy problem (for example, 'the Coco-Cola Store&# 阅读全文
posted @ 2013-07-19 23:06 贾树丙 阅读(451) 评论(1) 推荐(0) 编辑
摘要:I Can Guess the Data Structure!There is a bag-like data structure, supporting two operations:1 xThrow an element x into the bag.2Take out an element from the bag.Given a sequence of operations with return values, you're going to guess the data structure. It is a stack (Last-In, First-Out), a que 阅读全文
posted @ 2013-07-19 22:44 贾树丙 阅读(453) 评论(1) 推荐(0) 编辑
摘要:strcmp() Anyone?strcmp() is a library function in C/C++ which compares two strings. It takes two strings as input parameter and decides which one is lexicographically larger or smaller: If the first string is greater then it returns a positive value, if the second string is greater it returns a nega 阅读全文
posted @ 2013-07-19 22:24 贾树丙 阅读(442) 评论(1) 推荐(0) 编辑
摘要:Remember the WordNeal is very curious about combinatorial problems, and now here comes a problem about words. Knowing that Ray has a photographic memory and this may not trouble him, Neal gives it to Jiejie.Since Jiejie can't remember numbers clearly, he just uses sticks to help himself. Allowin 阅读全文
posted @ 2013-07-19 21:50 贾树丙 阅读(686) 评论(1) 推荐(0) 编辑
摘要:PieMy birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a numberNof them, of various tastes and of various sizes.Fof my friends are coming to my party and each of them gets a piece of pie. This should be one piece of one pie, not several small pieces since tha 阅读全文
posted @ 2013-07-19 01:23 贾树丙 阅读(551) 评论(0) 推荐(0) 编辑
摘要:A Different TaskThe (Three peg) Tower of Hanoi problem is a popular one in computer science. Briefly the problem is to transfer all the disks from peg-Ato peg-Cusing peg-Bas intermediate one in such a way that at no stage a larger disk is above a smaller disk. Normally, we want the minimum number of 阅读全文
posted @ 2013-07-19 00:55 贾树丙 阅读(577) 评论(0) 推荐(0) 编辑
摘要:Even ParityWe have a grid of sizeNxN. Each cell of the grid initially contains a zero(0) or a one(1).Theparityof a cell is the number of 1s surrounding that cell. A cell is surrounded by at most 4 cells (top, bottom, left, right).Suppose we have a grid of size4x4:1010The parity of each cell would be 阅读全文
posted @ 2013-07-18 21:05 贾树丙 阅读(308) 评论(0) 推荐(0) 编辑
摘要:Piotr's AntsTime Limit: 2 secondsPiotr likes playing with ants. He hasnof them on a horizontal poleLcm long. Each ant is facing either left or right and walks at a constant speed of 1 cm/s. When two ants bump into each other, they both turn around (instantaneously) and start walking in opposite 阅读全文
posted @ 2013-07-18 15:33 贾树丙 阅读(747) 评论(0) 推荐(0) 编辑
摘要:Spreading the WealthProblemA Communist regime is trying to redistribute wealth in a village. They have have decided to sit everyone around a circular table. First, everyone has converted all of their properties to coins of equal value, such that the total number of coins is divisible by the number o 阅读全文
posted @ 2013-07-18 15:11 贾树丙 阅读(719) 评论(0) 推荐(0) 编辑
摘要:Commando WarThere 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 haveNsoldiers in your squad. In your master-plan, every single soldier has a 阅读全文
posted @ 2013-07-16 18:54 贾树丙 阅读(485) 评论(1) 推荐(0) 编辑
摘要:Problem BThe Twin TowersInput:standard inputOutput:standard outputOnce upon a time, in an ancient Empire, there were two towers of dissimilar shapes in two different cities. The towers were built by putting circular tiles one upon another. Each of the tiles was of the same height and had integral ra 阅读全文
posted @ 2013-07-11 08:47 贾树丙 阅读(351) 评论(0) 推荐(0) 编辑
摘要:DollarsNew Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and 5c coins. Write a program that will determine, for any given amount, in how many ways that amount may be made up. Changing the order of listing does not increase the count. Thus 20c may be made up 阅读全文
posted @ 2013-04-30 15:26 贾树丙 阅读(329) 评论(0) 推荐(0) 编辑