标签:
比较简单,加一个B数组判重即可
Time Limit: 3000MS | Memory Limit: 60000K | |
Total Submissions: 21743 | Accepted: 9287 |
Description
Input
Output
Sample Input
7 10000 -1
Sample Output
20 18658
Source
1 //oimonster 2 #include<cstdio> 3 #include<cstdlib> 4 #include<iostream> 5 using namespace std; 6 int a[500001],b[10000000]={0}; 7 int main(){ 8 int i,j,n,m; 9 a[0]=0; 10 b[0]=1; 11 for(i=1;i<=500000;i++){ 12 m=a[i-1]-i; 13 if((m<=0)||(b[m]==1)){ 14 a[i]=a[i-1]+i; 15 b[a[i]]=1; 16 } 17 else{ 18 a[i]=m; 19 b[m]=1; 20 } 21 } 22 scanf("%d",&n); 23 while(n!=-1){ 24 printf("%d\n",a[n]); 25 scanf("%d",&n); 26 } 27 return 0; 28 }
标签:
原文地址:http://www.cnblogs.com/oimonster/p/4321143.html