142 - Mouse Clicks

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

User avatar
Chung Ha, Yun
New poster
Posts: 19
Joined: Tue Jul 16, 2002 5:56 pm
Location: Seoul
Contact:

^^

Post by Chung Ha, Yun » Fri Feb 27, 2004 12:48 am

Thank you :D

:o strain my eyes.........................FULL SEARCHING^-^

User avatar
Chung Ha, Yun
New poster
Posts: 19
Joined: Tue Jul 16, 2002 5:56 pm
Location: Seoul
Contact:

Huk

Post by Chung Ha, Yun » Fri Feb 27, 2004 1:43 am

Huk.............. :-?

I fixed followed code.
printf("%3c", (char)(i + 49)); -> printf("%3d", i + 1);
And I got Accepted.

Ha Ha.............. Sorry... my mistake ToT

Very large mistake!!!

Thank you very much El-idioto :D

User avatar
A1
Experienced poster
Posts: 173
Joined: Wed Jan 28, 2004 3:34 pm
Location: Bangladesh

142 Mouse click

Post by A1 » Sat Dec 04, 2004 10:26 am

I am getting WA with this problem.
Please help me by giving some more input output or you can tell some special conditions of this problem.

thanks

User avatar
A1
Experienced poster
Posts: 173
Joined: Wed Jan 28, 2004 3:34 pm
Location: Bangladesh

Post by A1 » Sun Dec 12, 2004 9:04 am

O! long time no reply!! (very lazy board :))

Ok here is some Input please use you AC code and tell me there output.
I think at least some people here solved this problem.

Code: Select all

I       216     28
R       22      19      170     102
I       40      150
I       96      138
I       36      193
R       305     13      425     103
I       191     184
I       387     200
R       266     63      370     140
I       419     134
I       170     102
I	40	152
I	40	172
I	60	152
M       50      50
M       236     30
M       403     167
M       330     83
M	370	50
M	330	83
M	50	162
#

User avatar
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim » Sun Dec 12, 2004 9:57 am

A1, I don't have my AC code with me, but I can tell you one set of critical case could be the consideration of boundary points, that is clicks falling on boundary.

User avatar
A1
Experienced poster
Posts: 173
Joined: Wed Jan 28, 2004 3:34 pm
Location: Bangladesh

Post by A1 » Sun Dec 12, 2004 3:08 pm

