347 - Run

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

Moderator: Board moderators

deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

347 - Run

Post by deddy one »

got TLE after rejudge.
do I have to precalculate all of the runaround number??? :o

any hint??? :roll:
eloha
New poster
Posts: 38
Joined: Thu Oct 31, 2002 8:24 am
Location: Taiwan

Post by eloha »

Yes, I do.
I got AC in 7 sec.
Masud(IIUC)
New poster
Posts: 1
Joined: Wed Dec 24, 2003 12:03 pm

please help me

Post by Masud(IIUC) »

My code is TLE. I can realize that for input 9999998 my code is TLE.
Can anyone please say me what is the output for it. :D
sergio
New poster
Posts: 23
Joined: Sun Jun 22, 2003 11:24 pm
Location: Natal-Brazil
Contact:

Re: please help me

Post by sergio »

I didn't get accepted, but I think the bigger runaround number is 9682415. Am I correct??
Ming Han
Learning poster
Posts: 77
Joined: Thu Jun 06, 2002 7:10 pm
Location: Singapore
Contact:

Post by Ming Han »

I think you are correct, i.e. the biggest number is 9682415.
I generated 448 runaround numbers in total.
:: HanWorks ::
Sakib
New poster
Posts: 24
Joined: Fri Jan 28, 2005 5:27 pm
Location: Bangladesh

problem 347 WAAAA!!!!!!!

Post by Sakib »

i generate all the 448 run around numbers.
then i just print the number greater or equal to input;
all output seems ok.
but i m getting WAAAAAA!!!!!!!!!!! :x

someone please help!
i m going crazy.........................
the biggest number is 96.... something like this.
what will be the output for .........
9999999 ???????

please help me.............
/* Sorry For Nothing */
mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Re: problem 347 WAAAA!!!!!!!

Post by mamun »

Sakib wrote:what will be the output for .........
9999999 ???????
Well, I don't think there is input greater than the largeest run-around number. Problem maybe somewhere else. Check your output format.
Sakib
New poster
Posts: 24
Joined: Fri Jan 28, 2005 5:27 pm
Location: Bangladesh

Post by Sakib »

Thanks for help.

i dont understand what could be wrong.
here is my code :

Code: Select all

Cut After ACC.
please check it to see the output format is correct.
tell me what is wrong..........
Last edited by Sakib on Tue Nov 15, 2005 9:18 pm, edited 1 time in total.
/* Sorry For Nothing */
mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun »

After giving a lot of time to your program I found the bug. You forgot to initiate the array in isDiff() function.
Sakib
New poster
Posts: 24
Joined: Fri Jan 28, 2005 5:27 pm
Location: Bangladesh

Post by Sakib »

Ups !!!!!!!

That was a stupid mistake.
ACC now.
Many Many thanks to u for help.
My code was working well with sample input and output in my PC without initializing the arr[] in isDiff().

But really that mistake was stupid. i should not do that mistake.

Anyway thanks again mamun.
/* Sorry For Nothing */
sclo
Guru
Posts: 519
Joined: Mon Jan 23, 2006 10:45 pm
Location: Vancouver, BC, Canada
Contact:

Post by sclo »

Easiest way is to precompute all runaround numbers, then binary search. If you want to have AC in 0.0 time, just precompute the numbers in a table.
StatujaLeha
Learning poster
Posts: 91
Joined: Tue May 31, 2005 2:01 pm
Location: Russia

347 Run, Run, Runaround Numbers

Post by StatujaLeha »

Hi all! I am interested in who how solved it? I did precompute some values of the runaround numbers at my computer and insert them to a programm as an array. If an input number is greater than the lowest array's element and is lower than the biggest array's element then i find answer in the array. Otherwise i check all the value that bigger or equal to input number until i found runaround number.
I want to know is there a more effective algorithm?
5olio
New poster
Posts: 4
Joined: Wed Jun 18, 2008 1:23 pm

Re: 347 Run, Run, Runaround Numbers

Post by 5olio »

