587 - There's treasure everywhere!

All about problems in Volume V. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

587 WA

Postby darkos32 » Thu Nov 23, 2006 3:51 am

hi,i got WA at problem 587

this is my code :

Code: Select all
#include <stdio.h>
#include <string.h>
#include <math.h>
double x,y;
void utara(int pindah){
   y+=pindah;
}
void selatan(int pindah){
   y-=pindah;
}
void timur(int pindah){
   x+=pindah;
}
void barat(int pindah){
   x-=pindah;
}
void utarabarat(int pindah){
   double temp = sqrt((pindah*pindah)/2);
   x-=temp;
   y+=temp;
}
void utaratimur(int pindah){
   double temp = sqrt((pindah*pindah)/2);
   x+=temp;
   y+=temp;
}
void selatanbarat(int pindah){
   double temp = sqrt((pindah*pindah)/2);
   x-=temp;
   y-=temp;
}
void selatantimur(int pindah){
   double temp = sqrt((pindah*pindah)/2);
   x+=temp;
   y-=temp;
}
void main(){
   freopen("treasure.in","r",stdin);
   freopen("treasure.out","w",stdout);
   char s[205] = "";
   int awal = 1;
   while(scanf("%s",&s)==1){
      if(strcmp(s,"END")==0) break;
      int i = 0;
      int byk = strlen(s);
      int mypindah = 0;
      int faktor = 1;
      x = 0;y = 0;
      while(i<byk){
         if(((int) s[i])>=48 && ((int) s[i])<=57){
            mypindah = (mypindah * faktor) + (((int) s[i]) - 48);
            faktor =10;
            i++;
         }
         else {
            faktor = 1;
            if(s[i]=='.'){
               i+=byk;
               continue;
            }
            else if(s[i]=='N' && (s[i+1]==',' || s[i+1]=='.')) {
               utara(mypindah);
               mypindah = 0;
               i+=2;
               if(s[i+1]=='.') i+=byk;
               continue;
            }
            else if(s[i]=='W' && (s[i+1]==',' || s[i+1]=='.')) {
               barat(mypindah);
               mypindah = 0;
               if(s[i+1]=='.') i+=byk;
               i+=2;continue;
            }
            else if(s[i]=='E' && (s[i+1]==',' || s[i+1]=='.')) {
               timur(mypindah);
               mypindah = 0;
               if(s[i+1]=='.') i+=byk;
               i+=2;continue;
            }
            else if(s[i]=='S' && (s[i+1]==',' || s[i+1]=='.')) {
               selatan(mypindah);
               mypindah = 0;
               if(s[i+1]=='.') i+=byk;
               i+=2;continue;
            }
            else if(s[i]=='N' && s[i+1]=='W') utarabarat(mypindah);
            else if(s[i]=='N' && s[i+1]=='E') utaratimur(mypindah);
            else if(s[i]=='S' && s[i+1]=='W') selatanbarat(mypindah);
            else if(s[i]=='S' && s[i+1]=='E') selatantimur(mypindah);
            if(s[i+2]=='.') i+=byk;
            mypindah = 0;
            i+=3;            
         }
         
      }
      printf("Map #%d\n",awal);
      printf("The treasure is located at (%.3f,%.3f).\n",x,y);
      double jarak = sqrt((x*x) + (y*y));
      printf("The distance to the treasure is %.3f.\n\n",jarak);
      awal++;
   }
}


can anyone help me please ?
thanks...
darkos32
New poster
 
Posts: 27
Joined: Tue Jul 25, 2006 8:10 am
Location: Indonesia

Re: 587 There's treasure everywhere! WA

Postby ishtiaq ahmed » Mon Apr 21, 2008 11:06 pm

My code seems to be okay by the given input. But its WA by judge. Anybody help me? Here is my code
Code: Select all

The code is deleted after AC.

Last edited by ishtiaq ahmed on Wed Apr 23, 2008 11:19 am, edited 1 time in total.
No venture no gain

with best regards
------------------------
ishtiaq ahmed
ishtiaq ahmed
Learning poster
 
Posts: 53
Joined: Sat Jul 29, 2006 7:33 am
Location: (CSE,DU), Dhaka,Bangladesh

Re: 587 There's treasure everywhere! WA

Postby mak(cse_DU) » Tue Apr 22, 2008 8:58 pm

if(casno > 1)
puts("");

Problem Statement say:
Print a blank line after each test case


Not between two test case.
Mak
Help me PLZ!!
mak(cse_DU)
Learning poster
 
Posts: 72
Joined: Tue May 30, 2006 5:57 pm
Location: bangladesh

Re: 587 There's treasure everywhere! WA

Postby ishtiaq ahmed » Wed Apr 23, 2008 11:18 am

Thanks a lot mak
No venture no gain

with best regards
------------------------
ishtiaq ahmed
ishtiaq ahmed
Learning poster
 
Posts: 53
Joined: Sat Jul 29, 2006 7:33 am
Location: (CSE,DU), Dhaka,Bangladesh

Re: 587 WA sm1 plz solve it...

Postby sushil2006090 » Sun Jul 27, 2008 3:23 pm

