537 - Artificial Intelligence

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

Re: 537 - Artificial Intelligence

Postby Parksungsu » Wed Mar 14, 2012 5:56 pm

Hi, my name is Austin.
I got WA. but all the value is true.
I think that it is need to some exception.
So I want to know the exception.
like that It isn't -0.00, only print 0.00

please, reply to this sentence.
Parksungsu
New poster
 
Posts: 5
Joined: Sun Aug 15, 2010 2:56 am

Re: 537 - Artificial Intelligence

Postby brianfry713 » Thu Mar 15, 2012 10:55 pm

I didn't have any precision issues on this problem, my straightforward AC code uses C doubles, doesn't add an epsilon, and doesn't protect against negative zero.
brianfry713
Guru
 
Posts: 1870
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 537 - Artificial Intelligence

Postby coder.bd » Mon Jul 09, 2012 9:43 am

Code: Select all
removed
coder.bd
New poster
 
Posts: 2
Joined: Mon Jul 09, 2012 9:33 am

Re: 537 - Artificial Intelligence

Postby uvasarker » Wed Aug 01, 2012 12:48 pm

I am getting Wa. WHY? Help me please.
Code: Select all
#include <cstdio>
#include <cstring>
#include <cctype>
#include <iostream>
using namespace std;
int main()
{
    int T, cas=0;
    //freopen("in-537.txt","r",stdin);
    //freopen("out-537.txt","w",stdout);
    double P=0.0, U=0.0, I=0.0, tmp=0.0;
    scanf("%d\n",&T);
    while(T)
    {
      char s[10000], ch;
      scanf("%s%c",s,&ch);
      int ln=strlen(s), k=0, m=0, M=0, eq=0, PP=0, VV=0, II=0;
      for(int i=0 ; i<ln ; i++)
      {
          if(s[i]=='=' && ( s[i-1]=='I' || s[i-1]=='P'|| s[i-1]=='U' ) && isdigit(s[i+1]) ) eq++;
          //if(s[i]=='=') eq++;
      }
      float d=1.0;
      if(eq>0)
      {
                long nm=0, dv=0, fag=0;
                for(int i=0 ; i<ln ; i++)
                {
                              if(s[i]=='m') m=1;
                                if(s[i]=='M') M=1;
                                if(s[i]=='k') k=1;
                                if(s[i]=='P') PP=1;
                                if(s[i]=='U') VV=1;
                                if(s[i]=='I') II=1;

                        if( s[i]>='0' && s[i]<='9' )
                        {
                            if(fag==1){dv=dv*10; d=(float)dv;}
                            nm=nm*10+(int)s[i]-48;
                        }
                        if( s[i]=='.' )
                        {
                            dv=1;
                            fag=1;
                        }

                        if(s[i]=='A' || s[i]=='W' || s[i]=='V')
                        {
                                tmp=(float)nm/d;
                                //printf("%lf m=%d M=%d k=%d\n",tmp,m,M,k);
                                if(PP==1){
                                    P=tmp;
                                    if(m==1) P=P/1000.0;
                                    else if(M==1) P=P*1000000.0;
                                    else if(k==1) P=P*1000.0;
                                }
                                else if(VV==1){
                                    U=tmp;
                                    if(m==1) U=U/1000.0;
                                    else if(M==1) U=U*1000000.0;
                                    else if(k==1) U=U*1000.0;
                                }
                                else if(II==1){
                                    I=tmp;
                                    if(m==1) I=I/1000.0;
                                    else if(M==1) I=I*1000000.0;
                                    else if(k==1) I=I*1000.0;
                                }
                                PP=0; VV=0; II=0; k=0; m=0; M=0;
                                nm=0; dv=0; fag=0; d=1.0;
                        }
                }
      }

            if(ch=='\n'){
                    if(cas>0) printf("\n");
                    printf("Problem #%d\n",++cas);
                    if(P==0.0){
                        P=U*I;
                        printf("P=%.2lfW\n",P);
                    }
                    else if(U==0.0){
                        U=P/I;
                        printf("U=%.2lfV\n",U);
                    }
                    else if(I==0.0){
                        I=P/U;
                        printf("I=%.2lfA\n",I);
                    }
                P=0.0; U=0.0; I=0.0; tmp=0.0;
                T--;
            }
    }
    return 0;
}

uvasarker
Learning poster
 
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh

Re: 537 - Artificial Intelligence

Postby brianfry713 » Wed Aug 01, 2012 10:04 pm

Print a blank line at the end of the output.
brianfry713
Guru
 
Posts: 1870
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 537 - Artificial Intelligence

Postby uvasarker » Sat Aug 04, 2012 9:38 am

