10696 - f91
Moderator: Board moderators
10696 - f91
i get WA for this problem.
for all test cases <=100 i get the ans as 91 and for>=101 i get n-10 as ans
any test cases ?????
for all test cases <=100 i get the ans as 91 and for>=101 i get n-10 as ans
any test cases ?????
Why my program use so many memory?
Why my program use 440
memory?(10696)
#include <iostream>
int main()
{
int n,k;
std::cin>>n;
while (n!=0)
{
if (n<=100) k=91;
else k=n-10;
std::cout<<"f91("<<n<<") = "<<k<<std::endl;
std::cin>>n;
}
return 0;
}
![:-?](./images/smilies/icon_confused.gif)
#include <iostream>
int main()
{
int n,k;
std::cin>>n;
while (n!=0)
{
if (n<=100) k=91;
else k=n-10;
std::cout<<"f91("<<n<<") = "<<k<<std::endl;
std::cin>>n;
}
return 0;
}
-
- New poster
- Posts: 6
- Joined: Fri Jun 01, 2007 7:20 am
Re: Why my program use so many memory?
Maybe that one will be better. My code only use 396, but still not good at allZaspire wrote:Why my program use 440memory?(10696)
#include <iostream>
int main()
{
int n,k;
std::cin>>n;
while (n!=0)
{
if (n<=100) std::cout<<"f91("<<n<<") = "<<91<<std::endl;
else std::cout<<"f91("<<n<<") = "<<n-10<<std::endl;
std::cin>>n;
}
return 0;
}
![:(](./images/smilies/icon_frown.gif)
Probably an error in the memory calculation, you can pay no attention to it if you get AC.
I remember a few years back the memory calculation are just totally off for some problems, I can allocate a 2M int array and it says I use 64KB....
But I think they've fixed a lot of those already and most are accurate. Still, can have bugs here.
I remember a few years back the memory calculation are just totally off for some problems, I can allocate a 2M int array and it says I use 64KB....
But I think they've fixed a lot of those already and most are accurate. Still, can have bugs here.
Re: 10696 - f91
I am getting TLE in this problem.But I don't know why.Can anyone please help me?
Code: Select all
#include<iostream>
using namespace std;
int f91(int n)
{
if(n<=100)
{
return f91(f91(n+11));
}
else if(n>=101)
return n-10;
}
int main(void)
{
int n;
while(cin>>n)
{
if(n==0)
return 0;
cout<<"f91("<<n<<") = "<<f91(n)<<endl;
}
return 0;
}
Re: 10696 - f91
Replace the input/output by scanf and printf ![:D](./images/smilies/icon_biggrin.gif)
you can directly use this for all test cases <=100 i get the ans as 91 and for>=101 i get n-10 as ans by an if. No need for this f91 function.
![:D](./images/smilies/icon_biggrin.gif)
you can directly use this for all test cases <=100 i get the ans as 91 and for>=101 i get n-10 as ans by an if. No need for this f91 function.
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
-
- New poster
- Posts: 3
- Joined: Tue Apr 28, 2009 7:26 pm
Re: 10696 - f91
Yours One is a Naive Straight-forward approach. Try to find the TRICK inside the recursive case by simulating some small cases(N <= 100) using your existing solution above. You'll find a simple number again & again! Now the rest is left upon you. Enjoy!ahmed wrote:I am getting TLE in this problem.But I don't know why.Can anyone please help me?Code: Select all
#include<iostream> using namespace std; int f91(int n) { if(n<=100) { return f91(f91(n+11)); } else if(n>=101) return n-10; } int main(void) { int n; while(cin>>n) { if(n==0) return 0; cout<<"f91("<<n<<") = "<<f91(n)<<endl; } return 0; }
-
- New poster
- Posts: 7
- Joined: Mon Jun 04, 2012 3:03 pm
UVA Problem ID :10696(Why I am getting Presentation error?)
Here is my source code:
=========================
#include<stdio.h>
long N,result;
long int Mc(long int );
int main()
{
while(scanf("%ld",&N)==1)
{
if(N==0) break;
else
{
result=Mc(N);
printf("f91(%ld) = %ld\n",N,result);
}
}
return 0;
}
long Mc(long int N)
{
if(N>=101)
return (N-10);
else
return (Mc(Mc(N+11)));
}
=========================
#include<stdio.h>
long N,result;
long int Mc(long int );
int main()
{
while(scanf("%ld",&N)==1)
{
if(N==0) break;
else
{
result=Mc(N);
printf("f91(%ld) = %ld\n",N,result);
}
}
return 0;
}
long Mc(long int N)
{
if(N>=101)
return (N-10);
else
return (Mc(Mc(N+11)));
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: UVA Problem ID :10696(Why I am getting Presentation erro
That is AC code.
Check input and AC output for thousands of problems on uDebug!
Re: 10696 - f91
Last edited by sith on Wed Jun 27, 2012 8:13 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10696 - f91
Don't print the runtime at the end.
Check input and AC output for thousands of problems on uDebug!
Re: 10696 - f91
Thanks, my stupid mistake ![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
-
- New poster
- Posts: 6
- Joined: Tue Jul 23, 2013 3:04 am
Re: 10696 - f91
i didn't get that how caluculate the f91 for N<= 100......anyone help please..
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10696 - f91
If N <= 100 then f91(N) = 91.
Check input and AC output for thousands of problems on uDebug!