+1
To apib2007 --- I tried to "sticky" this post but did not get it. Could you do that?
[此贴子已经被作者于2007-7-20 16:19:02编辑过]
I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
[此贴子已经被作者于2007-7-20 16:19:02编辑过]
umm, smart and detailed analysis ... ,GO ON.
For Example, when N = 2 and M = 3, there are 6 squares size of 1 * 1 and 2 squares size of 2 * 2 in the chessboard, so the answer is 8.
Input
There are several lines in the input, each line consist of two positive integers N and M (1 <= N <= 100, 1 <= M <= 100) except the last line which N = 0 and M = 0 implying the end of the input and you should not process it.
Output
Please output the number of the squares for each chessboard in a single line.
Sample Input
1 1
2 3
3 3
0 0
Sample Output
1
8
14
#include <iostream>
using namespace std;
#define max(x, y) ((x)>(y)?(x):(y))
int num(int, int);int main()
{
int N, M, ar[50];
int i=0;
while( cin>>N>>M )
{
if( N<0|| N>100 || M<0 || M>100 ) exit(-1);
ar[i]=N;
ar[i+1]=M;
if(ar[i]==0 && ar[i+1]==0 ) break;
i+=2;
}
for(int j=0; ar[j]!=0 && ar[j+1]!=0; j+=2, cout<<endl)
cout<<num(ar[j], ar[j+1]);return 0;
}
int num(int n, int m)
{int sum = 0;
for(int i=2; i<=max(n, m); ++i)
if( n >= i && m >= i)
{
if( n*m ==i*i ) sum += 1;
else
sum += ( m-i+1 )*( n-i+1 );
}
return sum+n*m;
}
[此贴子已经被作者于2007-7-21 15:41:13编辑过]
怎样在那些做题目的网站里看别人的答案啊?