POJ 1484 Blowing Fuses(我的水题之路——我必须在心中牢记这次惨痛的教训)

Blowing Fuses
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 2652 Accepted: 1056

Description

Maybe you are familiar with the following situation. You have plugged in a lot of electrical devices, such as toasters, refrigerators, microwave ovens, computers, stereos, etc, and have them all running. But at the moment when you turn on the TV, the fuse blows, since the power drawn from all the machines is greater than the capacity of the fuse. Of course this is a great safety feature, avoiding that houses burn down too often due to fires ignited by overheating wires. But it is also annoying to walk down to the basement (or some other inconvenient place) to replace to fuse or switch it back on. 

What one would like to have is a program that checks before turning on an electrical device whether the combined power drawn by all running devices exceeds the fuses capacity (and it blows), or whether it is safe to turn it on.

Input

The input consists of several test cases. Each test case describes a set of electrical devices and gives a sequence of turn on/off operations for these devices. 

The first line of each test case contains three integers n, m and c, where n is the number of devices (n <= 20), m the number of operations performed on these devices and c is the capacity of the fuse (in Amperes). The following n lines contain one positive integer ci each, the consumption (in Amperes) of the i-th device. 

This is followed by m lines also containing one integer each, between 1 and n inclusive. They describe a sequence of turn on/turn off operations performed on the devices. For every number, the state of that particular devices is toggled, i.e. if it is currently running, it is turned off, and if it is currently turned off, it will by switched on. At the beginning all devices are turned off. 

The input will be terminated by a test case starting with n = m = c = 0. This test case should not be processed.

Output

For each test case, first output the number of the test case. Then output whether the fuse was blown during the operation sequence. The fuse will be blown if the sum of the power consumptions ci of turned on devices at some point exceeds the capacity of the fuse c. 

If the fuse is not blown, output the maximal power consumption by turned on devices that occurred during the sequence. 

Output a blank line after each test case.

Sample Input

2 2 10
5
7
1
2
3 6 10
2
5
7
2
1
2
3
1
3
0 0 0

Sample Output

Sequence 1
Fuse was blown.

Sequence 2
Fuse was not blown.
Maximal power consumption was 9 amperes.

Source


首先,这道题是一道水题(非常弱弱的说)。

这道题先给你3个数字,表示有n个电器,m次操作,电流最高流量c。之后有n个数,表示每一个电器打开时候产生的电流,接着有m个操作步骤,用数字表示,分别表示操作哪个设备,第奇数次操作是打开该设备,第偶数次操作是关闭该设备。看在所有步骤操作完之前,电流总量是否要比c大,如果是,则熔丝会烧断,如果不会,则输出不会烧断,并且输出操作过程中的最大电流量。

解题很简单,是现对于所有的设备电流保存下来,然后对于每一次操作,如果是打开,就让电流数加上打开设备的电流量。如果是关闭,就在电流数上减去设备电流。

注意点:
1)提交前要去除调试printf代码(1OLE)
2)虽然在操作过程中可能电流量已经大于c,但是不能直接break,要把所有的数据读完才能输出,否则会OLE。(2OLE)
3)不要怀疑自己已经很熟悉的C语言基础知识,比如“把输出格式的两个‘\n’分在两个printf,会有不一样的效果”,这种思维是极度错误的(1WA)
4)不要忘记去除freopen(1WA)

代码(1AC 2WA 3OLE 人生在挫折中成长/(ㄒoㄒ)/~~):
#include <cstdio>
#include <cstdlib>
#include <cstring>

int n, m, c;
int cap[25];
int turn[25];

int main(void){
    int max, tmp;
    int ii, i, j;
    int oprate;

    ii = 0;
    while (scanf("%d%d%d", &n, &m ,&c), n != 0 && m != 0 && c != 0){
        ii++;
        tmp = max = 0;
        memset(cap, 0, sizeof(cap));
        memset(turn, 0, sizeof(turn));
        for (i = 1; i <= n; i++){
            scanf("%d", &cap[i]);
        }
        for (i = 0; i < m ; i++){
            scanf("%d", &oprate);
            if (max == -1){
                continue;
            }
            if (turn[oprate] == 0){
                tmp += cap[oprate];
                if (tmp > max){
                    max = tmp;
                }
                if (max > c){
                    max = -1;
                    continue;
                }
                turn[oprate] = 1;
            }
            else if (turn[oprate] == 1){
                tmp -= cap[oprate];
                turn[oprate] = 0;
            }
        }
        printf("Sequence %d\n", ii);
        if (max == -1){
            printf("Fuse was blown.\n");
        }
        else{
            printf("Fuse was not blown.\nMaximal power consumption was %d amperes.\n", max);
        }
        printf("\n");
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值