Hints:using dynamic programming
Provlen link
solution:
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
int i,n,next,cards[500000+1];
cards[1]=1;
cards[2]=2;
next=2;
for(i=3;i<=500000;i++)
{
if(i<next) next=2; cards[i]=next;
next+=2;
}
while(cin>>n)
{
if(n==0) break;
else cout<<cards[n]<<endl;
}
return 0;
}
Provlen link
solution:
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
int i,n,next,cards[500000+1];
cards[1]=1;
cards[2]=2;
next=2;
for(i=3;i<=500000;i++)
{
if(i<next) next=2; cards[i]=next;
next+=2;
}
while(cin>>n)
{
if(n==0) break;
else cout<<cards[n]<<endl;
}
return 0;
}
0 comments:
একটি মন্তব্য পোস্ট করুন