Page 1 of 5

661 - Blowing Fuses

Posted: Wed Dec 24, 2003 9:39 am
by Frostina
please tell me why... thx ... ^^"

[cpp]
#include <iostream>
using namespace std;
int main() {
long n,m,c,s,i,max;
int t,k=0;
while (cin>>n>>m>>c) {
if (!n&&!m&&!c) break;
int *on = new int[n];
int *power = new int[n];
for (i=0;i<n;i++) {
on = -1;
cin >> power;
}
for (i=0,s=0,max=0;i<m;i++) {
cin >> t;
--t;
on[t] = -on[t];
s+=power[t]*on[t];
if (s>c) break;
if (s>max) max = s;
}
cout << "Sequence " << ++k << endl;
if (s>c) cout << "Fuse was blown." << endl << endl;
else {
cout << "Fuse was not blown." << endl;
cout << "Maximal power consumption was " << max << " amperes." << endl << endl;
}
}
return 0;
}
[/cpp]

Posted: Wed Apr 07, 2004 8:57 am
by Ryan Pai
Think of a case like this:

Turning on something really powerful.
Turning it right off.

Logically this should blow a weak fuse.

Posted: Tue May 04, 2004 11:45 am
by Buffon
some features first.

think in your code, you are using 2 vectores, one only to take the signed of an integer..

why dont you take both to one?

Ok, another discusion is to see why you take
long n,m,c,s,i,max;
and your vectors are only INT. what happen if they give you unsigned longs as inputs, your program wont break, but gonna WA.

Another way can be you have one device that suply energy, its means that start from negative number, and only has 1 sequence that turn on that device, this means your max energy consumption will be negative, and you asume that start from zero, then this case will never pass.

im gonna solve this problem, when i get AC or PE i will report to you ;) only i have seen some cases will be exploit.

Posted: Fri Jun 18, 2004 3:56 pm
by Buffon
I get AC

the problem is in your vectors, made it as long

sorry but exams get all my time :S

661 blowing fuses please help me out i got WA

Posted: Sat Jul 10, 2004 11:36 am
by na5ir_algo
please tell me what to do. tell me if there is some logical mistake or others mistakes this is code which i have submitted to acm and got WA

[/cpp]
#include <iostream>

using namespace std;

int main(void)
{
int d = 0;
int o = 0;
int c = 0;
int *inarray;
int *farray;
int cap = 0;
int cindex = -1;
int maxcap = 0;
int seq = 0;
int size = 0;

cin>>d>>o>>c;

while(d != 0 || o!= 0 || c != 0)
{
seq++;
size = o+d;
inarray = new int[size];
size = d;
farray = new int[size];
size = o+d;
for(int z=0; z<size; z++)
{
inarray[z] = 0;

if(z < d)
farray[z] = 0;
}

for(int i=0; i<size; i++)
{
cin>>inarray;
if(i >= d)
{
cindex = inarray;

if(farray[cindex-1] == 0)
{
cap += inarray[cindex-1];
farray[cindex-1] = 1;
maxcap = cap;
}
else if(farray[cindex-1] == 1)
{
cap -= inarray[cindex-1];
farray[cindex-1] = 0;
}
}
}

if(cap > c)
{
cout<<"Sequence "<<seq<<endl;
cout<<"Fuse was blown."<<endl;
cout<<endl;
}
else if(cap < c)
{
cout<<"Sequence "<<seq<<endl;
cout<<"Fuse was not blown."<<endl;
cout<<"Maximal power consumption was "<<maxcap<<" amperes."<<endl;
cout<<endl;
}

cap = 0;
cin>>d>>o>>c;
}

return 0;
}
[cpp][/cpp] :(

Posted: Sat Jul 10, 2004 12:04 pm
by nasty
yar dr a qadir se contact karoo

i have checked ur program............

Posted: Sat Jul 10, 2004 1:54 pm
by majid
yar ek dafa phir Dr A Qadir se se contact karoo

Posted: Sat Jul 10, 2004 2:07 pm
by sohel
This is an international forum...

If you know English
then please use it.
else
use private message.

:wink:

Posted: Thu Jul 15, 2004 5:56 pm
by Raiyan Kamal
sohel wrote:This is an international forum...

If you know English
then please use it.
else
use private message.

:wink:
I agree.

If you don't let people help you, then should not expect any help form them.

661 - PE

Posted: Wed Jun 01, 2005 11:35 am
by Karthekeyan
Here's my code....I got PE from OJ!!!! Where's the problem?

Code: Select all

spoiler

Posted: Wed Jun 01, 2005 2:16 pm
by Mohammad Mahmudur Rahman
Problem statement says ->
Output a blank line after each test case.
But your program doesn't print one after the last case.

Posted: Wed Jun 01, 2005 4:08 pm
by Karthekeyan
that was rite....thanx!!!!

661 WA =(

Posted: Tue Aug 23, 2005 4:51 pm
by kenneth
This is a very easy question, but I just can't get it accepted. Can anyone provide any help by either providing some critical input/output or point out where is the problem of my logic? Thanks in advance

Finally Accepted. The problem is I made a mistake by breaking the for loop as soon as the fuse was blown, resulting in the program not reading all the input properly >.<

Posted: Wed Oct 05, 2005 12:18 am
by Jan
Karthekeyan,
Delete your code.

661 WA please help

Posted: Tue Feb 07, 2006 3:31 pm
by Wei-Ming Chen
AC now