标签:相同 node .net 需要 problem 循环 freopen div clu
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 }
标签:相同 node .net 需要 problem 循环 freopen div clu
原文地址:http://www.cnblogs.com/zyb993963526/p/6308858.html