24h購物| | PChome| 登入
2012-08-30 22:57:00| 人氣250| 回應0 | 上一篇 | 下一篇

[PTC] 201208A Defect Alarms [模擬]

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

Problem Description
Company A has several production lines. These production lines have a
global timer for synchronization. Workers feed in raw materials into a mixer
machine, and then the mixed material is dispatched to these production lines
so as to yield products. Every product has a unique product number for
quality control. A product number has three elds of the form ppp-ttttttt-q,
where ppp is a three-digit number representing the production line, ttttttt is
a seven-digit number representing the manufacture time (in seconds), and q
is a single digit for indicating the quality of this product.
The product may have defects due to a malfunction of a machine or
an incomplete mixture of the raw material. If a machine malfunctions, the
defective rate of the production line containing this malfunctioning machine
becomes high. On the other hand, once the raw material is not mixed well,
the defective rates of all production lines rise. Write a program that reads a
series of product numbers and outputs an alarm message instantly if one or
both of the following two types of event occur.
 The rst type of event is that the number of defective products yielded
by a single production line in t1 seconds is greater than or equal to k1.
 The second type of event is that the total number of defective products
yielded by all production lines in t2 seconds is greater than or equal to
k2.


看懂題目其實就很簡單了, 是在 t 秒內, 並不是 0~t 秒,
英文比較容易卡這個, 剩下的就不說了


#include <stdio.h>
#include <stdlib.h>
typedef struct {
    int p, t, q;
}DD;
DD D[10000];
int cmp(const void *i, const void *j) {
    DD *a, *b;
    a = (DD *)i, b = (DD *)j;
    return a->t - b->t;
}
int main() {
    int t, t1, t2, k1, k2, n;
    int i, p, tt, q;
    scanf("%d", &t);
    while(t--) {
        scanf("%d %d %d %d %d", &t1, &t2, &k1, &k2, &n);
        for(i = 0; i < n; i++) {
            scanf("%d-%d-%d", &p, &tt, &q);
            D[i].p = p, D[i].t = tt, D[i].q = q;
        }
        qsort(D, n, sizeof(DD), cmp);
        int mm[1000] = {}, flag = 0, j = 0;
        for(i = 0; i < n; i++) {
            while(j < n && D[j].t < D[i].t-t1) {
                if(D[j].q == 1)
                    mm[D[j].p]--;
                j++;
            }
            if(D[i].q == 1) {
                mm[D[i].p]++;
                if(mm[D[i].p] >= k1)
                    flag = 1;
            }
        }
        j = 0;
        int total = 0;
        for(i = 0; i < n; i++) {
            while(j < n && D[j].t < D[i].t-t2) {
                if(D[j].q == 1)
                    total--;
                j++;
            }
            if(D[i].q == 1) {
                total++;
                if(total >= k2)
                    flag = 1;
            }
        }
        puts(flag ? "ALARM" : "GOOD");
    }
    return 0;
}
/*
3
2 1 2 3 6
000-0000000-1
000-0000001-1
001-0000000-0
001-0000002-0
003-0000003-0
001-0000000-0
2 1 2 3 6
000-0000000-0
000-0000001-1
001-0000000-0
001-0000001-1
003-0000001-1
006-0000001-0
2 1 2 3 6
000-0000000-0
000-0000001-1
001-0000000-0
005-0000001-0
001-0000009-0
011-0000001-0
*/

台長: Morris
人氣(250) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: 資訊競賽 |
此分類下一篇:[PTC] 201208C RFC 1149
此分類上一篇:[PTC] 201208D Instant Noodles [馬可夫鏈]

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