661 - Blowing Fuses

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

Moderator: Board moderators

661 - Blowing Fuses

Postby Frostina » Wed Dec 24, 2003 9:39 am

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[i] = -1;
cin >> power[i];
}
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 ! ;)
Frostina
New poster
 
Posts: 23
Joined: Mon Dec 15, 2003 5:21 am

Postby Ryan Pai » Wed Apr 07, 2004 8:57 am

Think of a case like this:

Turning on something really powerful.
Turning it right off.

Logically this should blow a weak fuse.
Ryan Pai
Learning poster
 
Posts: 67
Joined: Fri Jul 04, 2003 9:59 am
Location: USA

Postby Buffon » Tue May 04, 2004 11:45 am

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

Postby Buffon » Fri Jun 18, 2004 3:56 pm

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

661 blowing fuses please help me out i got WA

Postby na5ir_algo » Sat Jul 10, 2004 11:36 am

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[i];
if(i >= d)
{
cindex = inarray[i];

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-
na5ir_algo
New poster
 
Posts: 2
Joined: Sat Jul 10, 2004 11:27 am

Postby nasty » Sat Jul 10, 2004 12:04 pm

yar dr a qadir se contact karoo
nasty
New poster
 
Posts: 4
Joined: Sat Jul 10, 2004 11:27 am
Location: pakistan

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

Postby majid » Sat Jul 10, 2004 1:54 pm

yar ek dafa phir Dr A Qadir se se contact karoo
majid
New poster
 
Posts: 3
Joined: Sat Jul 10, 2004 12:17 pm

Postby sohel » Sat Jul 10, 2004 2:07 pm

This is an international forum...

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

:wink:
User avatar
sohel
Guru
 
Posts: 862
Joined: Thu Jan 30, 2003 5:50 am
Location: University of Texas at San Antonio

Postby Raiyan Kamal » Thu Jul 15, 2004 5:56 pm

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.
Raiyan Kamal
Experienced poster
 
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh

661 - PE

Postby Karthekeyan » Wed Jun 01, 2005 11:35 am

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

Postby Mohammad Mahmudur Rahman » Wed Jun 01, 2005 2:16 pm

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.
Mohammad Mahmudur Rahman
Experienced poster
 
Posts: 154
Joined: Sat Apr 17, 2004 9:34 am
Location: EEE, BUET

Postby Karthekeyan » Wed Jun 01, 2005 4:08 pm

that was rite....thanx!!!!
Karthe
Karthekeyan
New poster
 
Posts: 33
Joined: Tue Jun 29, 2004 1:38 pm
Location: IITM,chennai,Tamil Nadu,India

661 WA =(

Postby kenneth » Tue Aug 23, 2005 4:51 pm

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 >.<
kenneth
New poster
 
Posts: 24
Joined: Wed Mar 02, 2005 12:29 am

Postby Jan » Wed Oct 05, 2005 12:18 am

Karthekeyan,
Delete your code.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

661 WA please help

Postby Wei-Ming Chen » Tue Feb 07, 2006 3:31 pm

AC now
Last edited by Wei-Ming Chen on Fri Feb 10, 2006 12:05 pm, edited 2 times in total.
Wei-Ming Chen
Experienced poster
 
Posts: 122
Joined: Sun Nov 13, 2005 10:25 am
Location: Taiwan

Next

Return to Volume VI

Who is online

Users browsing this forum: No registered users and 0 guests