| ||||||||||
| 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:我的程序怎么会wa!!!!!!!!,北大的大牛们看看!!!In Reply To:我的程序怎么会wa!!!!!!!!,北大的大牛们看看!!! Posted by:qmczcn at 2004-11-24 21:20:25
虽说函数没用好, 但至少是可以过的。
#include <stdio.h>
#include <iostream.h>
#include <math.h>
__int64 n;
int a[10][2];
__int64 s;
int num=0;
void swap ( int i, int j )
{
int k, l;
for ( l=0; l<2; l++ ) {
k = a[i][l];
a[i][l] = a[j][l];
a[j][l] = k;
}
}
void out ()
{
cout << num << endl;
int i, j;
for ( i=0; i<num; i++ )
for ( j=i+1; j<num; j++ )
if ( a[i][0] < a[j][0] ) swap ( i, j );
for ( i=0; i<num; i++ ) {
cout << a[i][0];
for ( j=0; j<a[i][0]; j++ )
cout << " " << a[i][1]++;
cout << endl;
}
}
void check1 ()
{
__int64 k, o, i;
for ( i=1; i<=s; i++ ) {
if ( !((3*n)%i) ) {
k = 3*n/i-2*i*i-1;
if ( !(k%6) ) {
k /= 6;
o = ( (int)sqrt(1+4*k)-1 )/2;
if ( o*(o+1)==k && o>=i ) {
a[num][0] = 2*i;
a[num++][1] = o-i+1;
}
}
}
}
}
void check ()
{
__int64 i, k, x;
for ( i=0; i<=s; i++ ) {
if ( !((3*n)%(2*i+1)) ) {
k = 3*n/(2*i+1)-i*i-i;
if ( !(k%3) ){
k/=3;
x = (int)sqrt(k);
if ( x*x==k && x>i) {
a[num][0] = 2*i+1;
a[num++][1] = x-i;
}
}
}
}
}
int main ()
{
scanf ( "%I64d", &n );
s = (__int64)pow ( n, 1/3.0 );
check1 ();
check ();
out ();
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator