[UVA12108]Extraordinarily Tired Students(模拟+水题)

最近在填紫书上的坑(以前由于浮躁没有做的习题),发现还是有很多题比较麻烦,虽然思路很容易想,但就是写不出ac代码,可能这就是眼高手低吧。希望在接下来的学习生活中,从小事做起,向着自己的目标而努力吧。
这道题挺有意思,虽然水,但是有一些细节不注意很容易wa,甚至样例都过不了。

#include <stdio.h>
#define MAXN 520

typedef struct {
    int a, b, c, period;
    int awake;
} Stu;

Stu stu[15];

int main() {
    //freopen("input.txt", "r", stdin);
    int n;
    int kase = 0;
    while(scanf("%d", &n) != EOF && n) {
        int awake;
        for(int i = 0; i < n; i++) {
            scanf("%d%d%d", &stu[i].a, &stu[i].b, &stu[i].c);
            stu[i].period = stu[i].a + stu[i].b;
            if (stu[i].a >= stu[i].c) {
                stu[i].awake = 1;
            }
            else {
                stu[i].awake = 0;
            }
        }
        int flag = 1;
        for(int t = 1; t < MAXN; t++) {
            awake = 0;
            for(int i = 0; i < n; i++) 
                if (stu[i].awake)  awake++;
            if (awake == n) {
                printf("Case %d: %d\n", ++kase, t);
                flag = 0;
                break;
            } 
            for(int i = 0; i < n; i++) {
                if (stu[i].c == stu[i].a) {
                    if (n - awake <= awake) { 
                        stu[i].c = 1;
                    }
                    else {
                        stu[i].c++;
                        stu[i].awake = 0;
                    }
                }
                else if (stu[i].c == stu[i].period) {
                    stu[i].awake = 1;
                    stu[i].c = 1;
                }
                else stu[i].c += 1;
            }
        }
        if (flag)  printf("Case %d: -1\n", ++kase);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值