661 - Blowing Fuses
Moderator: Board moderators
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
Congratulations, you've just started the fifth thread on this problem!
- You just dump your code, without any explanation;
- You don't use code tags, so it will be printed in a proportional letter type, all lines cramped to the left without indentation;
- Your code is completely non-descriptive, using variables a, b, c, etc., and goto label ss.
Do you realy expect anyone to actually help you?
- You just dump your code, without any explanation;
- You don't use code tags, so it will be printed in a proportional letter type, all lines cramped to the left without indentation;
- Your code is completely non-descriptive, using variables a, b, c, etc., and goto label ss.
Do you realy expect anyone to actually help you?
The biggest problem with most problems is not how to solve the problem, but how to not solve what is not the problem.
661 - Blowing Fusues! Runtime Error.
Can anyone help me?
My code is giving Runtime Error. Here's my code:
The OJ tells me:
![:(](./images/smilies/icon_frown.gif)
Code: Select all
#include<stdio.h>
main()
{
int n,m,c,i,power_device[21],operations[21],consumption,Max,turn[21],sequence,state;
for (sequence=1;;sequence++)
{
scanf("%d %d %d",&n,&m,&c);
if (!n && !m && !c) break;
for (i=1;i<=n;i++)
{
scanf("%d",&power_device[i]);
}
consumption=0;Max=0;
for (i=1;i<=20;i++) turn[i]=0;
for (i=1;i<=m;i++)
{
scanf("%d",&operations[i]);
state=operations[i];
if (state<=n)
{
if (turn[state]==0)
{
consumption += power_device[state];
turn[state]=1;
}
else
{
turn[state]==0;
consumption-=power_device[state];
}
if (c < Max) break;
if (Max < consumption) Max = consumption;
}
}
printf ("Sequence %d\n",sequence);
if (c < Max) printf ("Fuse was blown.\n");
else
{
printf ("Fuse was not blown.\n");
printf("Maximal power consumption was %d amperes.\n",Max);
}
}
return 0;
}
Your program has died with signal 11 (SIGSEGV). Meaning:
Invalid memory reference!
Solving for fun..
I've modified source-code! but Giving TLE. Why?
My modified source-code is What's the problem in my code?
Code: Select all
#include<stdio.h>
main()
{
int n,m,c,i,power_device[21][2],operations[21],consumption,Max,sequence,state;
for (sequence=1;;sequence++)
{
scanf("%d %d %d",&n,&m,&c);
if (!n && !m && !c) break;
for (i=1;i<=n;i++)
{
scanf("%d",&power_device[i][1]);
power_device[i][2]=0;
}
consumption=0;Max=0;
for (i=1;i<=m;i++)
{
scanf("%d",&operations[i]);
state=operations[i];
if (state<=n && c>Max){
if (!power_device[state][2])
{
consumption += power_device[state][1];
power_device[state][2]=1;
}
else
{
power_device[state][2]=0;
consumption-=power_device[state][1];
}
if (Max < consumption) Max = consumption;
}
}
printf ("Sequence %d\n",sequence);
if (c < Max) printf ("Fuse was blown.\n");
else
{
printf ("Fuse was not blown.\n");
printf("Maximal power consumption was %d amperes.\n",Max);
}
}
return 0;
}
Solving for fun..
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
The problem in your code was....
Got AC. Thanks for all posts.
Code: Select all
Removed
Last edited by linux on Thu Sep 11, 2008 9:41 pm, edited 2 times in total.
Solving for fun..
The problem in your code was....
Hey! frostina, I've solved this program got an error in your code.
Definitely It's your fault. Make a correction and get accepted. Wish you success.You've broken your for-loop when s>c.
Solving for fun..
Hi,
I think you mixed something up there. You don't use max at all. Think it over.
The fuse does not blow when the currect reaches c. It blows when the current goes beyond c.
Secondly, according to the break; you don't continue reading the missing gadget-switches. Hence you might get in trouble as you read the next a, b and c but you are still in the middle of gadgets of the previous testcase.
Cu, Erik![:)](./images/smilies/icon_smile.gif)
Code: Select all
if(amp>l)
max=amp;
l=amp;
Code: Select all
if(amp>=c)
{
printf("Sequence %ld\nFuse was blown.\n\n",s);
break;
}
Secondly, according to the break; you don't continue reading the missing gadget-switches. Hence you might get in trouble as you read the next a, b and c but you are still in the middle of gadgets of the previous testcase.
Cu, Erik
![:)](./images/smilies/icon_smile.gif)
-
- Experienced poster
- Posts: 162
- Joined: Thu Jul 13, 2006 7:07 am
- Location: Campus Area. Dhaka.Bangladesh
- Contact:
Thanx everybody.
there was a chilly mistake.
newton...................................................simply the best.
there was a chilly mistake.
Code: Select all
me [spoiler] too
newton...................................................simply the best.
Last edited by newton on Tue Mar 13, 2007 7:33 am, edited 1 time in total.
Try the cases...
Input:
Output:
Hope these help.
Input:
Code: Select all
5 3 9
7
6
6
7
2
3
2
2
3 9 10
5
3
5
3
2
3
3
2
1
1
3
2
0 0 0
Code: Select all
Sequence 1
Fuse was blown.
Sequence 2
Fuse was not blown.
Maximal power consumption was 10 amperes.
Ami ekhono shopno dekhi...
HomePage
HomePage