661 - Blowing Fuses

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

Moderator: Board moderators

Frostina
New poster
Posts: 23
Joined: Mon Dec 15, 2003 5:21 am

661 - Blowing Fuses

Post 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]
Thanks for your help ! ;)
Ryan Pai
Learning poster
Posts: 67
Joined: Fri Jul 04, 2003 9:59 am
Location: USA

Post 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.
Buffon
New poster
Posts: 2
Joined: Tue May 04, 2004 11:37 am

Post 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.
try to solve myself, later take it part of contest.
Buffon
New poster
Posts: 2
Joined: Tue May 04, 2004 11:37 am

Post by Buffon »

I get AC

the problem is in your vectors, made it as long

sorry but exams get all my time :S
try to solve myself, later take it part of contest.
na5ir_algo
New poster
Posts: 2
Joined: Sat Jul 10, 2004 11:27 am

661 blowing fuses please help me out i got WA

Post 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] :(
-A-S-D-F-G-H-J-K-L-
nasty
New poster
Posts: 4
Joined: Sat Jul 10, 2004 11:27 am
Location: pakistan

Post by nasty »

yar dr a qadir se contact karoo
majid
New poster
Posts: 3
Joined: Sat Jul 10, 2004 12:17 pm

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

Post by majid »

yar ek dafa phir Dr A Qadir se se contact karoo
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Post by sohel »

This is an international forum...

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

:wink:
Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post 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.
Karthekeyan
New poster
Posts: 33
Joined: Tue Jun 29, 2004 1:38 pm
Location: IITM,chennai,Tamil Nadu,India
Contact:

661 - PE

Post by Karthekeyan »

Here's my code....I got PE from OJ!!!! Where's the problem?

Code: Select all

spoiler
Last edited by Karthekeyan on Sun Dec 25, 2005 9:47 am, edited 1 time in total.
Karthe
Mohammad Mahmudur Rahman
Experienced poster
Posts: 154
Joined: Sat Apr 17, 2004 9:34 am
Location: EEE, BUET

Post 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.
You should never take more than you give in the circle of life.
Karthekeyan
New poster
Posts: 33
Joined: Tue Jun 29, 2004 1:38 pm
Location: IITM,chennai,Tamil Nadu,India
Contact:

Post by Karthekeyan »

that was rite....thanx!!!!
Karthe
kenneth
New poster
Posts: 24
Joined: Wed Mar 02, 2005 12:29 am

661 WA =(

Post 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 >.<
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Karthekeyan,
Delete your code.
Ami ekhono shopno dekhi...
HomePage
Wei-Ming Chen
Experienced poster
Posts: 122
Joined: Sun Nov 13, 2005 10:25 am
Location: Taiwan

661 WA please help

Post by Wei-Ming Chen »

AC now
Last edited by Wei-Ming Chen on Fri Feb 10, 2006 12:05 pm, edited 2 times in total.
Post Reply

Return to “Volume 6 (600-699)”