UVa 151 - Power Crisis

151 - Power Crisis


思路:用queue处理关闭电力,注意N=13。


#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

int main(void) {
	int n;
	queue s;
	while (cin >> n && n != 0) {
		if (n == 13) {
			cout << "1" << endl;
			continue;
		}
		for (int i = 1; i <= n; i++)
			s.push(i);
		int m = 1;
		while (true) {
			if (s.front() != 13) {
				s.pop();
				for (int i = 0; i < m - 1; i++) {
					s.push(s.front());
					s.pop();
				}
			}
			else {
				if (s.size() == 1) {
					cout << m << endl;
					break;
				}
				m = m + 1;
				while (!s.empty())
					s.pop();
				for (int i = 1; i <= n; i++)
					s.push(i);
			}
		}
	}
	return 0;
}




你可能感兴趣的:(UVa 151 - Power Crisis)