#include<iostream>
#include<fstream>
#include<cmath>
#include<algorithm>
#include<iterator>
#include<stack>
#include<list>
#include<queue>
#include<set>
#include<string>
#include<map>
#include<functional>
#include<utility>
#include<vector>
#include<deque>
#include<iomanip>
typedef long long LL;
typedef unsigned long UL;
using namespace std;
int main()
{
string str;
int map=1;
while(true)
{
cin>>str;
if(str=="END")
break;
float x=10e-6,y=10e-6;
int len=str.length();
for(int i=0;i<len-1;)
{
string s,st;
while(isdigit(str[i]))
{
s+=str[i];
i++;
}
st+=str[i];
i++;
if(str[i]!=','&& str[i]!='.')
st+=str[i];
i++;
// cout<<s<<" "<<st<<endl;
int l=s.length();
double temp=0;
int mult=1;
for(int i=l-1;i>=0;i--)
{temp+=(s[i]-'0')*mult;mult*=10;}
//cout<<temp<<endl;
if(st=="N")
{ y+=temp;}
else if(st=="S")
y-=temp;
else if(st=="E")
x+=temp;
else if(st=="W")
x-=temp;
else if(st=="SW")
{
x-=temp*sin(2*acos(0)/4);y-=temp*sin(2*acos(0)/4);
}
else if(st=="NW")
{x-=temp*sin(2*acos(0)/4);y+=temp*sin(2*acos(0)/4);}
else if(st=="NE")
{x+=temp*sin(2*acos(0)/4);y+=temp*sin(2*acos(0)/4);}
else if(st=="SE")
{x+=temp*sin(2*acos(0)/4);y-=temp*sin(2*acos(0)/4);}
//cout<<x<<" "<<y<<endl;
//cout<<x<<" "<<y<<endl;

}
cout<<"Map #"<<map<<"\n";
map++;
printf("The treasure is located at (%.3f,%.3f).\n",x,y);
printf("The distance to the treasure is %.3lf.\n\n", sqrt(x*x+y*y));

}
// system("pause");
}
sushil2006090
New poster
 
Posts: 7
Joined: Wed Feb 20, 2008 3:17 pm

Re: 587

Postby Shafaet_du » Thu Oct 28, 2010 9:59 pm

1.no need to use long double.
2. you DON'T need any eps anywhere in this problem,i got accepted without using any.
3. don't forget to TYPECAST if you divide an integer by an integer and store the result in a double.
4. print blank line after EACH output. also check your spelling,don't miss the fullstops.
4. try this inputs:

Code: Select all
3E,4N,10W,5NE.
10NE,10SE,10NW,10NE
19SW,19S,19W,19SW,28NE
27S,18N,10S,10N,3W,13NW,14SW,14NW
10S,10N,10N,10S
END


output:
Code: Select all
Map #1
The treasure is located at (-3.464,7.536).
The distance to the treasure is 8.294.

Map #2
The treasure is located at (14.142,14.142).
The distance to the treasure is 20.000.

Map #3
The treasure is located at (-26.071,-26.071).
The distance to the treasure is 36.870.

Map #4
The treasure is located at (-31.991,0.192).
The distance to the treasure is 31.992.

Map #5
The treasure is located at (0.000,0.000).
The distance to the treasure is 0.000.


Hope you'll get ac. happy programming :)
Shafaet_du
Experienced poster
 
Posts: 147
Joined: Mon Jun 07, 2010 11:43 am
Location: University Of Dhaka,Bangladesh

Re: 587

Postby shellexecutor » Sat Sep 08, 2012 4:35 pm

I can't figure out why I am getting WA.
Can someone help?

Code: Select all
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cfloat>

int main() {
    for ( int i=1; ; i++ ) {
        char guide[50000];
        gets(guide);
        if ( strcmp(guide, "END") == 0 ) break;
       
        if ( i>1 ) printf("\n");
       
        char *command = strtok( guide, ",." );
        double x = DBL_EPSILON, y = DBL_EPSILON;
       
        while ( command != NULL ) {
            if ( strstr(command, "NE") != NULL ) {
                x += atoi(command) / sqrt(2);
                y += atoi(command) / sqrt(2);
            } else if ( strstr(command, "NW") != NULL ) {
                x -= atoi(command) / sqrt(2);
                y += atoi(command) / sqrt(2);
            } else if ( strstr(command, "SE") != NULL ) {
                x += atoi(command) / sqrt(2);
                y -= atoi(command) / sqrt(2);
            } else if ( strstr(command, "SW") != NULL ) {
                x -= atoi(command) / sqrt(2);
                y -= atoi(command) / sqrt(2);
            } else if ( strstr(command, "N") != NULL ) {
                y += atoi(command);
            } else if ( strstr(command, "E") != NULL ) {
                x += atoi(command);
            } else if ( strstr(command, "W") != NULL ) {
                x -= atoi(command);
            } else if ( strstr(command, "S") != NULL ) {
                y -= atoi(command);
            }
           
            command = strtok( NULL, ",." );
        }
       
        printf("Map #%d\n", i);
        printf("The treasure is located at (%.3lf,%.3lf).\n", x, y);
        printf("The distance to the treasure is %.3lf.\n", sqrt(x*x+y*y)+DBL_EPSILON);
    }
   
    return 0;
}
shellexecutor
New poster
 
Posts: 2
Joined: Sat Sep 08, 2012 3:36 pm

Re: 587

Postby brianfry713 » Mon Sep 10, 2012 10:28 pm

Print a blank line after each test case, including the last one.
Check input and AC output for hundreds of problems on uDebug!
brianfry713
Guru
 
Posts: 5409
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Previous

Return to Volume V

Who is online

Users browsing this forum: No registered users and 1 guest