Guru,
It's not working.
I have test more with the following test cases:
Input:
Code: Select all
10
bla bla bla lightning strike I=2A bla bla bla P=2.5MW bla bla voltage?
If the voltage is U=200V and the current is I=4.5A, which power is generated?
A light-bulb yields P=100W and the voltage is U=220V. Compute the current, please.
gU=200VI=4.5A.
gU=220VP=100.00W.
tP=2.5MWI=2A.
PU=200VUI=4.5A.5W
IP=100WPU=220VI.5A
bla bla bla P=lightning st200rike I=2eA 200bla bla bla P=2.5MW bla bl100a I=voltage?
P=1WU=1V

Output:
Code: Select all
Problem #1
U=1250000.00V

Problem #2
P=900.00W

Problem #3
I=0.45A

Problem #4
P=900.00W

Problem #5
I=0.45A

Problem #6
U=1250000.00V

Problem #7
P=900.00W

Problem #8
I=0.45A

Problem #9
U=1250000.00V

Problem #10
I=1.00A


I have made two program for this problem. But judge verdict give WA WA WA.
Program 1 with gets() function:
Code: Select all
Removed

Program 2 with only string:
Code: Select all
#include <cstdio>
#include <cstring>
#include <cctype>
#include <iostream>
using namespace std;
int main()
{
    int T, cas=0;
    //freopen("in-537.txt","r",stdin);
    //freopen("out-537.txt","w",stdout);
    double P=0.0, U=0.0, I=0.0, tmp=0.0;
    scanf("%d\n",&T);
    while(T)
    {
      char s[1000], ch;
      scanf("%s%c",s,&ch);
      int ln=strlen(s), k=0, m=0, M=0, eq=0, PP=0, VV=0, II=0;
      for(int i=0 ; i<ln ; i++)
      {
          if( (s[i]=='=') && (s[i-1]=='I' || s[i-1]=='P'|| s[i-1]=='U') && (s[i+1]>='0' && s[i+1]<='9') ) eq++;
      }
      float d=1.0;
      if(eq>0)
      {
                long nm=0, dv=0, fag=0;
                for(int i=0 ; i<ln ; i++)
                {
                              if(s[i]=='m') m=1;
                                if(s[i]=='M') M=1;
                                if(s[i]=='k') k=1;
                                if(s[i]=='P' && s[i+1]=='=') PP=1;
                                if(s[i]=='U' && s[i+1]=='=') VV=1;
                                if(s[i]=='I' && s[i+1]=='=') II=1;

                        if( s[i]>='0' && s[i]<='9' )
                        {
                            if(fag==1){dv=dv*10; d=(float)dv;}
                            nm=nm*10+(int)s[i]-48;
                        }
                        if( s[i]=='.' )
                        {
                            dv=1;
                            fag=1;
                        }

                        if(s[i]=='A' || s[i]=='W' || s[i]=='V')
                        {
                                tmp=(float)nm/d;
                                //printf("%lf m=%d M=%d k=%d\n",tmp,m,M,k);
                                if(PP==1){
                                    P=tmp;
                                    if(m==1) P=P/1000.0;
                                    else if(M==1) P=P*1000000.0;
                                    else if(k==1) P=P*1000.0;
                                }
                                else if(VV==1){
                                    U=tmp;
                                    if(m==1) U=U/1000.0;
                                    else if(M==1) U=U*1000000.0;
                                    else if(k==1) U=U*1000.0;
                                }
                                else if(II==1){
                                    I=tmp;
                                    if(m==1) I=I/1000.0;
                                    else if(M==1) I=I*1000000.0;
                                    else if(k==1) I=I*1000.0;
                                }
                                PP=0; VV=0; II=0; k=0; m=0; M=0;
                                nm=0; dv=0; fag=0; d=1.0;
                        }
                }
      }

            if(ch=='\n' || ln==0){
                    if(cas>0) printf("\n");
                    printf("Problem #%d\n",++cas);
                    if(P==0.0){
                        P=U*I;
                        printf("P=%.2lfW\n",P);
                    }
                    else if(U==0.0){
                        U=P/I;
                        printf("U=%.2lfV\n",U);
                    }
                    else if(I==0.0){
                        I=P/U;
                        printf("I=%.2lfA\n",I);
                    }
                P=0.0; U=0.0; I=0.0; tmp=0.0;
                T--;
            }
    }
    return 0;
}


I am frustrated.
Last edited by uvasarker on Tue Aug 07, 2012 8:36 am, edited 1 time in total.
uvasarker
Learning poster
 
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh

Re: 537 - Artificial Intelligence

Postby brianfry713 » Mon Aug 06, 2012 11:17 pm

I only looked at your first program. Try input:
I=1A P=0W

Don't use floats, stick with doubles.
brianfry713
Guru
 
Posts: 1870
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 537 - Artificial Intelligence

Postby uvasarker » Tue Aug 07, 2012 8:34 am

Thanks Guru,
Finally, I got accccc after 10 submissions,
using double.
uvasarker
Learning poster
 
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh

Previous

Return to Volume V

Who is online

Users browsing this forum: No registered users and 1 guest

cron