| ||||||||||
| 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:不用动态规划也能a啊,^-^!In Reply To:为什么老是runtime error,快崩溃了,谁能告诉我why Posted by:csuyuanxing at 2010-04-30 02:38:39 #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int b[5000000];
int a[5000000];
int n,i,j,k,m=0;
int main()
{
while(~scanf("%d",&n))
{
if(n==-1)
break;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
a[1]=1;
b[1]=1;
b[0]=1;
if(a[n]!=0&&n!=0)
printf("%d\n",a[n]);
else
{
for(i=1; i<=n; i++)
{
m=a[i-1]-i;
if(m>0)
{
if(b[m]==0)
{
a[i]=m;
b[m]=1;
}
else
{
a[i]=a[i-1]+i;
b[a[i]]=1;
}
}
else
{
a[i]=a[i-1]+i;
b[a[i]]=1;
}
}
printf("%d\n",a[n]);
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator