111 - History Grading

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

Moderator: Board moderators

Post Reply
PerHagen
New poster
Posts: 23
Joined: Thu Oct 14, 2004 1:45 am
Location: lima

111

Post by PerHagen »

my code is
:

#include <stdio.h>
#include <iostream.h>
int calcula(int arreglo[],int arreglo2[],int n);
int ubica(int num,int arreglo[],int cant);
void main(void)
{ int a[30],b[30],n,m,i,tec,temp;


cin >> n;
for (m=1;m<=n;m++)
{
scanf("%d",&tec);
a[tec-1]=m;
}


while(scanf("%d",&temp)==1)
{
b[temp-1]=1;
for(i=2;i<=n;i++)
{

scanf("%d",&tec) ;
if ((tec-1)!=(temp-1)) b[tec-1]=i;

}
int precio=calcula(a,b,n);
cout << precio <<endl;
}


}
int calcula(int arreglo[],int arreglo2[],int n)
{
int max=-1,i,pos,k,pos2;
for (i=0;i<n;i++)
{
pos=ubica(arreglo2,arreglo,n);

k=i;int consecutivos=0;

while ((0<k) && (0<pos))
{
pos2=ubica(arreglo[pos-1],arreglo2,n);
if (pos2<k)
{
k=pos2;

consecutivos++;
}

pos--;

}

k=i; pos=ubica(arreglo2,arreglo,n);

while ((k<n) && (pos<(n-1)))
{
pos2=ubica(arreglo[pos+1],arreglo2,n);
if (k<pos2)
{
k=pos2;

consecutivos++;
}
pos++;
}

consecutivos++;
if (consecutivos> max ) max=consecutivos;
}
return max;
}

int ubica(int num,int arreglo[],int cant)
{
int encontrado=0,pos=0;
while ((encontrado==0)&& (pos < cant))
{
if (num==arreglo[pos]) encontrado=1;
else pos++;
}

return pos;
}

but i w.a. i don't undestand
I/O???
bye
hello !
jambon_vn
New poster
Posts: 15
Joined: Wed Sep 29, 2004 6:03 am

111 WA

Post by jambon_vn »

Here is my code. I already pasted input test. Can anyone point out my mistake?

Code: Select all

#include <iostream>

using namespace std;

int N;
int A[25], B[25], C[25], D[25][25];

int main()
{
	cin >> N;
	int i, j, ans;
	for (i = 1; i <= N; i++) 
	{	
		int k;
		cin >> k;
		A[k] = i;
	}

	for (i = 1; i <= N; i++)
		for (j = i + 1; j <= N; j++) D[A[i]][A[j]] = 1;

	while (! cin.eof())
	{
		ans = 1;
		for (i = 1; i <= N; i++) 
		{
			int k;
			cin >> k;
			B[k] = i;
			C[i] = 1;
		}	
	
		for (i = 1; i <= N; i++)
			for (j = 1; j < i; j++)
			{				
				if (D[B[j]][B[i]] == 1 && C[j] + 1 > C[i]) C[i] = C[j] + 1;
				if (ans < C[i]) ans = C[i];
			}		
	
		cout << ans << "\n";
	}
	return 0;
}
58050zz
New poster
Posts: 38
Joined: Sat Feb 26, 2005 8:13 am

111 Invalid memory reference

Post by 58050zz »


if use VC++ no error
use g++ ===>run time error
if input
10
3 1 2 4 9 5 10 6 8 7
1 2 3 4 5 6 7 8 9 10
4 7 2 3 10 6 9 1 5 8
3 1 2 4 9 5 10 6 8 7
2 10 1 3 8 4 9 5 7 6<===watch this
output
6
5
10
===>Run time error
if input
10
3 1 2 4 9 5 10 6 8 7
2 10 1 3 8 4 9 5 7 6<===watch this
output
9
==========exit with "no" (Run time)error==========
if input
10
3 1 2 4 9 5 10 6 8 7
2 10 1 3 8 4 9 5 7 6
1 2 3 4 5 6 7 8 9 10<===input anything will run time error

Code: Select all

