现在的位置: 首页 > 综合 > 正文

【gcj】2014 Round 3

2018年04月12日 ⁄ 综合 ⁄ 共 3971字 ⁄ 字号 评论关闭

解答

Problem B. Last Hit

这个题目DP, num[i] 为dianna杀死第i个monster时,能够得到的最大总得分。
num[i] = max ( num[i-2]+m[i], num[i-3]+m[i] )  原因是最优方案中,tower不可能连杀三个monster(最多连杀1或2个)。原因如下:
Diana为了获取杀死某些monster的机会,会放弃某次屠杀,从而改变她跟tower原有的杀敌顺序。
但如果连续放弃n次(n>=两次),得到的杀敌顺序和连续放弃n-2次一样,而且得分肯定降低。所以Diana在连续两次杀敌(monster i and monster j)之间,最多放弃过一次,此时 j=i+3。如果没放弃,则j=i+2.

Problem C. Crime House

题目

================================
https://code.google.com/codejam/contests.html  https://code.google.com/codejam/contest/3024486/dashboard#s=p2
Problem B. Last Hit

Diana needs your help maximizing her gold while playing her favorite game. She is often faced with a scenario where she is standing close to her tower and is facing N monsters. When that happens, Diana and the tower take turns shooting the monsters, and she
goes first. During her turn, Diana may choose a monster to shoot at (this means Diana may choose to skip a turn). During its turn, the tower shoots the monster closest to it. Diana and the tower can not shoot dead monsters.

If Diana shoots at a monster, its hit points are reduced by P. If the tower shoots at a monster, its hit points are reduced by Q. If a monster's hit points are reduced below 1, it is killed. The ith monster starts with Hi hit points. Diana is awarded Gi gold
if her shot kills the ith monster, but none if the tower's shot kills it. What is the maximum amount of gold Diana can obtain?

Input

The first line of the input gives the number of test cases, T. T test cases follow. Each case begins with one line containing three space-separated integers representing P, Q and N. N lines then follow, with the ith line containing two space-separated integers
representing Hi and Gi.

The monsters are given in the order of their distance from the tower. In other words, the tower will shoot at the ith monster only if all monsters < i are dead.

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the maximum amount of gold that Diana can obtain.

Limits

1 ≤ T ≤ 100
20 ≤ P ≤ 200
20 ≤ Q ≤ 200
1 ≤ Hi ≤ 200
0 ≤ Gi ≤ 106
Small dataset

1 ≤ N ≤ 4

Large dataset

1 ≤ N ≤ 100

Sample

Input 
 
Output 
 
2
20 40 3
100 100
20 100
60 100
20 60 3
80 100
80 200
120 300

Case #1: 300
Case #2: 500

=================================================
Problem C. Crime House

While working for the police, you've identified a house where people go to commit crimes, called Crime House. One day, you set up a camera over the door of the house and record a video.

You don't know how many people were in Crime House at the start of the day, but you can see people enter and leave through the front door. Unfortunately, because the people entering and leaving Crime House are criminals, sometimes they wear masks; and you aren't
quite sure if the front door is the only way in or out.

Sometimes you can guess who was wearing a mask. If criminal #5 entered the house, then someone wearing a mask left, then criminal #5 entered the house again, then either the person wearing the mask was criminal #5, or there is another way out of Crime House.

At the end of the day, when Crime House has closed its doors for the night, you watch your video. Because you're an optimist, you want to figure out if it's possible that there are no other entrances or exits from crime house; and if so, you want to figure
out the minimum number of people who could be in Crime House at the end of the day.

Input

The first line of the input gives the number of test cases, T. T test cases follow. Each test case starts with a line containing a single integer N, the number of times people pass through the front door of Crime House in the day. Next follows N lines, each
of which contains information about one person entering or leaving Crime House through the front door.

That information consists of a single character, E or L, followed by a space and then an integer id. If the first character is E, that indicates someone entered Crime House through the front door; if it's L, someone left through the front door. If id is greater
than zero, the person with that identifier entered or left Crime House. If id is zero, then the person who entered or left Crime House was wearing a mask, and we don't know who he or she was.

Output

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1). If it's possible that there are no other entrances or exits from Crime House, then y should be the minimum number of people who could be in Crime
House at the end of the day. If that's impossible, y should be "CRIME TIME".

Limits

1 ≤ T ≤ 100.
0 ≤ id ≤ 2000.
Small dataset

1 ≤ N ≤ 15.
Large dataset

1 ≤ N ≤ 1000
Sample

Input 
 
Output 
 
5
3
E 5
L 0
E 5
2
L 1
L 1
4
L 1
E 0
E 0
L 1
7
L 2
E 0
E 1
E 2
E 0
E 3
L 4
13
L 4
L 1
L 2
E 0
L 1
E 0
L 2
E 0
L 2
E 0
E 0
L 1
L 4

Case #1: 1
Case #2: CRIME TIME
Case #3: 1
Case #4: 4
Case #5: 0

【上篇】
【下篇】

抱歉!评论已关闭.