537 - Artificial Intelligence?

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

Moderator: Board moderators

shipu_a
New poster
Posts: 23
Joined: Tue Oct 23, 2012 8:04 pm
Location: Dhaka,Bangladesh
Contact:

WA-537-Artificial Intelligence?

Post by shipu_a »

wa plz help me................ :oops: :roll:

Code: Select all

/*************************************
******** Team : BUBT_HIDDEN **********
**************************************
*********** Shipu Ahamed *************
*** http://shipuahamed.blogspot.com **
*************************************/

#include<algorithm>
#include<iostream>
#include<iterator>
#include<cassert>
#include<sstream>
#include<fstream>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<complex>
#include<string>
#include<cctype>
#include<cstdio>
#include<vector>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<deque>
#include<list>
#include<set>
#include<map>

#define sc scanf
#define pf printf
#define ll long long
#define pi 2*acos(0.0)

#define ff first
#define se second
#define inf (1<<30)                                              //infinity value
#define pb push_back
#define mod  1000000007
#define ST(v) sort(v.begin(),v.end())
#define cover(a,d) memset(a,d,sizeof(a))
#define input freopen("in.txt","r",stdin)
#define output freopen("out.txt","w",stdout)
#define maxall(v) *max_element(v.begin(),v.end())
#define minall(v) *min_element(v.begin(),v.end())
#define un(v) ST(v), v.erase(unique(v.begin(),v.end()),v.end())

using namespace std;
int main()
{
    int t,no=0;
    sc("%d",&t);
    getchar();
    while(t--)
    {
        char s[10000],k[10000];
        gets(s);
        int l=strlen(s),j,st;
        double a=0,p=0,u=0;

        for(int i=0;i<l;i++)
        {
            if(s[i]=='U')
            {
               i=i+2;
               j=0;

              // pf("%c\n",s[i]);

               while(s[i]>='0'&&s[i]<='9')
               {
                   k[j++]=s[i];
                   i++;
               }
               k[j]='\0';
                 if(s[i]=='m')
                u=0.001*atof(k);
                else if(s[i]=='k')
                u=1000.0*atof(k);
                else if(s[i]=='M')
                u=1000000.0*atof(k);
               else
                u=atof(k);
            }
            else if(s[i]=='P')
            {
               i=i+2;
               j=0;
               while(!isalpha(s[i]))
               {
                   k[j++]=s[i];
                   i++;
               }
               k[j]='\0';
                  if(s[i]=='m')
                p=0.001*atof(k);
                else if(s[i]=='k')
                p=1000.0*atof(k);
                else if(s[i]=='M')
                p=1000000.0*atof(k);
               else
                p=atof(k);
            }
            else if(s[i]=='I')
            {
               i=i+2;
               j=0;
               while(!isalpha(s[i]))
               {
                   k[j++]=s[i];
                   i++;
               }
               k[j]='\0';
               if(s[i]=='m')
                a=0.001*atof(k);
                else if(s[i]=='k')
                a=1000.0*atof(k);
                else if(s[i]=='M')
                a=1000000.0*atof(k);
               else
                a=atof(k);
            }

        }
         printf("Problem #%d\n",++no);
            if(p==0){
                   printf("P=%.2lfW\n\n",a*u);
            }
            else if(a==0){
                 printf("I=%.2lfA\n\n",p/u);
            }
            else if(u==0){
                 printf("U=%.2lfV\n\n",p/a);
            }
    }
    return 0;
}
Nothing is imposible in the world.....And
Never Judge a Book by Its Cover.............
BUBT_Psycho
http://uhunt.felix-halim.net/id/168573
http://shipuahamed.blogspot.com
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: WA-537-Artificial Intelligence?

Post by brianfry713 »

Input:

Code: Select all

1
A light-bulb yields P=0W and the voltage is U=220V. Compute the current, please.
AC output:

Code: Select all

Problem #1
I=0.00A

Check input and AC output for thousands of problems on uDebug!
shipu_a
New poster
Posts: 23
Joined: Tue Oct 23, 2012 8:04 pm
Location: Dhaka,Bangladesh
Contact:

Re: WA-537-Artificial Intelligence?

Post by shipu_a »

brianfry713 wrote:Input:

Code: Select all

1
A light-bulb yields P=0W and the voltage is U=220V. Compute the current, please.
AC output:

Code: Select all

Problem #1
I=0.00A

again wa.............

Code: Select all

