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 |
难道是所有的TEST CASE算1000MS,我的对于单独的我都测了,貌似不会超时。除非是所有的TEST CASE算一次时间。。。 用的是暴力。。。 #include <iostream> using namespace std; int ways; void process ( int v ) { int i, j, m, n, a, b, c, d; for ( i = 0, a = i * i; i <= 512; i++, a = i * i ) { if ( a > v ) break; for ( j = i, b = j * j; j <= 512; j++, b = j * j ) { if ( a + b > v ) break; for ( m = j, c = m * m; m <= 512; m++, c = m * m ) { if ( a + b + c > v ) break; for ( n = m, d = n * n; n <= 512; n++, d = n * n ) { if ( a + b + c + d > v ) break; if ( a + b + c + d == v ) ways++; } } } } } int main () { int n; while ( cin >> n ) { if ( n == 0 ) break; ways = 0; process ( n ); cout << ways << endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator