Page 5 of 33

help,help,help:about data input of 102

Posted: Sat Aug 03, 2002 7:50 am
by hello world
1> when i use c++ :
[cpp] while(!cin.eof()){for(i=0;i<8;i++) cin>>n;}[/cpp]
i got wa;
2>when i use c++:
[cpp] while(cin>>n[0]>>n[1]......>>n[8]){};[/cpp]
i pass;
3>when i use c:
[c]while (!feof(stdin)){};[/c]
i pass;
why? can somebody tell me?

Just a simply edit!

Posted: Wed Aug 07, 2002 5:18 pm
by 1_UtterBlue
You may have misunderstanding its output regular. It requires one to output the alphabetically first string representing a minimal configuration should be printed. You may have miss that! Try again! Good luck! :D

Help 102!!

Posted: Thu Aug 15, 2002 11:23 am
by knight823
:cry:
please~~~~anyone can tell me!!
what's wrong!!

#include <iostream>
using namespace std;

void main()
{
do
{
int b[3][3],t[6];
int a=0,i,j,min;
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
cin>>b[j];
t[0]=b[1][1]+b[2][1]+b[0][2]+b[2][2]+b[0][0]+b[1][0];
t[1]=b[1][1]+b[2][1]+b[0][0]+b[2][0]+b[0][2]+b[1][2];
t[2]=b[1][2]+b[2][2]+b[0][1]+b[2][1]+b[0][0]+b[1][0];
t[3]=b[1][2]+b[2][2]+b[0][0]+b[2][0]+b[0][1]+b[1][1];
t[4]=b[1][0]+b[2][0]+b[0][1]+b[2][1]+b[0][2]+b[1][2];
t[5]=b[1][0]+b[2][0]+b[0][2]+b[2][2]+b[0][1]+b[1][1];
min=t[0];
for(i=1;i<=5;i++)
{
if(min>=t){min=t;a=i;}
}
switch(a)
{
case 0:cout<<"GCB";break;
case 1:cout<<"GBC";break;
case 2:cout<<"CGB";break;
case 3:cout<<"CBG";break;
case 4:cout<<"BGC";break;
case 5:cout<<"BCG";break;
}
cout<<" "<<min;
}
while(cin!=0);
}

Posted: Fri Aug 16, 2002 5:01 am
by Sisco Bermejo
quoted from problem description:

"If more than one order of brown, green, and clear bins yields the minimum number of movements then the alphabetically first string representing a minimal configuration should be printed. "

Good luck

prob 102. Is there any trick on input data?

Posted: Tue Sep 17, 2002 2:46 am
by dserrano
I

Posted: Wed Sep 18, 2002 8:56 am
by zerocool
In this problem, the reason why I get WA is "output format".
For example, When we output
123456789
It's may be transformed.
1.2E8
( The answer may be not correct. Just for example )
Unluckily, the output should be 123456789, so, do you get what I mean ?
:wink:
Best Regards

Posted: Wed Sep 18, 2002 9:57 pm
by dserrano
Can it happen with long integers?
I

Why WA 102 SOS!

Posted: Sun Sep 22, 2002 4:20 am
by ee
/*@JUDGE_ID: 23416EM 102 C++ ""*/
@BEGIN_OF_SOURCE_CODE
#include<stdio.h>
#include<stdlib.h>
void main()
{
long a[10];
long b[4],g[4],c[4];
long aa,bb,cc;
long dd,ee;
int k;
int q[50];
long total[7];
long aaa,bbb,ccc,ddd,eee,fff;
int digit=-1;
int i;
while(1){

for(i=1;i<50;i++)
q=-1;

i=49;

k=scanf("%d%d%d%d%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);
if(k!=9) break;
b[1]=a[1];b[2]=a[4];b[3]=a[7];
g[1]=a[2];g[2]=a[5];g[3]=a[8];
c[1]=a[3];c[2]=a[6];c[3]=a[9];
aaa=total[1]=b[2]+b[3]+c[1]+c[3]+g[1]+g[2];
bbb=total[2]=b[2]+b[3]+c[1]+c[2]+g[1]+g[3];
ccc=total[3]=b[1]+b[3]+c[2]+c[3]+g[1]+g[2];
ddd=total[4]=b[2]+b[1]+c[2]+c[3]+g[1]+g[3];
eee=total[5]=b[1]+b[3]+c[1]+c[2]+g[3]+g[2];
fff=total[6]=b[2]+b[1]+c[1]+c[3]+g[3]+g[2];

aa=(total[1]<total[2])?total[1]:total[2];
bb=(total[3]<total[4])?total[3]:total[4];
cc=(total[5]<total[6])?total[5]:total[6];

dd=(aa<bb)?aa:bb;
ee=(dd<total[6])?dd:total[6];
while(1){
if(ee==aaa){printf("BCG ");break;}
if(ee==bbb){printf("BGC ");break;}
if(ee==ccc){printf("CBG ");break;}
if(ee==ddd){printf("CGB ");break;}
if(ee==eee){printf("GBC ");break;}
if(ee==fff){printf("GCB ");break;}}

do{
digit=ee-ee/10*10;
ee=ee/10;
q=digit;
i--;
}while(ee>=1);
for(i=1;i<50;i++)
{
if(q==-1)continue;
printf("%d",q);
}
}
}
@END_OF_SOURCE_CODE

Hi

Posted: Wed Sep 25, 2002 8:07 am
by 21743NX
There seemed to be nothing wrong with your program

I tested it and run it on my computer with my AC program.

the only problem maybe that you didn't print a endline after each ouput.

The online judge may see the ouput as

BCG 30CBG 50

instead of the desired
BCG 30
CBG 50

This is just my hunch, i don't have a 100% confidence that placing a endline will work but it does eliminate one of the possibility that it may not work which will scale down your effort looking for a bug.

give it a try!!1

102: Extreme MEMORY usage... WHY?? =))

