┌ ┐ => 取無條件進位(即是取ceil值)
└ ┘ => 取無條件捨去(即是取floor值)
接著p和q就刷過各種可能即可得解。
[C](1.528)
This file contains hidden or 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
#include<stdio.h> | |
#include<math.h> | |
int main() | |
{ | |
int n; | |
while( scanf( "%d", &n ) != EOF ) | |
{ | |
int i; | |
for( i = 0 ; i < n ; i++ ) | |
{ | |
double x, k; | |
while( scanf( "%lf%lf", &x, &k ) != EOF ) | |
{ | |
double p, q, xk_floor = floor(x/k), xk_ceil = ceil(x/k); | |
int ok = 0; | |
for( p = 0 ; !ok ; p++ ) | |
for( q = 0 ; p*xk_floor + q*xk_ceil <= x && !ok ; q++ ) | |
if( p*xk_floor + q*xk_ceil == x ) | |
ok = 1; | |
p--; | |
q--; | |
printf( "%.0lf %.0lf\n", p, q ); | |
} | |
} | |
} | |
return 0; | |
} |
0 意見:
張貼留言