| ||||||||||
| 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 | |||||||||
实在受不了了?试了N个数,但不知道错在哪里。。谁能给个特殊数据??#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int n;
cin>>n;
int arr[31];
int a,b,c;
int i;
double k;
k=sqrt(double(n));
a=k;
b=n/a;
c=n%a;
for(i=0;i<a;i++)
arr[i]=b-a/2+i;
if(a%2==0)
{
for(i=a/2;i<a;i++)
arr[i]++;
i=a/2;
while(c>0&&i>0)
{
arr[--i]++;
c--;
}
while(c>0)
{i=a-1;
arr[i--]++;
c--;
}
}
else
{
i=a-1;
while(c>0)
{arr[i--]++;
c--;
}
}
for(i=0;i<a;i++)
cout<<arr[i]<<" ";
cout<<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