10037 - Bridge
Moderator: Board moderators
-
- Learning poster
- Posts: 83
- Joined: Wed Feb 27, 2002 2:00 am
- Location: Taiwan
[c]#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#define MAX 1000
int n;
int src[MAX+1],dest[MAX+1];
int totalcost,process[(MAX+1)*100][2],list;
void output()
{
int i,p,q;
printf("%d\n",totalcost);
for(i=0;i<=list;i++){
p=process[0];
q=process[1];
if( p > q && q!=-1) p^=q^=p^=q;
if(p!=-1) printf("%d",p);
if(q!=-1) printf(" %d",q);
printf("\n");
}
}
void solve()
{
int i,j,k;
int cost;
int finish=0;
totalcost=0;
list=-1;
memset(process,-1,sizeof(process));
list++;
for( i=1,j=0,cost=0 ; i<=n && j<2 ; i++ )
if( src!=-1 ) {
j++;
dest=src;
src=-1;
finish++;
if( cost<dest ) cost=dest;
process
#include "string.h"
#include "stdlib.h"
#define MAX 1000
int n;
int src[MAX+1],dest[MAX+1];
int totalcost,process[(MAX+1)*100][2],list;
void output()
{
int i,p,q;
printf("%d\n",totalcost);
for(i=0;i<=list;i++){
p=process[0];
q=process[1];
if( p > q && q!=-1) p^=q^=p^=q;
if(p!=-1) printf("%d",p);
if(q!=-1) printf(" %d",q);
printf("\n");
}
}
void solve()
{
int i,j,k;
int cost;
int finish=0;
totalcost=0;
list=-1;
memset(process,-1,sizeof(process));
list++;
for( i=1,j=0,cost=0 ; i<=n && j<2 ; i++ )
if( src!=-1 ) {
j++;
dest=src;
src=-1;
finish++;
if( cost<dest ) cost=dest;
process
- [j-1]=dest;
}
totalcost+=cost;
if(finish==n) return;
++list;
for( i=1 ; i<=n ; i++ )
if( dest!=-1 ) {
src[i]=dest[i];
dest[i]=-1;
finish--;
totalcost+=src[i];
process- [0]=src[i];
break;
}
while( finish<n ){
/*go to dest*/
if( ( n-finish ) == 3 && n%2 ){
cost=0;
list++;
for( i=1 ; i<=n ; i++ )
if( src[i]!= -1 ){
dest[i]=src[i];
src[i]=-1;
if( cost<dest[i] ) cost=dest[i];
finish++;
process- [0]=dest[i];
break;
}
for( i=n ; i>=1 ; i--)
if( src[i]!= -1 ){
dest[i]=src[i];
src[i]=-1;
if( cost<dest[i] ) cost=dest[i];
finish++;
process- [1]=dest[i];
break;
}
totalcost+=cost;
}else{
++list;
for( i=n,j=0,cost=0 ; i>=1 && j<2 ; i-- )
if( src[i]!= -1 ){
dest[i]=src[i];
src[i]=-1;
finish++;
j++;
if(cost<dest[i]) cost=dest[i];
process- [j-1]=dest[i];
}/*if*/
totalcost+=cost;
}/*else*/
if(finish==n) break;
list++;
for(i=1;i<=n;i++)
if(dest[i]!=-1){
src[i]=dest[i];
dest[i]=-1;
totalcost+=src[i];
finish--;
process- [0]=src[i];
break;
}
}/*while*/
}
int cmp(const void *a,const void *b)
{
return *(int *)a-*(int *)b;
}
void main()
{
int N,i,temp,kk=0;
scanf("%d",&N);
for(;N;N--){
if(kk==0) printf("\n");
kk++;
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d",&temp);
src[i]=temp;
}
src[0]=-1;
memset(dest,-1,sizeof(dest));
qsort(src,n+1,sizeof(src[0]),cmp);
solve();
output();
}
}[/c]
I think my program is right
but why I always got WA?
please help me~!
- [0]=src[i];
- [j-1]=dest[i];
- [1]=dest[i];
- [0]=dest[i];
- [0]=src[i];
- Moni
- Experienced poster
- Posts: 202
- Joined: Fri Mar 22, 2002 2:00 am
- Location: Chittagong. CSE - CUET
- Contact:
Re: What's going on with 10037?
Hai! what do you mean by this? How did you get judge solution ???Revenger wrote: But I have judge solution! What's wrong?


To Revenger:
I am not sure what's going on. But I guessed that the judge may modify the input by adding some tricky case..... It is usually that I can solve the "judge input", but still got WA.....
To Moni:
"judge solution" means the input/output files used during the regional/online contest. It is easy to check if such files exist on the network: copy a sentence from the problem specification to google and search, then you will know.....
I am not sure what's going on. But I guessed that the judge may modify the input by adding some tricky case..... It is usually that I can solve the "judge input", but still got WA.....
To Moni:
"judge solution" means the input/output files used during the regional/online contest. It is easy to check if such files exist on the network: copy a sentence from the problem specification to google and search, then you will know.....
My signature:
- Please make discussion about the algorithm BRFORE posting source code.
We can learn much more in discussion than reading source code. - I HATE testing account.
- Don't send me source code for debug.
10037 Bridges
I programmed this problem and got wrong answer.
But I can't find any bug in my program!!
Is there any trick?
But I can't find any bug in my program!!
Is there any trick?
hmmm... this qq (Q10037) looks interesting 
Could anyone plz suggest some test cases for which different strategies should be applied (with output, plz
)? Thx in adv.

Could anyone plz suggest some test cases for which different strategies should be applied (with output, plz

7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org