題意:
(from luckycat)
解法: 找規律去推導結果。
TAG: ad hoc
注意:
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Tittle: 10182 - Bee Maja | |
* Author: Cheng-Shih, Wong | |
* Date: 2015/05/09 | |
*/ | |
// include files | |
#include <iostream> | |
#include <cstdio> | |
#include <cstring> | |
using namespace std; | |
// definitions | |
#define FOR(i,a,b) for( int i=(a),_n=(b); i<=_n; ++i ) | |
#define clr(x,v) memset( x, v, sizeof(x) ) | |
// declarations | |
int n; | |
int x, y; | |
int pre[200]; | |
// functions | |
// main function | |
int main( void ) | |
{ | |
pre[0] = 1; | |
for( int i=0; pre[i] <= 100000; ++i ) | |
pre[i+1] = pre[i]+(i+1)*6; | |
int v, u, cnt, tmp; | |
bool neg; | |
// input | |
while( scanf( "%d", &n )==1 ) { | |
if( n==1 ) { | |
puts("0 0"); | |
continue; | |
} | |
// solve | |
for( v=1; pre[v]<n; ++v ); | |
u = pre[v-1]+1; | |
if( n-u >= v*3 ) { | |
neg = true; | |
n -= v*3; | |
} else { | |
neg = false; | |
} | |
x = v-1; y = 1; | |
cnt = n-u; | |
tmp = v-1; | |
while( cnt && tmp ) { | |
x -= 1; | |
y += 1; | |
--cnt; --tmp; | |
} | |
tmp = v; | |
while( cnt && tmp ) { | |
x -= 1; | |
--cnt; --tmp; | |
} | |
tmp = v; | |
while( cnt && tmp ) { | |
y -= 1; | |
--cnt; --tmp; | |
} | |
if( neg ) { | |
x = -x; | |
y = -y; | |
} | |
printf( "%d %d\n", x, y ); | |
} | |
return 0; | |
} |
沒有留言:
張貼留言
任何意見都樂意傾聽