Posted: Mon Sep 30, 2002 12:27 pm
by 7825JN
This is the source for my solution to 102: it works, but with approx. 388 kb of memory spent. Why I cannot understand! Doesn't malloc anything, and no recursion... must be something tricky. Do you know what it can be??

/Lars

SOURCE:

#include <stdio.h>
#define MAP(x) ((x==1)? 2 : (x==2)? 1 : 0)
int main(void)
{
int bins[3][3];
int i, j, k;
do
{
unsigned int best = 0xFF;
int min = 0;

for(i = 0; i < 9; i++)
{
scanf("%d", &((int*)bins));
min += ((int*)bins);
}

for(i = 0; i < 3; i++)
for(j = 0; j < 3; j++)
for(k = 0; k < 3; k++)
{
int sum = 0;
int n;

if(i == j || i == k || j == k)
continue;

for(n = 0; n < 9; n++)
{
int nn = n%3;
switch(n/3)
{
case 0:
if(nn != MAP(i))
sum += bins[0][nn];
break;
case 1:
if(nn != MAP(j))
sum += bins[1][nn];
break;
case 2:
if(nn != MAP(k))
sum += bins[2][nn];
break;
}
}

if(sum <= min)
{
/* check if "more" alphabetical... */
int test = k + (j << 2) + (i << 4);
/* best == 112233 */
if((test < best && sum == min) || best == 0xFF || sum < min)
best = test;
min = sum;
}
}

for(i = 4; i >= 0; i -= 2)
{
switch((best & (3 << i)) >> i)
{
case 0:
printf("B");
break;
case 1:
printf("C");
break;
case 2:
printf("G");
break;
}
}
printf(" %d\n", min);
scanf("\n");
}while(!feof(stdin));
return 0;
}

Posted: Mon Sep 30, 2002 2:08 pm
by Ivor
It's not the first time this question is asked, but once again -- it has something to do with internal IO buffering, I guess.

Ivor

102=>WA...help

Posted: Sat Oct 12, 2002 10:02 am
by supermin
I test it many times,but I still can't figure out why judge sends me WA....
Could anyone give me help..or ....just a sample input to show my wrong..
thanx..^^

[color=olive]#include<stdio.h>
int main(void)
{
long int can[3][3],BGC,BCG,GBC,GCB,CBG,CGB;
long int min_step;

while(scanf("%ld%ld%ld%ld%ld%ld%ld%ld%ld",&can[0][0],&can[0][1],&can[0][2],&can[1][0],&can[1][1],&can[1][2],&can[2][0],&can[2][1],&can[2][2])==9)
{
min_step=10000000;
BGC=BCG=GBC=GCB=CBG=CGB=0;
/* B G C
can1 can[0][0] can[0][1] can[0][2]
can2 can[1][0] can[1][1] can[1][2]
can3 can[2][0] can[2][1] can[2][2] */
BGC=can[0][1]+can[0][2]+can[1][0]+can[1][2]+can[2][0]+can[2][1];
BCG=can[0][1]+can[0][2]+can[1][0]+can[1][1]+can[2][0]+can[2][2];
GBC=can[0][0]+can[0][2]+can[1][1]+can[1][2]+can[2][0]+can[2][1];
GCB=can[0][0]+can[0][2]+can[1][0]+can[1][1]+can[2][1]+can[2][2];
CBG=can[0][0]+can[0][1]+can[1][1]+can[1][2]+can[2][0]+can[2][2];
CGB=can[0][0]+can[0][1]+can[1][0]+can[1][2]+can[2][1]+can[2][2];

/* printf("%ld %ld %ld %ld %ld %ld",BGC,BCG,GBC,GCB,CBG,CGB); */

if(min_step>BCG)
min_step=BCG;
if(min_step>BGC)
min_step=BGC;
if(min_step>CBG)
min_step=CBG;
if(min_step>CGB)
min_step=CGB;
if(min_step>GBC)
min_step=GBC;
if(min_step>GCB)
min_step=GCB;


if(min_step==BCG)
{
printf("BCG");
goto A;
}
if(min_step==BGC)
{
printf("BGC");
goto A;
}
if(min_step==CBG)
{
printf("CBG");
goto A;
}
if(min_step==CGB)
{
printf("CGB");
goto A;
}
if(min_step==GBC)
{
printf("GBC");
goto A;
}
if(min_step==GCB)
{
printf("GCB");
goto A;
}

A:
printf(" %ld\n",min_step);


}
return 0;
}[/color][/c]

Posted: Sat Oct 19, 2002 3:11 am
by Ghost77 dimen
8) Hi 8)
It will be helpful by replacing "long int" to int and "%ld" to "%d".
I am not firmly sure of that , but you can make it a try.

Posted: Sat Oct 19, 2002 12:01 pm
by supermin
hmm...I try it as you say..,but it still can't send me AC message..
Anyway,thanks..

Could anyone help me solve this problem..

Posted: Sat Oct 19, 2002 5:12 pm
by junjieliang
I'm not sure, but perhaps you can initialise min_step to something bigger like 2147483647?