WA 231 Testing the catcher

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

Moderator: Board moderators

gettin wa plz some one help

Postby Sadasidha08 » Fri Jun 18, 2010 8:24 pm

#include<iostream.h>
#include<stdlib.h>

#define MAX 100000

void swap(long& x,long& y)
{
int t=x;
x=y;
y=t;
}
int max(int x,int y)
{
if(x>y)
return x;
else
return y;
}

long arry[MAX][MAX]={0,};
int main()
{
long ar1[MAX],ar2[MAX];

long n,t=0,i,j,k;

while(1)
{
t++;
cin>>n;
if(n==-1)
break;
j=0;
while(1)
{
ar2[j]=ar1[j]=n;
for(k=j;k>0;k--)
{
if(ar2[k]>ar2[k-1])
swap(ar2[k],ar2[k-1]);
}
cin>>n;
j++;
if(n==-1)
break;


}


int m=j;

for(i=1;i<=m;i++)
{
for(j=1;j<=m;j++)
{
if(ar1[i-1]==ar2[j-1])
arry[i][j]=arry[i-1][j-1]+1;
else
arry[i][j]=max(arry[i][j-1],arry[i-1][j]);
}
}


if(t!=1)
cout<<"\n";

cout<<"Test #"<<t<<":\n";
cout<<" maximum possible interceptions: "<<arry[m][m];

}


return 0;
}
Sadasidha08
New poster
 
Posts: 3
Joined: Mon Apr 05, 2010 8:09 pm

Re: WA 231 Testing the catcher

Postby riger400 » Wed May 14, 2014 11:53 pm

can anyone help me I'm getting WA again and again, here is my code
[/code]

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

public class Main{

static int[] motherArray = new int[33000];
static int arrayCounter = 0;

public static void main(String[] args) throws IOException {
BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
//BufferedReader obj = new BufferedReader(new FileReader("D://uva.txt"));
PrintWriter prin = new PrintWriter(System.out);
String line;
int testCase = 0;
while ((line = obj.readLine()) != null) {
int num = Integer.parseInt(line);
if (num >= 0) {
motherArray[arrayCounter] = num;
arrayCounter++;
} else if (num == -1) {
testCase++;
LIS(testCase);

Arrays.fill(motherArray, 0);
arrayCounter = 0;
}

}
prin.flush();
}

public static void LIS(int test) {
if (arrayCounter == 0) {
return;
}
PrintWriter prin = new PrintWriter(System.out);
String[] length = new String[arrayCounter];
int[] size = new int[arrayCounter];
for (int i = 0; i < arrayCounter; i++) {
size[i] = 1;
length[i] = motherArray[i] + " ";
}
int maxLength = 1;
for (int i = 1; i < arrayCounter; i++) {
for (int j = 0; j < i; j++) {
if (motherArray[i] <= motherArray[j] && size[i] < size[j] + 1) {
size[i] = size[j] + 1;
length[i] = length[j] + motherArray[i] + " ";
if (maxLength < size[i]) {
maxLength = size[i];
}
}
}
}
String line = "";

prin.println("Test #" + test + ":");
prin.println(" maximum possible interceptions: " + maxLength);
prin.println();
prin.flush();
}
}
riger400
New poster
 
Posts: 1
Joined: Thu May 01, 2014 7:50 am

Re: WA 231 Testing the catcher

Postby brianfry713 » Thu May 15, 2014 8:29 pm

There should be two spaces before maximum.
brianfry713
Guru
 
Posts: 3423
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Previous

Return to Volume II

Who is online

Users browsing this forum: No registered users and 1 guest