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 |
实在不明白为什么会RA搞好久了,谁能帮我测试一下#include <iostream> #include <cmath> #include <fstream> using std::cout; using std::endl; using std::ifstream; using std::cin; //ifstream cin( "in.txt" ); const int MAXLENGTH = 11; const int MAXNUM = 500001; const int ITEMNUM = 37; struct Internal{ int left; int right; }; struct Leaf{ char name[MAXLENGTH]; int turn; }; union Content{ public: Leaf l; Internal i; }; struct Node{ Content c; bool isleaf; }; Node* child; int (*tableItem)[2]; int n; int curN; int nameStart; int totalFloor; int targetItemIdx; void build( int node, int num ){ if( num == 1 ){ cin >> child[node].c.l.name; cin >> child[node].c.l.turn; child[node].isleaf = true; return; } int m = num / 2; child[node].c.i.left = m; child[node].c.i.right = num - child[node].c.i.left; child[node].isleaf = false; build( node * 2, child[node].c.i.left ); build( node * 2 + 1, child[node].c.i.right ); return; } void pick( int turn , int localTurn, int node ){ if( child[node].isleaf ){ curN --; if( n - curN == tableItem[targetItemIdx][0] ) cout << child[node].c.l.name << ' ' << tableItem[targetItemIdx][1] << endl; else{ if( child[node].c.l.turn < 0 ){ int temp = (turn -2 - child[node].c.l.turn) % curN + 1 ; pick( temp, temp, 1 ); } else{ int temp = curN - (( curN - turn ) + child[node].c.l.turn ) % curN ; pick( temp, temp, 1 ); } } } else{ if( child[node].c.i.left >= localTurn ){ child[node].c.i.left--; pick( turn, localTurn, node * 2 ); } else{ child[node].c.i.right--; pick( turn, localTurn - child[node].c.i.left, node * 2 + 1 ); } } } int main(){ child = new Node[MAXNUM * 3]; //clock_t start = clock(); int theTableItem[ITEMNUM + 1][2] = { 1,1,2,2,4,3,6,4,12,6,24,8,36,9,48,10,60,12, 120,16,180,18,240,20,360,24,720,30,840,32, 1260,36,1680,40,2520,48,5040,60,7560,64, 10080,72,15120,80,20160,84,25200,90,27720,96, 45360,100,50400,108,55440,120,83160,128, 110880,144,166320,160,221760,168,277200,180, 332640,192,498960,200, 554400,216, 665280, 224 }; tableItem = theTableItem; // cout << table[MAXNUM -1][0] << endl; //cout << "time_used:" << clock() - start << endl; int k; while( !cin.eof()){ cin >> n >> k; //cin.ignore(); curN = n; int l = -1; int r = ITEMNUM + 1; while( l != r -1 ){ int m = ( l + r )/ 2; if( n >= tableItem[m][0] ) l = m; else r = m; } targetItemIdx = l; build( 1, n ); pick( k, k, 1 ); } delete []child; delete []tableItem; //system( "pause" ); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator