111 - History Grading
Moderator: Board moderators
111
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
:
#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 !
111 WA
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;
}
111 Invalid memory reference
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
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:
Regards,
Suman.
Usage example:
compile code with debug info as:
Code: Select all
g++ -g filename.cpp -o executable
gdb executable
...
Suman.
http://kent.dl.sourceforge.net/sourcefo ... .2.1-1.exesumankar 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:Regards,Code: Select all
g++ -g filename.cpp -o executable gdb executable ...
Suman.
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++
Re: 111 Invalid memory reference
how can i get more information(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)
Re: 111 Invalid memory reference
Don't you see?58050zz wrote:how can i get more information(no debugging symbols found)...(gdb) run
Starting program: /win.exe
....
[snipped]

man page if you have it for that debugger info option, but surely
Code: Select all
g++ -g
Code: Select all
g++ -ggdb
After you have made g++ generate that extra info, you'll find more than
you could have ever possibly asked in that backtrace

Regards,
Suman.
111 misunderstand the problem need help
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...
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...
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.
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.

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
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
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
Thx in advance!
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;
}
keep it real!