int long_rank(int rank_ans[20],int rank_data[20],int n)
{//this function makes run time error

	int longest=0;
	int temp_long=0;
	int position=0;
	int quit=0;
	for(int start=0;start<n;start++)
	{//start for rank_ans[20]
		if(longest>(n-start)) break;
		temp_long=0;
		position=0;
	for(int i=start;i<n-1,position<n;i++)
	{
		quit=0;
		for(int j=position;j<n;j++)
		{
			if(i==n || j==n) break;
			if(i<n-3)
			{
				if(
				rank_ans[i+1]==rank_data[j]
				|| rank_ans[i+2]==rank_data[j]
				|| rank_ans[i+3]==rank_data[j])
				quit++;
				if(quit==2) break;

			}
			else if(i==n-3)
			{
				if(
				rank_ans[i+1]==rank_data[j]
				|| rank_ans[i+2]==rank_data[j])
				quit++;
				if(quit==2) break;
			}
			if(rank_ans[i]==rank_data[j])
			{
				position=j+1;
				temp_long++;
				break;				
			}
		}
		
	}
	if(temp_long-1>longest)  longest=temp_long-1;
	}
	return longest;
}

int main()
{

#define ans_p 0;
	int n,i,j,num=0;
	cin>>n;

	int rank_ans[20];
	int rank_data[20];
	int longest_rank=0;
	int data[MAX][20]={0};
	int score=0;
	bool breakflag=false;

	i=0;
	while(cin>>data[num][i])
	{
		if(cin.eof()) 
		{
			break;
		}			
		if(i==n-1) 
		{
			num++;
			i=0;
			continue;
		}
		i++;
	}
	for(i=0;i<n;i++)
	{
		rank_ans[data[0][i]-1]=i+1;
	}

/*	for(i=0;i<n;i++)
	{
		printf("%2d,",rank_ans[i]);
	}*/

	
	for(i=1;;i++)
	{
		score=0;
		if(data[i][0]==0)
		{
			break;
		}
		for(j=0;j<n;j++)
		{
			if(data[i][j]==data[0][j])
			{
				score++;
			}
			rank_data[data[i][j]-1]=j+1;
		}
	/*	for(j=0;j<n;j++)
		{
			printf("%2d,",rank_data[j]);
		}
		printf("\n");*/
		score+=long_rank(rank_ans,rank_data,n);
		if(score>n) score=n;
		cout<<score<<endl;
	}	
	return 0;
	
}

who can tell me where i can get g++ with debug
my g++ have no debug

this is my g++
Bloodshed Dev-C++ 4.0

can i get c++ compiler and IDE same as judge system
sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

Post by sumankar »

G++ is a compiler, if you need to use a debugger, get one.G++ can't help you there.Use gdb/dbx/adb/ddd - whatever is available on your system.
Usage example:
compile code with debug info as:

Code: Select all

g++ -g filename.cpp -o executable
gdb executable
...
Regards,
Suman.
58050zz
New poster
Posts: 38
Joined: Sat Feb 26, 2005 8:13 am

Post by 58050zz »

sumankar wrote:G++ is a compiler, if you need to use a debugger, get one.G++ can't help you there.Use gdb/dbx/adb/ddd - whatever is available on your system.
Usage example:
compile code with debug info as:

Code: Select all

g++ -g filename.cpp -o executable
gdb executable
...
Regards,
Suman.
http://kent.dl.sourceforge.net/sourcefo ... .2.1-1.exe
i get gdb here

type g++ -g filename.cpp -o executable
and run executable.exe
but nothing happen~

can i use it like the debug of MS VC++
58050zz
New poster
Posts: 38
Joined: Sat Feb 26, 2005 8:13 am

Re: 111 Invalid memory reference

Post by 58050zz »

(no debugging symbols found)...(gdb) run
Starting program: /win.exe

Program received signal SIGSEGV, Segmentation fault.
0x004012ce in ?? ()
(gdb) where
#0 0x004012ce in ?? ()
#1 0x00401537 in ?? ()
#2 0x004011c1 in ?? ()
#3 0x004011eb in ?? ()
#4 0x7c816d4f in ?? ()
(gdb) print
The history is empty.
(gdb)
how can i get more information
sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

Re: 111 Invalid memory reference

Post by sumankar »

