Page 5 of 6
WA-537-Artificial Intelligence?
Posted: Mon Apr 01, 2013 11:19 pm
by shipu_a
wa plz help me................
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;
}
Re: WA-537-Artificial Intelligence?
Posted: Mon Apr 01, 2013 11:31 pm
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:
Re: WA-537-Artificial Intelligence?
Posted: Mon Apr 01, 2013 11:36 pm
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:
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;
}
Re: WA-537-Artificial Intelligence?
Posted: Mon Apr 01, 2013 11:48 pm
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:
Re: WA-537-Artificial Intelligence?
Posted: Tue Apr 02, 2013 12:00 am
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:
may be it's not correct answer.........
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,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;
}
Re: WA-537-Artificial Intelligence?
Posted: Tue Apr 02, 2013 12:12 am
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:
Re: WA-537-Artificial Intelligence?
Posted: Tue Apr 02, 2013 12:46 am
by shipu_a
finally ac..........
Re: WA-537-Artificial Intelligence?
Posted: Tue Apr 02, 2013 12:53 am
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?
Re: WA-537-Artificial Intelligence?
Posted: Thu Aug 15, 2013 6:42 pm
by dhruba07
getting wrong answer on this code
Thanks.I finally got AC
Re: WA-537-Artificial Intelligence?
Posted: Thu Aug 15, 2013 11:12 pm
by brianfry713
Print a blank line after the last test case.
Re: WA-537-Artificial Intelligence?
Posted: Thu Jul 03, 2014 4:14 pm
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;
}
Re: WA-537-Artificial Intelligence?
Posted: Tue Jul 08, 2014 12:53 am
by brianfry713
I used atof() to convert the real numbers.
WA verdict 537 - Artificial Intelligence?
Posted: Mon Aug 18, 2014 12:05 am
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++)
Re: WA verdict 537 - Artificial Intelligence?
Posted: Mon Aug 18, 2014 1:44 am
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..
Re: WA verdict 537 - Artificial Intelligence?
Posted: Mon Aug 18, 2014 11:15 am
by mhsn06
I'm getting the same result with no error.
Will you please tell me the error description?