498 - Polly the Polynomial

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

Moderator: Board moderators

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

Re: 498 TLE

Post by Obaida » Sat Feb 14, 2009 7:13 am

Help me I got TLE..

Code: Select all

removed
Ok now i know why i am TLE.. But someone please help me to allocate the eof for this program i don't know how to do it. I got TLE in another problem for this. :oops: :oops: :oops:
Last edited by Obaida on Sun Feb 15, 2009 5:40 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.

Moshiur Rahman
New poster
Posts: 13
Joined: Mon Sep 08, 2008 6:57 pm
Location: State University of Bangladesh

Re: 498 TLE

Post by Moshiur Rahman » Sat Feb 14, 2009 6:40 pm

I made the following change in your second while loop and got AC:

Code: Select all

while(1)
{
     int ret = scanf("%d%c",&c[i++],&a);
     if(ret != 2) return 0;
     if(a==10)break;
}
good luck!
Never think too hard, let ideas come to you...

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

Re: 498 TLE

Post by Obaida » Sun Feb 15, 2009 5:42 am

Thank you 2 much!! Now i can avoid TLE in some oter problems too. :)
And learned a good lesson 2. :D
try_try_try_try_&&&_try@try.com
This may be the address of success.

bill8124
New poster
Posts: 8
Joined: Fri Jan 21, 2011 8:13 am

Re: How to get even number line input???(498,10268)

Post by bill8124 » Sat Jul 28, 2012 9:18 am

Use fgets(line1, 200, stdin) instead of gets(line1)
gets() don't do any length control and may cause buffer overflow. (e.g. Write other variables and make an error in your program)

ccmoralesj
New poster
Posts: 1
Joined: Thu Mar 28, 2013 4:09 am

498 Why am i getting RTE?

Post by ccmoralesj » Thu Mar 28, 2013 4:19 am

Hi, i've been trying this problem and i have tried ALL test cases i've found, but i still getting RTE, maybe it's the way i read the input... i don't know.. if someone please could help me...

Code: Select all

import java.io.*;

public class Main{
	public static void main(String[] Args)throws IOException{
		BufferedReader read= new BufferedReader(new InputStreamReader(System.in));
		String line1,line2;
		String[] coef, exes;
		int x,polly,lengthe,lengthcoef;
		while(((line1=read.readLine())!=null)&&((line2=read.readLine())!=null)){
			line1=line1.trim();
			coef=line1.split("\\s");
			line2=line2.trim();
			exes=line2.split("\\s");
			lengthe= exes.length;
			lengthcoef= coef.length;
			for(int i=0;i<lengthe;i++){
				polly=Integer.parseInt(coef[0]);
				x=Integer.parseInt(exes[i]);
				for(int k=1;k<lengthcoef;k++){
					polly=polly*x + Integer.parseInt(coef[k]);
				}
				System.out.print(polly+" ");
			}
			System.out.println();
		}
		read.close();
		System.exit(0);
	}
}

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

Re: 498 Why am i getting RTE?

Post by brianfry713 » Thu Mar 28, 2013 9:25 pm

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

techbd123
New poster
Posts: 14
Joined: Tue Aug 06, 2013 3:42 pm

Re: 498 - polly the polynomial

Post by techbd123 » Sun Aug 11, 2013 9:24 am

Why PE in this code???
Please help me to find out.

Code: Select all

CODE REMOVED AFTER GETTING AC
Last edited by techbd123 on Sat Aug 17, 2013 2:56 pm, edited 1 time in total.

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

Re: 498 - polly the polynomial

Post by brianfry713 » Wed Aug 14, 2013 9:58 pm

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

techbd123
New poster
Posts: 14
Joined: Tue Aug 06, 2013 3:42 pm

Re: 498 - polly the polynomial

Post by techbd123 » Sat Aug 17, 2013 2:57 pm

Thanks to Guru! Brianfry.

sady
New poster
Posts: 17
Joined: Sat Dec 07, 2013 8:00 am

Re: 498 - polly the polynomial

Post by sady » Sat Dec 07, 2013 9:21 am

Can anyone plz help me, i'm getting TLE. I'm a new comer and this my first submission. Thanks in advance.

Code: Select all

 code removed after getting ac
Last edited by sady on Mon Dec 23, 2013 10:03 am, edited 1 time in total.

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

Re: 498 - polly the polynomial

Post by brianfry713 » Mon Dec 09, 2013 9:40 pm

Don't print a space or a '\b' at the end of a line.
Check input and AC output for thousands of problems on uDebug!

sady
New poster
Posts: 17
Joined: Sat Dec 07, 2013 8:00 am

Re: 498 - polly the polynomial

Post by sady » Mon Dec 23, 2013 10:13 am

:P thanks @brianfry713

zyt144
New poster
Posts: 1
Joined: Thu Mar 27, 2014 3:53 am

498 rte

Post by zyt144 » Thu Mar 27, 2014 4:00 am

Hi I tried so many times but keep getting rte... I have removed the spaces at the end of each line, and did not use Math.pow...
Can anyone help??

Code: Select all

import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader cin = new BufferedReader(new FileReader("input.txt"));
		// BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
		String line1;
		int count =0;
		while ((line1 = cin.readLine()) != null) {
			if(count!=0)
				System.out.println();
			
			String line2 = cin.readLine();
			String[] parts1 = line1.split(" ");
			String[] parts2 = line2.split(" ");
			int cl = parts1.length;
			int xl = parts2.length;
			int[] coeff = new int[cl];
			for (int i = 0; i < cl; i++) {
				coeff[i] = Integer.parseInt(parts1[i]);
			}
			int[] indep = new int[xl];
			for (int i = 0; i < xl; i++) {
				indep[i] = Integer.parseInt(parts2[i]);
			}

			for (int i = 0; i < xl; i++) {
				int x = indep[i];
				int result = 0;
				for (int j = 0; j < cl; j++) {
					int temp=1;
					for(int k=0;k<cl-1-j;k++)
						temp = temp*x;
					result = result + coeff[j]*temp;
				}
				if (i == xl-1)
					System.out.print(result);
				else
					System.out.print(result + " ");
			}
			count++;
		}
		cin.close();
	}

}

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

Re: 498 rte

Post by brianfry713 » Thu Mar 27, 2014 9:20 pm

Don't read from a file.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 4 (400-499)”