/*************************************
******** Team : BUBT_HIDDEN **********
**************************************
*********** Shipu Ahamed *************
*** http://shipuahamed.blogspot.com **
*************************************/

#include<algorithm>
#include<iostream>
#include<iterator>
#include<cassert>
#include<sstream>
#include<fstream>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<complex>
#include<string>
#include<cctype>
#include<cstdio>
#include<vector>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<deque>
#include<list>
#include<set>
#include<map>

#define sc scanf
#define pf printf
#define ll long long
#define pi 2*acos(0.0)

#define ff first
#define se second
#define inf (1<<30)                                              //infinity value
#define pb push_back
#define mod  1000000007
#define ST(v) sort(v.begin(),v.end())
#define cover(a,d) memset(a,d,sizeof(a))
#define input freopen("in.txt","r",stdin)
#define output freopen("out.txt","w",stdout)
#define maxall(v) *max_element(v.begin(),v.end())
#define minall(v) *min_element(v.begin(),v.end())
#define un(v) ST(v), v.erase(unique(v.begin(),v.end()),v.end())

using namespace std;
int main()
{
    int t,no=0;
    sc("%d",&t);
    getchar();
    while(t--)
    {
        char s[10000],k[10000];
        gets(s);
        int l=strlen(s),j,st;
        double a=-1,p=-1,u=-1;

        for(int i=0;i<l;i++)
        {
            if(s[i]=='U')
            {
               i=i+2;
               j=0;

              // pf("%c\n",s[i]);

               while(s[i]>='0'&&s[i]<='9')
               {
                   k[j++]=s[i];
                   i++;
               }
               k[j]='\0';
                 if(s[i]=='m')
                u=0.001*atof(k);
                else if(s[i]=='k')
                u=1000.0*atof(k);
                else if(s[i]=='M')
                u=1000000.0*atof(k);
               else
                u=atof(k);
            }
            else if(s[i]=='P')
            {
               i=i+2;
               j=0;
               while(!isalpha(s[i]))
               {
                   k[j++]=s[i];
                   i++;
               }
               k[j]='\0';
                  if(s[i]=='m')
                p=0.001*atof(k);
                else if(s[i]=='k')
                p=1000.0*atof(k);
                else if(s[i]=='M')
                p=1000000.0*atof(k);
               else
                p=atof(k);
            }
            else if(s[i]=='I')
            {
               i=i+2;
               j=0;
               while(!isalpha(s[i]))
               {
                   k[j++]=s[i];
                   i++;
               }
               k[j]='\0';
               if(s[i]=='m')
                a=0.001*atof(k);
                else if(s[i]=='k')
                a=1000.0*atof(k);
                else if(s[i]=='M')
                a=1000000.0*atof(k);
               else
                a=atof(k);
            }

        }
         printf("Problem #%d\n",++no);
            if(p==-1){
                   printf("P=%.2lfW\n\n",a*u);
            }
            else if(a==-1){
                 printf("I=%.2lfA\n\n",p/u);
            }
            else if(u==-1){
                 printf("U=%.2lfV\n\n",p/a);
            }
    }
    return 0;
}
Nothing is imposible in the world.....And
Never Judge a Book by Its Cover.............
BUBT_Psycho
http://uhunt.felix-halim.net/id/168573
http://shipuahamed.blogspot.com
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: WA-537-Artificial Intelligence?

Post by brianfry713 »

Input:

Code: Select all

1
A light-bulb yields P=-1W and the voltage is U=2V. Compute the current, please.
AC output:

Code: Select all

Problem #1
I=-0.50A

Check input and AC output for thousands of problems on uDebug!
shipu_a
New poster
Posts: 23
Joined: Tue Oct 23, 2012 8:04 pm
Location: Dhaka,Bangladesh
Contact:

Re: WA-537-Artificial Intelligence?

Post by shipu_a »

brianfry713 wrote:Input:

Code: Select all

1
A light-bulb yields P=-1W and the voltage is U=2V. Compute the current, please.
AC output:

Code: Select all

Problem #1
I=-0.50A