Any Special Cases Please

There is my code

Code: Select all

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

string Number;
bool Visited[10];

bool allVisited()
{
	for(int i = 0; i < Number.length(); i ++)
		if(Visited[i] == false)
			return false;
			
	return true;
}

bool isRunaroundNumber(int Index)
{
	if(Index == 0 && allVisited())
	{
		return true;
	}
		
	if(!Visited[Index])
	{
		Visited[Index] = true;
		
		int Next = (Index + Number[Index]  - 48);
		
		if(Next >= Number.length())
		 		Next %= Number.length();
		 		
		isRunaroundNumber(Next);
	}
}

void addOne(string& Number)
{
	
	for(int i = 0; i < Number.length(); i ++)
		if(Number[i] == '0')
			Number[i] ++;
	
	reverse(Number.begin(), Number.end());
	
	int Index = 0;
	Number[Index] += 1;
	
	while(Number[Index] > '9')
	{
		
		Number[Index ++] -= 9;
			
		if(Index == Number.length())
			Number += "1";
		else
			Number[Index] += 1;
	}
	
	reverse(Number.begin(), Number.end());
}

bool DigitsAreUnique(string& Number)
{
	for(int i = 0; i < Number.length(); i ++)
	{
		for(int j = i + 1; j < Number.length(); j ++)
		{
			if(Number[i] == Number[j])
				return false;
		}
	}
	return true;
}

void removeLeadingZeros(string& Number)
{
	string Temp = "";
	bool First = true;
	for(int i = 0; i < Number.length(); i ++)
	{
		if(Number[i] != '0' && First)
			First = false;
			
		if(!First)
			Temp += Number[i];
	}
	
	Number = Temp;
}

int main()
{
	freopen("ACM.in", "r", stdin);
	
	for(int Case = 1; getline(cin, Number) && Number != "0"; Case++)
	{
		removeLeadingZeros(Number);
		fill(Visited, Visited + 10, false);
		
		while(!DigitsAreUnique(Number) || !isRunaroundNumber(0))
		{
			addOne(Number);
			fill(Visited, Visited + 10, false);
		}
		
		cout << "Case " << Case << ": " << Number << endl;
	}
	return 0;
}
Thanks
dejavu_logic
New poster
Posts: 6
Joined: Sat Mar 06, 2010 8:30 am

347 Java Runtime Error (Again?!?!)

Post by dejavu_logic »

Previously I posted a topic in this Volume III board about getting java runtime error on problem 343
but I didn't get any reply or solution
Then I moved on to another problem which is problem 347 and I still got runtime error (again) using java

Here is my code

Code: Select all

// @JUDGE_ID:  250890  374  Java  "Big Mod"

import java.io.BufferedReader;
//import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Scanner;

class BigModMain {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
//        Scanner in = new Scanner(new FileInputStream(new File("input")));
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        
        BigInteger b = BigInteger.ZERO;
        BigInteger p = BigInteger.ZERO;
        BigInteger m = BigInteger.ZERO;
        
        while (in.hasNext()) {
            b = in.nextBigInteger();
            p = in.nextBigInteger();
            m = in.nextBigInteger();
            System.out.println(b.modPow(p, m));
        }

        in.close();
        return;
    }

}
Please anyone,
I desperately need a solution on this error
I know probably using C/C++ is one of the solution but I don't know C/C++ programming well
Therefore I need to know how to submit source code in java programming in UVa OnlineJudge

Any solution will be very appreciated
Thx.
bobSHIH
New poster
Posts: 4
Joined: Thu Feb 13, 2014 6:58 am

Re: problem 347 WAAAA!!!!!!!

Post by bobSHIH »

well I don't know what happened on my code
I always got WA
but I can't find out where my problem is,format? Or something I miss?
I don't know
pls someone for help!!!!!

Code: Select all

delete after AC
Last edited by bobSHIH on Thu Feb 20, 2014 9:46 am, edited 1 time in total.
Post Reply

Return to “Volume 3 (300-399)”