地址http://acm.scs.bupt.cn/onlinejudge/showproblem.php?problem_id=1337
Rugs Submit: 87 Accepted:43 Time Limit: 1000MS Memory Limit: 65535KDescription
Rugs come in various sizes. In fact, we can find a rug with any integer width and length, except that no rugs have a distinct width and length that are both even integers. For example, we can find a 4*4 rug, but not a 2*4 rug. We want to know how many different choices we have for a given area.
Create a class RugSizes the contains a method rugCount that is given the desired area and returns the number of different ways in which we can choose a rug size that will cover that exact area. Do not count the same size twice -- a 6*9 rug and a 9*6 rug should be counted as one choice.
Input
A single integer T, the number of cases. Then the following T lines, each case per line, there is only one integer S, representing the area, which is less than 2*10^9.
Output
For each case, output a single integer N, the number of ways.
Sample Input
2
4
8
Sample Output
2
1
Source
Chiara
#include<iostream>
using namespace std;
int a[100000];
int main()
{
int i,j,n,x,count,other;
while(cin>>n)
{
for(i=0;i<n;i++)
{
count=0;
x=1;
cin>>a[i];
while(x*x<=a[i])
{
other=a[i]%x;
if(x%2==1&&other==0)
{
count++;
}
else if(x%2==0&&other==0)
{
if((a[i]/x)%2==1)
{
count++;
}
else if(x*x==a[i])
{
count++;
break;
}
}
x++;
} //while
a[i]=count;
} //for
for(i=0;i<n;i++)
cout<<a[i]<<endl;
}//while
system("pause");
return 0;
}
思路 按奇数偶数划分,如果x的平方大于了a[i],那么x之后的组合一定与X之前的某个组合重复,可以不再继续计算。