58050zz wrote:
(no debugging symbols found)...(gdb) run
Starting program: /win.exe
....
[snipped]
how can i get more information
Don't you see? 8) There are no debug informations!So check the g++
man page if you have it for that debugger info option, but surely

Code: Select all

 g++ -g 
didn't work on your system.So go and try

Code: Select all

 g++ -ggdb 
and let us know.

After you have made g++ generate that extra info, you'll find more than
you could have ever possibly asked in that backtrace :D
Regards,
Suman.
58050zz
New poster
Posts: 38
Joined: Sat Feb 26, 2005 8:13 am

Re: 111 Invalid memory reference

Post by 58050zz »

Code: Select all

 g++ -ggdb 
and let us know.

i use
g++ -ggdb abc.cpp
it creat one a.exe
sunnycare
Learning poster
Posts: 74
Joined: Tue Mar 08, 2005 2:35 am
Location: China , Shanghai

111 misunderstand the problem need help

Post by sunnycare »

input:
10
3 1 2 4 9 5 10 6 8 7
2 10 1 3 8 4 9 5 7 6

output:
9



why the output is 9? i think it is 5...
neno_uci
Experienced poster
Posts: 104
Joined: Sat Jan 17, 2004 12:26 pm
Location: Cuba

Post by neno_uci »

Please note that what is given in the input is the position of the i-th event in the chronological order, for example, in your input:

10
3 1 2 4 9 5 10 6 8 7
2 10 1 3 8 4 9 5 7 6

that means that in the correct order, event 1 is in the 3rd position, event 2 is in the first position..., like this:

2 3 1 4 6 8 10 9 5 7

and the order of the order of the student is then:

3 1 4 6 8 10 9 5 7 2, and the LCS of that is 9 - (3 1 4 6 8 10 9 5 7)

Do you understand now?
I hope yes,

Yandry. 8)
sunnycare
Learning poster
Posts: 74
Joined: Tue Mar 08, 2005 2:35 am
Location: China , Shanghai

Post by sunnycare »

thanks very much!

i really misunderstand it...
jakabjr
Learning poster
Posts: 56
Joined: Wed Mar 23, 2005 9:21 pm
Location: Timisoara, Romania

Post by jakabjr »

10x for the explanation, it got my code AC too.
If any admin is reading this, I saw the warning near the prob name, but I didn't understand what it meant... Maybe you shuold make things more clear, it's not like you're giving away the answer, just clarifying the problem :)
Understanding a problem in a natural way will lead to a natural solution
ibrahim
Experienced poster
Posts: 149
Joined: Mon Feb 07, 2005 10:28 pm
Location: Northern University, Bangladesh
Contact:

Post by ibrahim »

I don't know if you allready got AC.

I test your code and find that it makes a extra output at the last line.
Sample output:
1
2
3
Your output is:
1
2
3
3
please test your code using file input. :D

Reagards,
Ibrahim
jaracz
Learning poster
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland

Post by jaracz »

I agree
keep it real!
jaracz
Learning poster
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland

Post by jaracz »

I passed sample in/out and these in this post, but still WA
I need some critical input, or hint..

Here's my code if someone wants to check it

Code: Select all

#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

vector <int> modify(vector <int> a)
{
    vector <int> pom(a);
    for(int i = 0; i < a.size(); i++)
    pom[a[i]-1] = i+1;
    return pom;
}    

int main()
{
    int n,a,pos,pos2,points;scanf("%d",&n);
    vector <int> order,current;
    back_insert_iterator<vector<int> > iter(order),iter2(current);
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&a);
        *iter = a;
    }
    order = modify(order);
    while(scanf("%d",&a)==1)
    {
        *iter2 = a;
        for(int i = 1; i < n; i++)
        {
            scanf("%d",&a);
            *iter2 = a;
        }
        current = modify(current);
        points = 1;
        pos = find(order.begin(),order.end(),current[0]) - order.begin();
        for(int i = 1; i < n; i++)
        {
            pos2 = find(order.begin(),order.end(),current[i]) - order.begin();
            if(pos2>pos)points++;
            pos = pos2;
        }
        printf("%d\n",points);
        current.clear();
    }
    return 0;
}     
Thx in advance!
keep it real!
Post Reply

Return to “Volume 1 (100-199)”