10696 - f91

All about problems in Volume 106. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

10696 - f91

Post by abhi » Thu Dec 15, 2005 10:30 am

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 ?????

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun » Thu Dec 15, 2005 4:29 pm

Your idea is alright. Check your output format and you need long for this problem.

User avatar
Zaspire
New poster
Posts: 36
Joined: Sun Apr 23, 2006 2:42 pm
Location: Russia

Why my program use so many memory?

Post by Zaspire » Thu Jun 15, 2006 12:26 pm

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;
}

Deny Sutani
New poster
Posts: 6
Joined: Fri Jun 01, 2007 7:20 am

Re: Why my program use so many memory?

Post by Deny Sutani » Sun Jun 03, 2007 2:00 pm

Zaspire wrote:Why my program use 440 :-? memory?(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;
}
Maybe that one will be better. My code only use 396, but still not good at all :(

yiuyuho
A great helper
Posts: 325
Joined: Thu Feb 21, 2002 2:00 am
Location: United States
Contact:

Post by yiuyuho » Sun Jun 03, 2007 6:55 pm

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.

ahmed
New poster
Posts: 9
Joined: Tue Mar 17, 2009 6:36 pm

Re: 10696 - f91

Post by ahmed » Sat Apr 04, 2009 8:19 pm

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;
}

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10696 - f91

Post by Obaida » Sun Apr 05, 2009 8:19 pm

Replace the input/output by scanf and printf :D
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.

wasifhossain
New poster
Posts: 3
Joined: Tue Apr 28, 2009 7:26 pm

Re: 10696 - f91

Post by wasifhossain » Tue Jan 03, 2012 7:47 pm

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;
}
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!

Enayet Kabir
New poster
Posts: 7
Joined: Mon Jun 04, 2012 3:03 pm

UVA Problem ID :10696(Why I am getting Presentation error?)

Post by Enayet Kabir » Thu Jun 14, 2012 10:09 pm

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)));
}

brianfry713
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

Post by brianfry713 » Fri Jun 15, 2012 9:04 pm

That is AC code.
Check input and AC output for thousands of problems on uDebug!

sith
Learning poster
Posts: 72
Joined: Sat May 19, 2012 7:46 pm

Re: 10696 - f91

Post by sith » Tue Jun 26, 2012 10:59 pm

Hello
I've got WA, Why?

Here is my solution

Code: Select all

AC
Last edited by sith on Wed Jun 27, 2012 8:13 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10696 - f91

Post by brianfry713 » Tue Jun 26, 2012 11:56 pm

Don't print the runtime at the end.
Check input and AC output for thousands of problems on uDebug!

sith
Learning poster
Posts: 72
Joined: Sat May 19, 2012 7:46 pm

Re: 10696 - f91

Post by sith » Wed Jun 27, 2012 8:13 pm

Thanks, my stupid mistake :)

raihan_sust5
New poster
Posts: 6
Joined: Tue Jul 23, 2013 3:04 am

Re: 10696 - f91

Post by raihan_sust5 » Tue Jul 23, 2013 10:14 am

i didn't get that how caluculate the f91 for N<= 100......anyone help please..

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10696 - f91

Post by brianfry713 » Wed Jul 24, 2013 3:32 am

If N <= 100 then f91(N) = 91.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 106 (10600-10699)”