编程介的小学生 2018-12-19 00:53 采纳率: 20.5%
浏览 362
已采纳

一个颜色方块的比较判断的问题,请问如何用C语言实现

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

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-08-24 23:56
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