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 |
请高手帮着看看, 总是RE , 感激!!!#include "stdio.h" #include "stdlib.h" __int64 pow_ex(__int64 x, __int64 y) { __int64 i; __int64 mul = 1; for ( i = 0; i < y; i++ ) { mul = mul * x; } return mul; } int main() { // deal with inputs __int64 nCase; scanf( "%I64d", &nCase ); if ( nCase <=0 ) { return 0; } __int64 **pInputs = (__int64**)malloc( 0x000FFFFF ); __int64 i, total, cant, pos, nMaxTotal = 1; for ( i = 0; i < nCase; i++ ) { scanf("%I64d %I64d %I64d", &total, &cant, &pos); if ( (pos+cant-1) > total ) { *(pInputs+i) = (__int64*)malloc( sizeof(__int64) ); **(pInputs+i) = -1; } else { *(pInputs+i) = (__int64*)malloc( 3*sizeof(__int64) ); **(pInputs+i) = total; *(*(pInputs+i) + 1) = cant; *(*(pInputs+i) + 2) = pos; if ( total > nMaxTotal ) { nMaxTotal = total; } } /* else */ } /* for */ // build map table __int64 nBits = 0; do { nMaxTotal = nMaxTotal >> 1; nBits++; } while( nMaxTotal != 0 ); //__int64 *MapTable = (__int64*)malloc( sizeof(__int64)*( pow_ex(2, nBits)) ); int *MapTable = (int*)malloc( 0x000FFFFF ); __int64 j; MapTable[0] = 0; MapTable[1] = 1; for ( i = 2; i <= nBits; i++ ) { for ( j = (__int64)pow_ex(2, i-1); j < ( (__int64)pow_ex(2, i-1) + (__int64)pow_ex(2, i) )/2; j++ ) { MapTable[j] = MapTable[(__int64)pow_ex(2, i-2) + (j - (__int64)pow_ex(2, i-1))]; } for ( j = ( (__int64)pow_ex(2, i-1) + (__int64)pow_ex(2, i) )/2; j < (__int64)pow_ex(2, i); j++ ) { MapTable[j] = MapTable[ j - (__int64)pow_ex(2, i-2) ] + 1; } } // output results __int64 nStart, nSum; for ( i = 0; i < nCase; i++ ) { printf("Case %I64d:", i+1); if ( **(pInputs+i) == -1 ) { printf(" It cannot be solved.\n"); continue; } nStart = *(*(pInputs+i) + 2); nSum = *(*(pInputs+i) + 1); for ( j = 0; j < nSum; j++ ) { printf(" %d", MapTable[nStart+j]); } printf("\n"); } free(MapTable); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator