训练赛(Older)#001
题解(F):
1不知道 二维多重背包。。。
2多重背包模板题
3完全背包模板题
4线段树求区间最值 模板题
5幂取模乱搞
6DFS
7水题
8水题
ID | Origin | Title | ||
---|---|---|---|---|
2 / 14 | Problem A | HDU 3496 | Watch The Movie | |
10 / 23 | Problem B | HDU 2191 | 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 | |
8 / 11 | Problem C | HDU 4508 | 湫湫系列故事――减肥记I | |
5 / 9 | Problem D | POJ 3264 | Balanced Lineup | |
6 / 22 | Problem E | HDU 4506 | 小明系列故事――师兄帮帮忙 | |
4 / 5 | Problem F | HDU 2181 | 哈密顿绕行世界问题 | |
4 / 6 | Problem G | POJ 3210 | Coins | |
7 / 7 | Problem H | POJ 3094 | Quicksum |
B
思路:多重背包模板题
转换为01背包思想
procedure MultiplePack(cost,weight,amount)
if cost*amount>=V
CompletePack(cost,weight)
return
integer k=1
while k ZeroOnePack(k*cost,k*weight) amount=amount-k k=k*2 ZeroOnePack(amount*cost,amount*weight) C 思路:完全背包模板题 procedure CompletePack(cost,weight) for v=cost..V f[v]=max{f[v],f[v-c[i]]+w[i]} D Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the cows. To keep things simple, he will take a contiguous range of cows from the milking lineup to play the game. However, for all the cows to have fun they should not differ too much in height. Farmer John has made a list of Q (1 ≤ Q ≤ 200,000) potential groups of cows and their heights (1 ≤ height ≤ 1,000,000). For each group, he wants your help to determine the difference in height between the shortest and the tallest cow in the group. Input Output Sample Input Sample Output Source 思路:区间最值问题。 详细分析见:POJ 3264 区间最值模板题 E 思路:幂取模问题。 先将数组元素乘以 k^t %mod ,然后再对应于数组元素个数 n 确定其周期性,根据 t%n 顺时针旋转来确定首位置。 (PS:测试时注意首位置不要比 n 大)。 注意:整数的溢出(int *int 可能会超int) 循环输出时,首位置的确定,最好用下面那组数据测试一下,否则WA到正无穷啊 F 思路:简单DFS应用,记录路径。注意格式和输出顺序要先给点排序,还有就是执行dfs的条件要注意下,我标记了的。 G Description Snoopy has three coins. One day he tossed them on a table then and tried to flip some of them so that they had either all heads or all tails facing up. After several attempts, he found that regardless of the initial configuration of the coins, he could always achieve the goal by doing exactly two flippings, under the condition that only one coin could be flipped each time and a coin could be flipped more than once. He also noticed that he could never succeed with less than two flippings. Snoopy then wondered, if he had n coins, was there a minimum number x such that he could do exactly x flippings to satisfy his requirements? Input The input contains multiple test cases. Each test case consists of a single positive integer n (n < 10,000) on a separate line. A zero indicates the end of input and should not be processed. Output For each test case output a single line containing your answer without leading or trailing spaces. If the answer does not exist, output “ Sample Input Sample Output Source 比赛时实在没看懂是什么意思,现在想起,就算当时看懂了也应该不会想到这儿吧。。。下面copy个牛人的分析。 分析来自:点击打开链接 题意:Snoopy想问下,若有n枚硬币,这n枚硬币的初始状态是任意的,则至少需要翻转几次,才能保证对于任何一种初始状态而 言,都能变成n枚硬币全为正或全为反。 思路:若n为偶数: 1: 若初始状态为偶数正面 + 偶数反面,要想变成全正或全反,翻转的次数必为偶数。 例如: ○○●●●● 则翻转 2,4,6,8……次均可。 2: 若初始状态为奇数正面 + 奇数反面,要想变成全正或全反,翻转的次数必为奇数。 例如: ○○○○○● 则翻转 1,3(先将●翻为○,再将任一个○翻两下),5,7……次均可。 因次,我们就无法得到一个确定的翻转次数x,让它能使任意初始状态的硬币变成全为正或全为反,因为若x为偶数,则无法满足例2,若x为奇数,则无法满足例1。故应输出"No Solution!"。 若n为奇数: 初始状态只可能为偶数正面 + 奇数反面(偶数反面 + 奇数正面同理),故要想变成全正或全反,是必能找出一个次数x满足所有任意情况的。 1:对初始状态即全为奇数个正面而言,翻转的次数必为偶数。 2: 由1得只能翻所有正面为反面,因为这样才需翻转偶数次。 例如: ○○○○●●● 则翻转4,6,8,10……次均可,其中最小为4。要保证对7枚硬币的任意初始状态都可行,则最小应为 7-1=6 ,否则对 ○○○○○○● 无法实现。 因此,当你为奇数是,最少翻转次数为n-1。 源代码:(这题考的是题意和推理,不是代码) H Description A checksum is an algorithm that scans a packet of data and returns a single number. The idea is that if the packet is changed, the checksum will also change, so checksums are often used for detecting transmission errors, validating document contents, and in many other situations where it is necessary to detect undesirable changes in data. For this problem, you will implement a checksum algorithm called Quicksum. A Quicksum packet allows only uppercase letters and spaces. It always begins and ends with an uppercase letter. Otherwise, spaces and letters can occur in any combination, including consecutive spaces. A Quicksum is the sum of the products of each character's position in the packet times the character's value. A space has a value of zero, while letters have a value equal to their position in the alphabet. So, A=1, B=2, etc., through Z=26. Here are example Quicksum calculations for the packets " Input The input consists of one or more packets followed by a line containing only # that signals the end of the input. Each packet is on a line by itself, does not begin or end with a space, and contains from 1 to 255 characters. Output For each packet, output its Quicksum on a separate line in the output. Sample Input Sample Output Source 思路:字符串简单处理,直接看代码即可,注意空格的处理就好了。
#include
湫湫系列故事——减肥记I
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 922 Accepted Submission(s): 454
但是对于女生来说,卡路里(热量)是天敌啊!
资深美女湫湫深谙“胖来如山倒,胖去如抽丝”的道理,所以她希望你能帮忙制定一个食谱,能使她吃得开心的同时,不会制造太多的天敌。
当然,为了方便你制作食谱,湫湫给了你每日食物清单,上面描述了当天她想吃的每种食物能带给她的幸福程度,以及会增加的卡路里量。
每组数据以一个整数n开始,表示每天的食物清单有n种食物。
接下来n行,每行两个整数a和b,其中a表示这种食物可以带给湫湫的幸福值(数值越大,越幸福),b表示湫湫吃这种食物会吸收的卡路里量。
最后是一个整数m,表示湫湫一天吸收的卡路里不能超过m。
[Technical Specification]
1. 1 <= n <= 100
2. 0 <= a,b <= 100000
3. 1 <= m <= 100000
#include
Time Limit: 5000MS
Memory Limit: 65536K
Total Submissions: 26485
Accepted: 12426
Case Time Limit: 2000MS
Lines 2..
N+1: Line
i+1 contains a single integer that is the height of cow
i
Lines
N+2..
N+
Q+1: Two integers
A and
B (1 ≤
A ≤
B ≤
N), representing the range of cows from
A to
B inclusive.
6 3
1
7
3
4
2
5
1 5
4 6
2 2
6
3
0
/*
*Accepted
*8404 KB
*3579 ms
*G++
*1022 B 2013-03-23 21:57:28
*O(n*logn)
*第一次写RMQ套用lrj的模板,效率较低,模板较坑 Orz
*/
#include
小明系列故事——师兄帮帮忙
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 2043 Accepted Submission(s): 476
所以,他现在私下求你帮忙解决这道题目,题目是这样的:
给你n个数字,分别是a1,a2,a3,a4,a5……an,这些数字每过一个单位时间就会改变,假设上一个单位时间的数字为a1’,a2’,a3’……an’,那么这个单位时间的数字a[i] = a[i - 1]’ * K(i == 1的时候a[1] = a[n]’ * K),其中K为给定的系数。
现在的问题就是求第t单位时间的时候这n个数字变成了什么了?由于数字可能会很大,所以只要你输出数字对10^9 + 7取余以后的结果。
每组数据有两行,第一行包含输入三个整数n, t, k,其中n代表数字个数,t代表第t个单位时间,k代表系数;第二行输入n个数字ai,代表每个数字开始的时候是多少。
[Technical Specification]
T <= 100
1 <= n <= 10 ^ 4
0 <= t <= 10 ^ 9 其中 t = 0 表示初始状态
1 <= k <= 10 ^ 9
1 <= ai<= 10 ^ 9
#include
哈密顿绕行世界问题
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 612 Accepted Submission(s): 369
/*
*F
*Accepted
*204 KB
*0 ms
*G++
*867 B
*2013-03-26
*/
#include
Time Limit: 1000MS
Memory Limit: 131072K
Total Submissions: 6465
Accepted: 4215
No Solution!
”2
3
0
No Solution!
2
/*
*Accepted
*132 KB
*0 ms
*C++
*176 B
*/
#include
Time Limit: 1000MS
Memory Limit: 65536K
Total Submissions: 11832
Accepted: 8152
ACM
" and "MID CENTRAL
": ACM: 1*1 + 2*3 + 3*13 = 46
MID CENTRAL: 1*13 + 2*9 + 3*4 + 4*0 + 5*3 + 6*5 + 7*14 + 8*20 + 9*18 + 10*1 + 11*12 = 650
ACM
MID CENTRAL
REGIONAL PROGRAMMING CONTEST
ACN
A C M
ABC
BBC
#
46
650
4690
49
75
14
15
#include