I consider that But sitll WA :(
so some one please give me those outputs.

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 » Sun Dec 12, 2004 4:02 pm

A1 wrote:

Code: Select all

I       216     28
R       22      19      170     102
I       40      150
I       96      138
I       36      193
R       305     13      425     103
I       191     184
I       387     200
R       266     63      370     140
I       419     134
I       170     102
I	40	152
I	40	172
I	60	152
M       50      50
M       236     30
M       403     167
M       330     83
M	370	50
M	330	83
M	50	162
#
Output from my AC code:

Code: Select all

A
  1
  6  7
C
B
C
  9 10 11
Hope this helps.

User avatar
A1
Experienced poster
Posts: 173
Joined: Wed Jan 28, 2004 3:34 pm
Location: Bangladesh

Post by A1 » Sun Dec 19, 2004 9:37 am

Oh god !
It has multiple test set of input. I thought that there will be one set of input and get wrong answer again and again!!!!

thanks chunyi for you reply.

SRX
Learning poster
Posts: 63
Joined: Sat May 14, 2005 8:13 am
Location: Taiwan

142input-way

Post by SRX » Sat Sep 24, 2005 7:15 pm

I saw fix mistake post
Is my input way ok ?

Code: Select all

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std ;
struct Point {
 double x ;
 double y ;    
} point[100] ;
int inx = -1 , tmp = 0 ;    
int InputI (){ cin >> point[++inx].x >> point[inx].y ;    }  
int InputR ( char ar[600][600] ) {
 int i , j , a , b , c , d ;
 cin >> a >> b >> c >> d ;
 ++tmp ;  
 for ( i=a ; i<=c ; i++ )
   for ( j=b ; j<=d ; j++ )    
                      ar[i][j]=tmp ; 
}   
char s[2] ;  
double dis ( double x , double y , double tx , double ty ){ return sqrt((x-tx)*(x-tx)+(y-ty)*(y-ty)) ; }  
int Answer ( char ar[600][600] ) {
 int a , b ;    
 cin >> a >> b ; 
   if ( ar[a][b] )
                 putchar(ar[a][b]+'A'-1)  ;
   else {
    int i  ;
    double min = 999999.0 ; 
    for ( i=0 ; i<=inx ; i++ )    
               if ( dis  ( (double)a , (double)b , point[i].x , point[i].y ) < min )
                                  min =  dis  ( (double)a , (double)b , point[i].x , point[i].y )  ; 
       for ( i=0 ; i<=inx ; i++ )
                    if ( dis  ( (double)a , (double)b , point[i].x , point[i].y ) == min )
                                         cout << "  " << i+1 ;    
    }      
 putchar('\n') ; 
}    
int Q ( char ar[600][600] ) {
    if ( s[0]=='I' )
                                  InputI (  ) ; 
    else if ( s[0]=='R')
                                  InputR ( ar ) ; 
    else
                                  Answer ( ar ) ;   
}    
int main () {
while ( cin >> s  ){
  char ar[600][600]={0} ;
  inx = -1 , tmp = 0 ; 
  Q(ar) ; 
  while ( cin >> s && s[0]-'#' )   
                   Q(ar) ; 
  }                    
}    

s000015
New poster
Posts: 5
Joined: Sat Oct 08, 2005 1:56 pm
Location: Taiwan

142 mouse clicks WA - tricky input?

Post by s000015 » Sat Oct 08, 2005 2:11 pm

Hi,

I just check if some icons are overlaped by regions, if is, mark it.
For every click, I check if a region is selected, if is, print it, otherwise
print closest visible icons.

Anyone gets AC after rejudge?

Code: Select all

#include<stdio.h>
class rg{
public:
int sx,sy,ex,ey;
    bool inrg(int x,int y){
        if(sx<=x && x<=ex && sy<=y && y<=ey)
            return true;
        return false;
    }
    void get(){
        scanf("%d %d %d %d",&sx,&sy,&ex,&ey);
    }
}rg[250];
class ic{
public:
    int cx,cy;
    int dis(int x,int y){
        return (cx-x)*(cx-x)+(cy-y)*(cy-y);
    }
    void get(){
        scanf("%d %d",&cx,&cy);
    }
}ic[500];
main(){
int i,j,x,y,min,in=0,rn=0,mark[500];
char c[10000];
while(scanf("%s",c)!=EOF && *c!='#'){
    if(*c=='I'){
        mark[in]=0;
        ic[in].get();
        for(i=0;i<rn;i++)
            if(rg[i].inrg(ic[in].cx,ic[in].cy))
                mark[in]=1;
        in++;
    }
    else if(*c=='R'){
        rg[rn].get();
        for(i=0;i<in;i++)
            if(rg[rn].inrg(ic[i].cx,ic[i].cy))
                mark[i]=1;
        rn++;
    }
    else if(*c=='M'){
        scanf("%d %d",&x,&y);
        for(i=rn-1;i>=0;i--)
            if(rg[i].inrg(x,y))break;
        if(i>=0){
            printf("%c\n",'A'+i);
            continue;
        }
        min=100000000;
        for(i=0;i<in;i++)
            min<?=ic[i].dis(x,y);
        for(i=0;i<in;i++)
            if(min==ic[i].dis(x,y))
                printf("%3d",i+1);
        puts("");
    }
}
}


lovemagic
Learning poster
Posts: 52
Joined: Thu Oct 02, 2003 11:38 am

For those,who r trying to solve 142.....

Post by lovemagic » Tue Dec 20, 2005 6:29 am

The problem description is a bit ambiguous.While trying to solve this problem,i thought of input order....such as
if a region defined earlier than an icon,what will be happened.If this icon stays in that rectengular region,what will be on the top?
The icon or the region?Normal thinking says that the icon must be on the top as it defined later.But after sm WA,I checkd the visiblity
of icons after all input r given.& got AC.This means if an icon & a region stays at same place,the region is on the
top & the input order is not fact here.
khobaib

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 » Sun Dec 25, 2005 5:58 am

Read the problem description again:

Code: Select all

Note that regions always overlap icons so that obscured icons need not be considered
If an icon is within a rectangular region , then the region is always on top of the icon.

I think you are right about checking visibility of icons after taking in all the region and icon specifications. Edit: I double-checked my code which got WA after rejudge (previously AC), and it does check visibility of icons after taking all region and icon specifications. The problem is somewhere else.
Last edited by chunyi81 on Sun Dec 25, 2005 10:00 am, edited 2 times in total.

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf » Sun Dec 25, 2005 6:43 am

I too got WA after rejudge, but my mistake was that I'd missed the word 'visible' from this sentence:
otherwise it selects the closest visible icon (or icons in the case of a tie).
My previously AC code printed all closest icons (visible or not), now it rightfully gets WA.

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 » Sun Dec 25, 2005 11:50 am

mf, what should be the output for this test case?

Code: Select all

I       170     102
R       22      19      170     102
M       200      200
#
According to the problem specifications, the mouse click at 200 200 for this test case does not select anything at all since it does not select the only region in this test case and the only icon the mouse click can select is not visible. What should be the output for such test cases?

Here is my code (I changed it to handle cases like the one I have given above, but still WA.)

Code: Select all

Cut after AC. Thanks for all the help.
Where is the error in my code? For each line of input, my program checks if the first non-whitespace character is 'R', 'I', 'M' or '#', and then if its R, I or M it processes accordingly. The visibility of icons is only checked when a mouse click ('M') is encountered.
Last edited by chunyi81 on Mon Dec 26, 2005 4:23 am, edited 1 time in total.

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf » Sun Dec 25, 2005 1:17 pm

chunyi81 wrote: mf, what should be the output for this test case?

Code: Select all

I       170     102
R       22      19      170     102
M       200      200
# 
Both my programs (old and new ACs) print a blank line.

Main problem with your code, I think, is that you use floating-point numbers. This can easily lead to all sorts of trouble. Try to use just integers.

Secondly, this part of your code still may print obscured icons, check it carefully.

Code: Select all

if (icon >= 0) {
    printf("%3d",icon + 1);

    for (j = icon + 1;j < icons;j++) {

        distance = get_distance(x,y,xval[j],yval[j]);

        if (distance == min)
            printf("%3d",j + 1);

    }

}

Post Reply

Return to “Volume 1 (100-199)”