|
|
back to boardTime limet Test 10 How to solve? // nalgoritm.cpp : Defines the entry point for the console application. // //#include "stdafx.h" //#include "conio.h" #include "stdio.h" short *A; int *B; int n,i; int last; int co; void fun() { int stack=A[i]; for(int j=0;j<i;j++) { if(A[j]==stack&&B[j]!=(-1)) { last=B[j]; co=j; } } A[co]=(-1); } int main() { int j,nom,zn,k; char c; int element; i=k=0; scanf("%d",&n); A=new short int[n]; B=new int[n]; while(i<n){ j=0; scanf("%c",&c) ; while( c!=' ') { scanf("%c",&c); j++; } if(j==4) { scanf("%d",&nom); A[k]=nom; B[k]=(-1); k++; } else{ scanf("%d %d",&nom,&zn); A[k]=nom; B[k]=zn; k++; } i++; } for(i=0;i<n;i++) { if(B[i]==(-1)) { fun(); printf("%d\n",last); } } //getch(); } Re: Time limet Test 10 TLE because you got O(N^2). |
|
|