F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Color Squares

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 595    Accepted Submission(s): 235


Problem Description
You have a 3 * 3 board of color squares. Each square is either empty or has a block in it. Initially, all the squares are empty. There are four kinds of blocks: blue (B), red (R), green (G) and yellow (Y). Each of these block scores wb, wr, wg and wy , respectively (blocks of the same color always have the same score). We assume that wb<=wr<=wg<=wy .


In each step, you can place a new block in a square. If that square already has a block in it, take it out first (taking it out does not count as a step). You can do this as many times as you like (you're given enough blocks for each color), as long as you follow these rules:


Rule 1: You can always place a blue block.
Rule 2: You can place a red block if and only if it's surrounded by at least one blue block.
Rule 3: You can place a green block if and only if it's surrounded by at least one blue and one red block.
Rule 4: You can place a yellow block if and only if it's surrounded by at least one blue, one red and one green block


Every square is surrounded by squares that share one edge with it, so each of four corner squares is surrounded by exactly two squares, each of four squares on the edge (but not at corners) is surrounded by exactly three squares, and the center square is surrounded by exactly four squares.

Write a program to find the minimal number of steps needed to get a score of at least w . The total score is the sum of individual scores of each block on the current board, regardless of what blocks you've thrown away.
 

Input
The input contains several test cases. Each case contains five positive integer, wb, wr, wg, wy, w (1<=wb<=wr<=wg<=wy¡Ü100, 0<=w<=1000) in a single line. The last test case is followed by a single zero, which should not be processed.
 

Output
For each test case, print the case number and the minimum number of steps. If it is impossible, output ``Impossible".
 

Sample Input
1 1 1 1 3 1 2 4 8 21 1 1 1 100 500 7 20 53 94 395 0
 

Sample Output
Case 1: 3 Case 2: 7 Case 3: Impossible Case 4: 11
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-25 18:29:36, Gzip enabled