24h購物| | PChome| 登入
2013-07-18 11:32:35| 人氣629| 回應0 | 上一篇 | 下一篇

[UVA] 11975 - Tele-loto

推薦 0 收藏 0 轉貼0 訂閱站台

Y  — Tele-loto

Time Limit: 1 sec
Memory Limit: 32 MB

Tele-loto is a lottery game that is held every weekend in Lithuania. Most of the population know this game and almost everyone have played it at least once. In this task you are asked to write an application which finds the winnings given N balls, the lottery tickets and amount of money for each combination. Possible combinations are listed below:

  • Corners (must be filled within the first 35 balls)
  • MidLine (must be filled within the first 40 balls)
  • Diagonals (must be filled within the first 45 balls)
  • Table (until one of the players wins the game)

Totally 75 balls are in the game each with a unique number from 1 to 75. The i-th column in the ticket contains unique numbers in the interval [(i − 1) * 15 + 1; i * 15], no other numbers may appear in the column. If the ticket wins more than one combination the total money won is equal to the sum of money won for each combination. Pay attention that combination MidLine is applied only to a single middle line!

INPUT

The first line contains the number of tests T (T ≤ 100). Then T tests follow. On the first line of each test there are 2 numbers: N (0 ≤ N ≤ 75) — number of balls, L (L ≤ 103) — number of tickets. On the second line there are N different integers indicating the values of the drawn lucky balls separated by a single space character. Next line contains 4 integers V (Vi ≤ 1000) indicating the values of each combination in left-to-right order as in the picture. Then 5 lines follow for each ticket with 25 different integers indicating the numbers on the ticket in the order as in the picture. Each line contains exactly 5 integers separated by a single space character.

OUTPUT

For each test case output the line "Case T:" where T is a test number starting from 1. Then L lines follow each indicating the amount of money the ticket won in the order they appear in the input. The test cases must be separated by a blank line. Refer sample output for details.

SAMPLE INPUT

1
9 1
12 67 8 75 4 30 42 54 74
2 5 10 1000
12 20 36 57 67
2 28 45 59 63
4 30 42 54 74
5 26 34 49 70
8 16 37 48 75

SAMPLE OUTPUT

Case 1:
7

Problem by: Aleksej Viktorchik; Leonid Sislo
Huge Easy Contest #2

兌獎有限定在 35, 40, 45, 75 個球內,一開始以為 "
until one of the players wins the game"
指的是直到一個勝利者出現,事實上是獨立的,看做前 75 個前即可。

#include <stdio.h>
#include <string.h>

int main() {
    int testcase, cases = 0;
    int n, m, B[5], g[1000][5][5];
    int i, j, k, A[105];
    scanf("%d", &testcase);
    while(testcase--) {
        scanf("%d %d", &n, &m);
        int ball[105] = {};
        for(i = 0; i < n; i++) {
            scanf("%d", &A[i]);
        }
        scanf("%d %d %d %d", &B[0], &B[1], &B[2], &B[3]);
        for(i = 0; i < m; i++) {
            for(j = 0; j < 5; j++)
                for(k = 0; k < 5; k++)
                    scanf("%d", &g[i][j][k]);
        }
        printf("Case %d:\n", ++cases);
        int earn[1005] = {}, kind[1005][4] = {};
        for(i = 0; i < n; i++) {
            ball[A[i]] = 1;
            for(j = 0; j < m; j++) {
                if(kind[j][0] == 0 && i < 35) {
                    if(ball[g[j][0][0]] && ball[g[j][4][0]] && ball[g[j][0][4]] && ball[g[j][4][4]]) {
                        earn[j] += B[0];
                        kind[j][0] = 1;
                    }
                }
                if(kind[j][1] == 0 && i < 40) {
                    if(ball[g[j][2][0]] && ball[g[j][2][1]] && ball[g[j][2][2]] && ball[g[j][2][3]] && ball[g[j][2][4]]) {
                        earn[j] += B[1];
                        kind[j][1] = 1;
                    }
                }
                if(kind[j][2] == 0 && i < 45) {
                    int flag = 1;
                    for(k = 0; k < 5; k++) {
                        flag &= ball[g[j][k][k]];
                        flag &= ball[g[j][k][4-k]];
                    }
                    if(flag) {
                        earn[j] += B[2];
                        kind[j][2] = 1;
                    }
                }
                if(kind[j][3] == 0) {
                    int flag = 1, p, q;
                    for(p = 0; p < 5 && flag; p++)
                        for(q = 0; q < 5 && flag; q++)
                            flag &= ball[g[j][p][q]];
                    if(flag) {
                        earn[j] += B[3];
                        kind[j][3] = 1;
                    }
                }
            }
        }
        for(i = 0; i < m; i++)
            printf("%d\n", earn[i]);
        if(testcase)    puts("");
    }
    return 0;
}

台長: Morris
人氣(629) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][greedy] 12498 - Ant's Shopping Mall
此分類上一篇:[UVA][遞迴] 939 - Genes

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文