23dfcca431 2011-02-23 kinaba: //----------------------------------------------------------------------------- d103994d4c 2012-02-11 kinaba: // >>Code Template<< (for Visual C++ 11) 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: #include <iostream> 23dfcca431 2011-02-23 kinaba: #include <sstream> 23dfcca431 2011-02-23 kinaba: #include <iomanip> 23dfcca431 2011-02-23 kinaba: #include <vector> d103994d4c 2012-02-11 kinaba: #include <string> 23dfcca431 2011-02-23 kinaba: #include <map> d103994d4c 2012-02-11 kinaba: #include <set> 23dfcca431 2011-02-23 kinaba: #include <algorithm> 23dfcca431 2011-02-23 kinaba: #include <numeric> 23dfcca431 2011-02-23 kinaba: #include <iterator> 23dfcca431 2011-02-23 kinaba: #include <functional> d103994d4c 2012-02-11 kinaba: #include <complex> 23dfcca431 2011-02-23 kinaba: #include <queue> 23dfcca431 2011-02-23 kinaba: #include <stack> 23dfcca431 2011-02-23 kinaba: #include <cmath> 23dfcca431 2011-02-23 kinaba: #include <cassert> 23dfcca431 2011-02-23 kinaba: #include <cstring> d103994d4c 2012-02-11 kinaba: #include <tuple> 23dfcca431 2011-02-23 kinaba: using namespace std; 23dfcca431 2011-02-23 kinaba: typedef long long LL; 23dfcca431 2011-02-23 kinaba: typedef complex<double> CMP; 23dfcca431 2011-02-23 kinaba: void END_OF_INPUT_FOR_THIS_TEST_CASE(); // stub for multi-threading 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: //----------------------------------------------------------------------------- 23dfcca431 2011-02-23 kinaba: // >>Main<< 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: void case_main( ostream& os ) 23dfcca431 2011-02-23 kinaba: { 23dfcca431 2011-02-23 kinaba: END_OF_INPUT_FOR_THIS_TEST_CASE(); 23dfcca431 2011-02-23 kinaba: } 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: //----------------------------------------------------------------------------- 23dfcca431 2011-02-23 kinaba: // >>Code Template<< (Multi-Thread Solver) 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: #if 1 23dfcca431 2011-02-23 kinaba: #undef cout 23dfcca431 2011-02-23 kinaba: #include <windows.h> 23dfcca431 2011-02-23 kinaba: #include <process.h> 23dfcca431 2011-02-23 kinaba: d103994d4c 2012-02-11 kinaba: static const int THREAD_NUM = 4; 23dfcca431 2011-02-23 kinaba: volatile int g_id; 23dfcca431 2011-02-23 kinaba: int g_nCase; 23dfcca431 2011-02-23 kinaba: CRITICAL_SECTION g_cs; 23dfcca431 2011-02-23 kinaba: vector<string> g_output; 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: unsigned __stdcall thread_main( void* t_id ) { 23dfcca431 2011-02-23 kinaba: for(;;) { 23dfcca431 2011-02-23 kinaba: EnterCriticalSection(&g_cs); 23dfcca431 2011-02-23 kinaba: const int id = ++g_id; 23dfcca431 2011-02-23 kinaba: if(id>g_nCase) { LeaveCriticalSection(&g_cs); break; } 23dfcca431 2011-02-23 kinaba: cerr << setw(4) << id << " @ " << (int)t_id << " start" << endl; 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: ostringstream ss; 23dfcca431 2011-02-23 kinaba: ss << "Case #" << id << ": "; 23dfcca431 2011-02-23 kinaba: case_main( ss ); 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: EnterCriticalSection(&g_cs); 23dfcca431 2011-02-23 kinaba: if(g_output.size()<id) g_output.resize(id); 23dfcca431 2011-02-23 kinaba: g_output[id-1] = ss.str(); 23dfcca431 2011-02-23 kinaba: cerr << setw(4) << id << " @ " << (int)t_id << " end" << endl; 23dfcca431 2011-02-23 kinaba: LeaveCriticalSection(&g_cs); 23dfcca431 2011-02-23 kinaba: } 23dfcca431 2011-02-23 kinaba: return 0; 23dfcca431 2011-02-23 kinaba: } 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: void END_OF_INPUT_FOR_THIS_TEST_CASE() { LeaveCriticalSection(&g_cs); } 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: int main() { 23dfcca431 2011-02-23 kinaba: cin >> g_nCase; 23dfcca431 2011-02-23 kinaba: string dummy; getline(cin, dummy); 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: InitializeCriticalSection(&g_cs); 23dfcca431 2011-02-23 kinaba: vector<HANDLE> thread; 23dfcca431 2011-02-23 kinaba: for(int i=0; i<THREAD_NUM; ++i) 23dfcca431 2011-02-23 kinaba: thread.push_back( (HANDLE)_beginthreadex(0, 0, &thread_main, (void*)i, 0, 0) ); 23dfcca431 2011-02-23 kinaba: WaitForMultipleObjects( thread.size(), &thread[0], TRUE, INFINITE ); 23dfcca431 2011-02-23 kinaba: DeleteCriticalSection(&g_cs); 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: copy( g_output.begin(), g_output.end(), ostream_iterator<string>(cout) ); 23dfcca431 2011-02-23 kinaba: } 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: //----------------------------------------------------------------------------- 23dfcca431 2011-02-23 kinaba: // >>Code Template<< (Single-Thread Solver) 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: #else 23dfcca431 2011-02-23 kinaba: #undef cout 23dfcca431 2011-02-23 kinaba: void END_OF_INPUT_FOR_THIS_TEST_CASE() {} 23dfcca431 2011-02-23 kinaba: int main() { 23dfcca431 2011-02-23 kinaba: int nCase; cin >> nCase; 23dfcca431 2011-02-23 kinaba: string dummy; getline(cin, dummy); 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: for(int id=1; id<=nCase; ++id) { 23dfcca431 2011-02-23 kinaba: cout << "Case #" << id << ": "; 23dfcca431 2011-02-23 kinaba: case_main( cout ); 23dfcca431 2011-02-23 kinaba: } 23dfcca431 2011-02-23 kinaba: } 23dfcca431 2011-02-23 kinaba: #endif