661 - Blowing Fuses
Moderator: Board moderators
661 - Blowing Fuses
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]
[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 ! ![;)](./images/smilies/icon_wink.gif)
![;)](./images/smilies/icon_wink.gif)
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
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.
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
and your vectors are only INT. what happen if they give you unsigned longs as inputs, your program wont break, but gonna WA.long n,m,c,s,i,max;
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
![;)](./images/smilies/icon_wink.gif)
try to solve myself, later take it part of contest.
-
- New poster
- Posts: 2
- Joined: Sat Jul 10, 2004 11:27 am
661 blowing fuses please help me out i got WA
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]![:(](./images/smilies/icon_frown.gif)
[/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]
![:(](./images/smilies/icon_frown.gif)
-A-S-D-F-G-H-J-K-L-
i have checked ur program............
yar ek dafa phir Dr A Qadir se se contact karoo
-
- Experienced poster
- Posts: 106
- Joined: Thu Jan 29, 2004 12:07 pm
- Location: Bangladesh
- Contact:
-
- New poster
- Posts: 33
- Joined: Tue Jun 29, 2004 1:38 pm
- Location: IITM,chennai,Tamil Nadu,India
- Contact:
661 - PE
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
-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET
-
- New poster
- Posts: 33
- Joined: Tue Jun 29, 2004 1:38 pm
- Location: IITM,chennai,Tamil Nadu,India
- Contact:
661 WA =(
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 >.<
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 >.<
-
- Experienced poster
- Posts: 122
- Joined: Sun Nov 13, 2005 10:25 am
- Location: Taiwan
661 WA please help
AC now
Last edited by Wei-Ming Chen on Fri Feb 10, 2006 12:05 pm, edited 2 times in total.