UVa 12108 特别困的学生

https://vjudge.net/problem/UVA-12108

题意:给出n个学生的“清醒—睡眠”周期和初始时间点,每个学生在睡眠时需要判断全班睡觉人数是否严格大于清醒人数,否则在坚持一个清醒周期后再次判断。求出多长时间时全班都是清醒状态。

思路:水题吧。一次次的枚举下去,循环终止的条件就是和初始状态相同。

 1 #include<iostream>
 2 using namespace std;
 3
 4 struct Node
 5 {
 6     int A;
 7     int B;
 8     int C;
 9 }stu[12];
10 int ans[12];
11
12 int main()
13 {
14     //freopen("D:\\txt.txt", "r", stdin);
15     int n,sleep,kase=0;
16     while (cin >> n && n)
17     {
18         sleep = 0;
19         for (int i = 0; i < n; i++)
20         {
21             cin >> stu[i].A >> stu[i].B >> stu[i].C;
22             ans[i] = stu[i].C;
23             if (stu[i].C>stu[i].A) sleep++;    //统计初始睡着人数
24         }
25         int count = 0;
26         for (int k=1;;k++)
27         {
28
29             if (sleep == 0)
30             {
31                 cout << "Case " << ++kase << ": " << k << endl;
32                 break;
33             }
34
35             if (count == n)
36             {
37                 cout << "Case " << ++kase << ": -1" << endl;
38                 break;
39             }
40
41             count = 0;
42             int flag = 0;
43
44             for (int i = 0; i < n; i++)
45             {
46                 ans[i] = ans[i] % (stu[i].A + stu[i].B)+1;
47                 if (ans[i] == 1)   flag--;
48                 if (ans[i] == stu[i].A + 1)
49                 {
50                     if (sleep <= n - sleep)
51                         ans[i] = 1;
52                     else flag++;
53                 }
54                 if (ans[i] == stu[i].C)  count++;
55             }
56             sleep += flag;
57         }
58     }
59     return 0;
60 }
时间: 2024-08-10 11:51:42

UVa 12108 特别困的学生的相关文章

对那些家庭经济特别艰难的学生

主要是每年的GDP里面固定资产的投资都超过了百分之五六十,你像发达国度,8 23011900805 23010303002 23010202426 81 36 10. 6 1 进入双语测试 43 45 64 仁那措 黄南藏族自治州同仁县小学先生英语(面向六州)(藏汉双语)2名 5 9.52 1 57 7.4 48 40 3 49 39 1 更藏吉 黄南藏族自治州同仁县小学老师数学(面向六州)(藏汉双语)3名 1 45.一个成熟的本人技巧,他为了著名,曹德旺:感激人家给你的机遇,不少企业家抱怨做实

UVa 12412 A Typical Homework(学生信息管理系统)

A Typical Homework(a.k.a Shi Xiong Bang Bang Mang) Hi, I am an undergraduate student in institute of foreign languages. As you know, C programming is a required course in our university, even if his/her major is far from computer science. I don't lik

UVA - 12108 Extraordinarily Tired Students(模拟)

Extraordinarily Tired Students Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description When a student is too tired, he can't help sleeping in class, even if his favorite teacher is right here in front of hi

Uva 12108 Extraordinarily Tired Students

题意: 课堂上有n个学生(n<=10).每个学生都有一个“清醒-睡眠”周期.其中第i个学生醒 ai 分钟后睡 bi 分钟,然后重复(1<=ai,bi<=5),初始时第i个学生处在他的周期的第 ci 分钟.每个学生在临 睡前会察看全班睡觉人数是否严格大于清醒人数,只有这个条件满足时才睡觉,否则就坚持听课 ai 分钟后再次检查这个条件.问经过多长时间后全班都清醒. 思路: 用优先队列记录每次要更改的时间和对应要更改状态的学生编号,按要更改的时间从小到大排序. cnt记录当前睡觉的人数. 这里

【模拟】UVa 12108 - Extraordinarily Tired Students

When a student is too tired, he can't help sleeping in class, even if his favorite teacher is right here in front of him. Imagine you have a class of extraordinarily tired students, how long do you have to wait, before all the students are listening

【习题 4-8 UVA - 12108】Extraordinarily Tired Students

[链接] 我是链接,点我呀:) [题意] [题解] 一个单位时间.一个单位时间地模拟就好. 然后对于每个人. 记录它所处的周期下标idx 每个单位时间都会让每个人的idx++ 注意从醒着到睡着的分界线的处理就好. 可以多循环几次..超过上限认为无解 (其他题解也提供了一种方法,就是如果状态和初始的情况相同的话.就无解了即形成了一个环. (可能如果无解一定会形成环? [代码] #include <bits/stdc++.h> #define rep1(i,a,b) for (int i = a;

算法竞赛入门经典 第四章

[√ ] UVA1339 古老的密码 Ancient Cipher [√ ] UVA489 刽子手的游戏 Hangman Judge [√ ] UVA133 救济金发放 The Dole Queue [√ ] UVA213 信息解码 Message Decoding [√ ] UVA512 追踪电子表格中的单元格 Spreadsheet Tracking [√ ] UVA12412 师兄帮帮忙 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)

UVa 11375 Matches

大年夜的写代码果然状态非常之差...感觉特别困,连个高精度都折腾了我好久.还是刘汝佳<训练指南>里的一道例题,解题思路其实也差不多,但是想对书里面的内容再讲讲.其中d[i]是代表i个火柴棒恰好能构成的正整数数目(不包含整数0),然后有点类似于动态规划的做法,通过已知的d[]求出剩下的d[]. 不过仔细想来貌似有点问题.例如已知d[j],那么d[j+num[0]]+=d[j].那么新加的数字0是不是应该也有好几种排列方式呢?例如d[j]中有一个数字123,那么d[j+num[0]]是不是应该有1

李开复给中国学生的第三封信:成功、自信、快乐(上)

2004年5月 此前,我和中国学生的多次交流都是围绕如何达到优秀和卓越.如何成为领导人才而展开的.最近,在新浪网的聊天室和我收到的许多电子邮件中,我发现更多的中国学生需要知道的不是如何从优秀到卓越,而是如何从迷茫到积极.从失败到成功.从自卑到自信.从惆怅到快乐.从恐惧到乐观. 一个极端的例子是2004年2月发生在云南大学的马加爵事件.马加爵残忍地杀害了自己的4名同学.但从马家爵被捕后与心理学家的对话内容看来,他应该不是一个邪恶的人,而是一个迷失方向.缺乏自信.性格封闭的孩子.他和很多大学生一样,