may be it's not correct answer.........
again wa.......... :( :cry: :oops:

Code: Select all

/*************************************
******** Team : BUBT_HIDDEN **********
**************************************
*********** Shipu Ahamed *************
*** http://shipuahamed.blogspot.com **
*************************************/

#include<algorithm>
#include<iostream>
#include<iterator>
#include<cassert>
#include<sstream>
#include<fstream>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<complex>
#include<string>
#include<cctype>
#include<cstdio>
#include<vector>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<deque>
#include<list>
#include<set>
#include<map>

#define sc scanf
#define pf printf
#define ll long long
#define pi 2*acos(0.0)

#define ff first
#define se second
#define inf (1<<30)                                              //infinity value
#define pb push_back
#define mod  1000000007
#define ST(v) sort(v.begin(),v.end())
#define cover(a,d) memset(a,d,sizeof(a))
#define input freopen("in.txt","r",stdin)
#define output freopen("out.txt","w",stdout)
#define maxall(v) *max_element(v.begin(),v.end())
#define minall(v) *min_element(v.begin(),v.end())
#define un(v) ST(v), v.erase(unique(v.begin(),v.end()),v.end())

using namespace std;
int main()
{
    int t,no=0;
    sc("%d",&t);
    getchar();
    while(t--)
    {
        char s[10000],k[10000];
        gets(s);
        int l=strlen(s),j,uu=0,aa=0,pp=0;
        double a,p,u;

        for(int i=0;i<l;i++)
        {
            if(s[i]=='U')
            {
               i=i+2;
               j=0;

              // pf("%c\n",s[i]);

               while(s[i]>='0'&&s[i]<='9')
               {
                   k[j++]=s[i];
                   i++;
               }
               k[j]='\0';
                 if(s[i]=='m')
                u=0.001*atof(k);
                else if(s[i]=='k')
                u=1000.0*atof(k);
                else if(s[i]=='M')
                u=1000000.0*atof(k);
               else
                u=atof(k);
                uu=1;
            }
            else if(s[i]=='P')
            {
               i=i+2;
               j=0;
               while(!isalpha(s[i]))
               {
                   k[j++]=s[i];
                   i++;
               }
               k[j]='\0';
                  if(s[i]=='m')
                p=0.001*atof(k);
                else if(s[i]=='k')
                p=1000.0*atof(k);
                else if(s[i]=='M')
                p=1000000.0*atof(k);
               else
                p=atof(k);
                pp=1;
            }
            else if(s[i]=='I')
            {
               i=i+2;
               j=0;
               while(!isalpha(s[i]))
               {
                   k[j++]=s[i];
                   i++;
               }
               k[j]='\0';
               if(s[i]=='m')
                a=0.001*atof(k);
                else if(s[i]=='k')
                a=1000.0*atof(k);
                else if(s[i]=='M')
                a=1000000.0*atof(k);
               else
                a=atof(k);
                aa=1;
            }

        }
         pf("Problem #%d\n",++no);
            if(pp==0){
                   pf("P=%.2lfW\n\n",a*u);
            }
            else if(aa==0){
                 pf("I=%.2lfA\n\n",p/u);
            }
            else if(uu==0){
                 pf("U=%.2lfV\n\n",p/a);
            }
    }
    return 0;
}
Nothing is imposible in the world.....And
Never Judge a Book by Its Cover.............
BUBT_Psycho
http://uhunt.felix-halim.net/id/168573
http://shipuahamed.blogspot.com
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: WA-537-Artificial Intelligence?

Post by brianfry713 »

Input:

Code: Select all

1
I light-bulb yields P=1W and the voltage is U=2V. Compute the current, please.
AC output:

Code: Select all

Problem #1
I=0.50A

Check input and AC output for thousands of problems on uDebug!
shipu_a
New poster
Posts: 23
Joined: Tue Oct 23, 2012 8:04 pm
Location: Dhaka,Bangladesh
Contact:

Re: WA-537-Artificial Intelligence?

Post by shipu_a »

finally ac..........
Nothing is imposible in the world.....And
Never Judge a Book by Its Cover.............
BUBT_Psycho
http://uhunt.felix-halim.net/id/168573
http://shipuahamed.blogspot.com
shipu_a
New poster
Posts: 23
Joined: Tue Oct 23, 2012 8:04 pm
Location: Dhaka,Bangladesh
Contact:

Re: WA-537-Artificial Intelligence?

Post by shipu_a »

input:

Code: Select all

3
A light-bulb yields P=0W and the voltage is U=220V. Compute the current, please.
I light-bulb yields P=1W and the voltage is U=2V. Compute the current, please.
A light-bulb yields I=-1A and the voltage is U=-2V. Compute the current, please.
output:

Code: Select all

Problem #1
I=0.00A


Problem #2
I=0.50A


Problem #3
P=2.00W
impossible

Code: Select all

A light-bulb yields P=0W and the voltage is U=0V. Compute the current, please.
bla bla bla lightning strike I=0A bla bla bla P=0.5MW bla bla voltage?
Nothing is imposible in the world.....And
Never Judge a Book by Its Cover.............
BUBT_Psycho
http://uhunt.felix-halim.net/id/168573
http://shipuahamed.blogspot.com
dhruba07
New poster
Posts: 20
Joined: Tue May 21, 2013 9:02 pm
Location: BUET

Re: WA-537-Artificial Intelligence?

Post by dhruba07 »

getting wrong answer on this code :(

Code: Select all

code removed after AC
Thanks.I finally got AC
Last edited by dhruba07 on Sun Aug 18, 2013 8:37 pm, edited 1 time in total.
Accept who you are :)
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: WA-537-Artificial Intelligence?

Post by brianfry713 »

Print a blank line after the last test case.
Check input and AC output for thousands of problems on uDebug!
PromeNabid
New poster
Posts: 21
Joined: Mon Jun 18, 2012 12:52 am
Location: Dhaka, Bangladesh.
Contact:

Re: WA-537-Artificial Intelligence?

Post by PromeNabid »

Got WA.. Can somone give some input and outputs?
Thanks in advance.

Code: Select all

/*
Name: Md. Nabid Imteaj
Prob:
Algo:
*/

#pragma comment( linker, "/STACK:16777216" )
#pragma warning( disable:4786 )

#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>

using namespace std;

// debug
// credit: smilitude
#define D(x) if(1) cout << __LINE__ << " " << #x" = " << (x) << endl
#define D2(x,y) if(1) cout << __LINE__ << " " << #x" = " << (x) \
			   << ", " << #y" = " << (y) << endl
#define READ(f) freopen( (f), "r", stdin )
#define WRITE(f) freopen( (f), "w", stdout )
#define mset(x,n) memset((x),(n),sizeof((x)))
#define pf(x) cout << (x)
#define pfl(x) cout << (x) << endl
#define pfln() cout << endl
#define pfs() cout << " "
#define sys() system("pause")
#define FOR(i,a,b) for(int i=(a),_e(b); i<=_e; i++)

template<class T> inline T MAX( T a, T b ) { return a>b?a:b; }
template<class T> inline T MIN( T a, T b ) { return a<b?a:b; }
template<class T> inline void SWAP( T &a, T &b ) { a=a^b; b=a^b; a=a^b; }
template<class T, class T1>inline void Reverse( T1 A[], T i, T j ) { for( ; i<j; i++,j-- ) SWAP( A[i], A[j] ); }
template<class T> inline T fAbs( T a ) { return a<0?a*(-1):a; }

const int SZ = 1e5+10;
const int INF = 1<<29;
const double PI = 2*acos(0.0);
const double EPS = 1e-9;

char str[SZ];
vector<char>tmpi, tmpd;
bool si[4];

int intPart( ) {
	int i, len = tmpi.size();
	int tm = 0, ten = 1;
	for( i=len-1; i>=0; i-- ) {
		tm += (tmpi[i] - '0') * ten;
		ten *= 10;
	}
	return tm;
}
double doublePart( ) {
	int i, len = tmpd.size(), tt = 0;
	double tm = 0.0;
	int ten = 1;
	for( i=0; i<len; i++ ) {
		//D( tmpd[i] );
		tt += (tmpd[i] - '0') * ten;
		ten *= 10;
	}
	//ten *= 10;
	tm = (double)tt / ten;
	return tm;
}

int main( ) {

//#define DeBug
//#define CF_Loop

#ifdef DeBug
    READ( "in.txt" );
    // WRITE( "out.txt" );
#endif
#ifdef CF_Loop
    while( 1 ) {
#endif // CF_Loop

	int tc, caseno = 1;
	char fake;
	scanf( "%d%c", &tc, &fake );
	//D2( (int)fake, fake );
	while( tc-- ) {
		fgets( str, SZ, stdin );
		//cin.ignore();
		int len = strlen( str );
		str[ --len ] = '\0';

		bool U, I, P;
		int m, k, M;
		U = I = P = false;
		m = k = M = 1;
		int it;  // integer part
		double dt; // double part
		double ru, ri, rp, res;

		int i, j;
		for( i=0; i<len; i++ ) {
			if( (U&&I) || (U&&P) || (P&&I) ) break;
			if( str[i] == 'U' || str[i] == 'P' || str[i] == 'I' && i+1 < len && str[i+1] == '=' ) {
				//D2( i, str[i] );
				tmpi.clear();
				tmpd.clear();
				mset( si, false );
				// take integer part
				for( j=i+2; j<len; j++ ) {
					if( str[j] == '.' ) break;
					if( str[j] == '-' ) {
						si[0] = true;
						continue;
					}
					if( str[j] >= '0' && str[j] <= '9' ) {
						tmpi.push_back( str[j] );
					} else break;
				}
				//FOR(x, 0, tmpi.size()-1) D(tmpi[x]);
				// take decimal part
				if( str[j] == '.' ) {
					for( j=j+1; j<len; j++ ) {
						if( str[j] >= '0' && str[j] <= '9' ) {
							tmpd.push_back( str[j] );
						} else break;
					}
				}
				//FOR(x, 0, tmpd.size()-1) D(tmpd[x]);

				// check for mili, kilo, mega
				if( str[j] == 'm' ) m = 1000;
				else if( str[j] == 'k' ) k = 1000;
				else if( str[j] == 'M' ) M = 1000000;
				//D(m); D(k); D(M);

				it = intPart( );
				dt = doublePart( );
				//D2( it, dt );

				if( str[i] == 'U' ) {
					U = true;
					ru = (double)it + dt;
					ru = (ru * k * M) / m;
					if( si[0] ) si[1] = true;
				} else if( str[i] == 'I' ) {
					I = true;
					ri = (double)it + dt;
					ri = (ri * k * M) / m;
					if( si[0] ) si[2] = true;
				} else if( str[i] == 'P' ) {
					P = true;
					rp = (double)it + dt;
					rp = (rp * k * M) / m;
					if( si[0] ) si[3] = true;
				}

			}
		}
		//D( ru ); D( ri ); D( rp );
		printf( "Problem #%d\n", caseno++ );
		if( !U ) {
			printf( "U=" );
			if( fAbs( ri-0.00 ) < EPS ) res = 0.00;
			else {
				res = rp / ri;
				if( (!si[2] && si[3]) || (si[2] && !si[3]) ) printf( "-" );
			}
			printf( "%.2lfV", res );
		}
		else if( !P ) {
			printf( "P=" );
			res = ru * ri;
			if( (!si[2] && si[1]) || (si[2] && !si[1]) ) printf( "-" );
			printf( "%.2lfW", res );
		}
		else if( !I ) {
			printf( "I=" );
			if( fAbs( ru-0.00 ) < EPS ) res = 0.00;
			else {
				res = rp / ru;
				if( (!si[1] && si[3]) || (si[1] && !si[3]) ) printf( "-" );
			}
			printf( "%.2lfA", res );
		}

		printf( "\n\n" );
		//D("tesTtube");
	}

#ifdef CF_Loop
    }
#endif // CF_Loop
	//cin.get();
	return 0;
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: WA-537-Artificial Intelligence?

Post by brianfry713 »

I used atof() to convert the real numbers.
Check input and AC output for thousands of problems on uDebug!
mhsn06
New poster
Posts: 16
Joined: Tue Apr 01, 2014 7:36 pm

WA verdict 537 - Artificial Intelligence?

Post by mhsn06 »

Hello everyone,
I'm getting WA verdict but can't find the bug. Please help me to find the bug.

Got AC.

Code: Select all


the following line was the culprit

  for(i; c[i]; i++)
 
Last edited by mhsn06 on Mon Aug 18, 2014 1:33 pm, edited 2 times in total.
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: WA verdict 537 - Artificial Intelligence?

Post by lighted »

Use search by problem number (537) and check your program for input in that threads.
http://acm.uva.es/board/search.php?keyw ... 1235a6aaec
One example
Jan wrote:Just try the I/O set... In my compiler your code returns wrong..

Input:

Code: Select all

3
U=120V and I=5.36A. What is the reason for calculating p? I cant understand ?
There was a p who has P=560W Which was destroyed by U=291.89V.
No chance if P=111.11W and I=3.004A.
Output:

Code: Select all

Problem #1
P=643.20W

Problem #2
I=1.92A

Problem #3
U=36.99V
Hope it works..
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
mhsn06
New poster
Posts: 16
Joined: Tue Apr 01, 2014 7:36 pm

Re: WA verdict 537 - Artificial Intelligence?

Post by mhsn06 »

I'm getting the same result with no error.
Will you please tell me the error description?
Post Reply

Return to “Volume 5 (500-599)”