摘要: 题意: 给定船的最大载重量和旅客人数,以及每个旅客的体重,每条船最多坐两人,求让每个旅客都上船所需船数量的最小值。 由于旅客体重范围较小,可直接遍历所有可能的体重,省去了对旅客体重值的排序。用一个数组记录每个体重旅客的人数,根据较轻体重的旅客与较重体重旅客的最佳搭配得到最优解。代码:#include<iostream>#include<cstring>using namespace std ;int main(){ int a[300] ; int m, n, i, j ; cin >> m >> n ; memset(a, 0, sizeof( 阅读全文
posted @ 2011-08-14 12:36 追逐. 阅读(609) 评论(0) 推荐(1) 编辑
摘要: 题意: 有N个任务,每个任务都花费一个单位的时间来完成,每个任务都有规定的时间期限,超出期限完成则要罚款。求所能使罚款最小的任务组合及最小罚款金额。 输入: 一个整数N代表任务个数,下面N行分别有两个整数,第一个为时间期限,第二个为超时罚款金额。输出: 期限内完成的任务编号,期限外完成任务编号,罚款数。 本题关键在罚款金额,所以要尽可能的使罚款金额大的任务先完成,对任务根据罚款金额从大到小排序,依次处理各个任务。得到可提前完成的任务后,对任务根据时间期限排序,使期限大的任务尽可能的靠后,这样能保证提前完成的任务数量最大。代码:#include<iostream>#include&l 阅读全文
posted @ 2011-08-14 12:36 追逐. 阅读(774) 评论(0) 推荐(0) 编辑
摘要: DescriptionBackground "KO-RE-A, KO-RE-A" shout 54.000 happy football fans after their team has reached the semifinals of the FIFA World Cup in their home country. But although their excitement is real, the Korean people are still very organized by nature. For example, they have organized h 阅读全文
posted @ 2011-08-14 12:35 追逐. 阅读(335) 评论(0) 推荐(0) 编辑
摘要: 题意: 随意给定一串数字1,2,3,求最少多少次交换操作可以将其按升序排列,输出最少次数以及每次交换的位置。代码:#include<iostream>#include<cstring>using namespace std ;int min(int a, int b){ if(a>b) return b ; else return a ;}int main(){ int n, i, j ; int a[1001], b[1001], s[4][4] ; cin >> n ; int num[4] ; int sum, key ; memset(num, 阅读全文
posted @ 2011-08-14 12:35 追逐. 阅读(213) 评论(0) 推荐(0) 编辑
摘要: 题意: 给定两个字符串,求经过多少次的增删改操作可使两个字符串相同。与poj2192相似,用dp[n]记录使str1前n个字符与str2前m个字符相同的最少操作数。每次的判断都有三种情况,即str1前i个字符str2前j-1个字符,str1前i-1个字符str2前j个字符,str1前i-1个字符str2前j-1个字符。取三种情况经过本次操作后的最小值即可。 代码:#include<iostream>#include<cstring>usingnamespacestd;intmin(inta,intb,intc){intm=1000000;if(a<m)m=a;if 阅读全文
posted @ 2011-08-14 12:34 追逐. 阅读(202) 评论(0) 推荐(0) 编辑
摘要: DescriptionYou want to arrange the window of your flower shop in a most pleasant way. You have F bunches of flowers, each being of a different kind, and at least as many vases ordered in a row. The vases are glued onto the shelf and are numbered consecutively 1 through V, where V is the number of va 阅读全文
posted @ 2011-08-14 12:34 追逐. 阅读(178) 评论(0) 推荐(0) 编辑
摘要: Description 73 88 1 02 7 4 44 5 2 6 5(Figure 1)Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right. In 阅读全文
posted @ 2011-08-14 12:33 追逐. 阅读(217) 评论(0) 推荐(0) 编辑
摘要: 题意: 给定三个字符串,判断前两个经过字符顺序不变的组合能否变为第三个字符串。 用bool型数组dp[i][j]记录str1的前i个字符和str2的前j个字符能否组合成str3的前i+j个字符。str3的最后一个字符肯定是 str1或str2的最后一个字符,想得到dp[i][j],则必须知道dp[i-1][j](即str1的前i-1个字符和str2的前j个字符能否组合成str3的前i-1+j个字符)和dp[i][j-1](即str1的前i个字符和str2的前j-1个字符能否组合成str3的前i+j-1个字符),由此将问题分解为str1的前n个字符和str2的前m个字符能否组合成str3... 阅读全文
posted @ 2011-08-14 12:33 追逐. 阅读(199) 评论(0) 推荐(0) 编辑
摘要: A military contractor for the Department of Defense has just completed a series of preliminary tests for a new defensive missile called the CATCHER which is capable of intercepting multiple incoming offensive missiles. The CATCHER is supposed to be a remarkable defensive missile. It can move forwar. 阅读全文
posted @ 2011-08-14 12:27 追逐. 阅读(907) 评论(0) 推荐(0) 编辑
摘要: 题意: N个人减肥,给出他们的起始体重和减肥的天数,而且每天能减去一磅的体重。要求按减肥者减肥过后的体重降序排列姓名。 输入:姓名 减肥天数 起始体重 输出:降序输出姓名 此题原想用C++写,但因不太了解C++字符串操作的基本方法(strcmp()),无法实现部分功能,所以改用JAVA。创建一个类存放减肥者的信息(姓名,减肥后的体重),根据计算得出的weight对对象数组排序。要注意要求每组数据输出后保留一行空格。 代码: import java.util.* ; class People{ String name ;int weigth ;} public class Main{ publi 阅读全文
posted @ 2011-08-14 12:19 追逐. 阅读(298) 评论(0) 推荐(0) 编辑
摘要: DescriptionThere is a huge mountain outside Kicc's house, and Kicc has to climb the mountain every time he wants to go out. It costs him a lot of time and he wants to change the situation. Yes, he figures out a good idea - to move the mountain away! But there is a problem. There are some wild an 阅读全文
posted @ 2011-08-14 12:17 追逐. 阅读(331) 评论(0) 推荐(0) 编辑