Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
那位老大给看看(严重超时),^-^#include <iostream> #include <string> using namespace std; bool findNext(); int k; int m; int current; basic_string<int> executeStatus; // 1 indicates executed, 0 not int main() { cin >> k; while (k != 0) { int i; bool flag; executeStatus.resize(k * 2); for (m = k + 1; ; m++) { current = 0; // initial position flag = true; for (i = 0; i < 2 * k; i++) { executeStatus[i] = 0; } for (i = 0; i < k; i++) { if (!findNext()) { flag = false; break; } } if (flag == true) { break; } } /* * output result and read the next k */ cout << m << endl; cin >> k; } return 0; } bool findNext() { int i; for (i = 0; i < m;) { if (executeStatus[current] == 0) { i++; if (i != m) { current = (current + 1) % (2 * k); } } else { current = (current + 1) % (2 * k); } } if (current < k) { return false; } else { executeStatus[current] = 1; /* * position to the next guy */ for (i = 0; i < 1;) { current = (current + 1) % (2 * k); if (executeStatus[current] == 0) { i++; } } return true; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator