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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 661 - Blowing Fuses

Post by brianfry713 » Fri Apr 04, 2014 9:03 pm

Try running your code on the sample input.
Check input and AC output for thousands of problems on uDebug!

chenqian
New poster
Posts: 5
Joined: Wed Jun 25, 2014 12:21 am

661-Blowing fuses

Post by chenqian » Mon Jul 21, 2014 3:20 pm

Hello everyone,
This is my code I have tried every input sample what i can find in the forum, all results seem good for me. I don't know why is still "WA". Can anybody help me ? Thanks a lot!!

Code: Select all


index error in the programme . delete the code after got AC

Last edited by chenqian on Tue Jul 22, 2014 2:21 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 661-Blowing fuses

Post by brianfry713 » Mon Jul 21, 2014 9:23 pm

Input:

Code: Select all

1 20 59
17
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
5 8 82
18
20
3
1
20
2
4
3
3
5
4
2
3
8 14 93
7
1
20
8
9
18
10
13
1
2
6
5
2
5
2
4
4
8
4
3
7
6
6 5 65
14
11
18
14
7
2
6
1
5
1
6
11 20 72
11
10
13
19
15
9
20
10
16
12
5
6
8
3
4
8
6
10
3
6
5
2
4
10
2
5
6
6
4
2
4
18 7 67
8
2
15
7
3
2
10
20
7
8
10
18
1
16
2
5
12
11
5
10
11
12
17
1
9
4 12 18
13
1
4
20
2
3
3
4
4
4
3
3
3
4
4
4
12 1 4
15
11
3
14
1
2
11
17
4
14
10
1
7
2 17 10
3
7
2
1
2
2
1
2
2
1
1
1
2
1
1
2
1
1
1
1 10 1
9
1
1
1
1
1
1
1
1
1
1
2 25 99
9
9
1
2
1
1
1
2
2
1
1
2
1
2
1
2
2
1
2
2
1
1
2
1
2
2
1
1 25 5
12
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
6 24 71
10
10
14
14
14
15
4
3
3
5
4
1
5
5
5
4
1
5
5
4
2
3
3
3
1
6
2
1
5
5
20 9 60
13
12
5
8
15
12
12
10
11
16
10
19
17
15
11
9
17
6
14
5
15
18
20
18
15
8
6
5
7
4 6 60
8
1
19
2
4
2
3
2
1
4
4 13 19
6
2
7
11
3
4
1
1
3
2
3
2
4
4
1
3
3
8 20 15
18
12
18
7
14
3
3
18
6
8
8
3
1
2
2
7
5
2
3
7
4
6
1
3
5
1
1
7
12 25 70
9
6
19
7
11
2
1
8
19
20
3
2
12
5
11
3
1
8
9
4
3
6
4
1
10
8
6
9
7
12
10
7
5
4
9
7
1
1 13 64
13
1
1
1
1
1
1
1
1
1
1
1
1
1
5 6 11
18
18
5
17
3
4
1
1
4
1
1
0 0 0
AC output:

Code: Select all

Sequence 1
Fuse was not blown.
Maximal power consumption was 17 amperes.

Sequence 2
Fuse was not blown.
Maximal power consumption was 41 amperes.

Sequence 3
Fuse was not blown.
Maximal power consumption was 77 amperes.

Sequence 4
Fuse was not blown.
Maximal power consumption was 23 amperes.

Sequence 5
Fuse was not blown.
Maximal power consumption was 65 amperes.

Sequence 6
Fuse was not blown.
Maximal power consumption was 66 amperes.

Sequence 7
Fuse was blown.

Sequence 8
Fuse was blown.

Sequence 9
Fuse was not blown.
Maximal power consumption was 10 amperes.

Sequence 10
Fuse was blown.

Sequence 11
Fuse was not blown.
Maximal power consumption was 18 amperes.

Sequence 12
Fuse was blown.

Sequence 13
Fuse was not blown.
Maximal power consumption was 49 amperes.

Sequence 14
Fuse was not blown.
Maximal power consumption was 54 amperes.

Sequence 15
Fuse was not blown.
Maximal power consumption was 29 amperes.

Sequence 16
Fuse was blown.

Sequence 17
Fuse was blown.

Sequence 18
Fuse was blown.

Sequence 19
Fuse was not blown.
Maximal power consumption was 13 amperes.

Sequence 20
Fuse was blown.

Check input and AC output for thousands of problems on uDebug!

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 661-Blowing fuses

Post by lighted » Tue Jul 22, 2014 11:29 am

Its strange how your program was giving correct output.
You must change this part

Code: Select all

if (etat[device] == false ){
    currentC +=  cap[device-1]; 
  }
  else{
    currentC -= cap[device-1];
  }
  etat[device] = !etat[device-1];
It must be

Code: Select all

if (etat[device - 1] == false ){
    currentC +=  cap[device-1]; 
  }
  else{
    currentC -= cap[device-1];
  }
  etat[device - 1] = !etat[device-1];
Don't forget to remove your code after getting accepted. 8)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

chenqian
New poster
Posts: 5
Joined: Wed Jun 25, 2014 12:21 am

Re: 661-Blowing fuses

Post by chenqian » Tue Jul 22, 2014 2:19 pm

Thanks a lot !! What a stupid error i have made!!!!!!!! get accept!!

kabanen
New poster
Posts: 1
Joined: Mon Jan 12, 2015 8:41 pm

Re: 661 - Blowing Fuses

Post by kabanen » Mon Jan 12, 2015 8:44 pm

nvm, got AC.

hkhoi
New poster
Posts: 1
Joined: Wed Mar 25, 2015 4:36 pm

Re: 661 - Blowing Fuses

Post by hkhoi » Wed Mar 25, 2015 4:51 pm

I really don't know why I receive WA on this problem. I test my code with udebug and the output is correct. Please help me figure out what the problem is. Thank you very much!

Code: Select all


import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	static int seq = 1;

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int dev, op, max;
		while (true) {
			dev = scan.nextInt();	// Get number of devices
			op = scan.nextInt();	// Get number of operations
			max = scan.nextInt();	// Get fuse capacity

			if (dev == 0 && op == 0 && max == 0) {
				break;				// If dev = op = max = 0 then terminate
			}
			boolean[] toggle = new boolean[dev];	// All devices are turned-off
			int power[] = new int[dev];
			boolean blow = false;

			for (int i = 0; i < dev; ++i) {
				power[i] = scan.nextInt();		// Get power consumption of each device	
			}

			int cur = 0, maxPower = 0;

			for (int i = 0; i < op; ++i) {
				int temp = scan.nextInt() - 1;	// Get current operation
				if (!blow) {					// If the fuse was not blown
					if (!toggle[temp]) {		// If it is off
						toggle[temp] = true;	// turn on
						cur += power[temp];		
						if (cur > max) {
							blow = true;
							continue;
						}
						if (cur > maxPower) {
							maxPower = cur;
						}
					} else {
						toggle[temp] = false;
						cur -= power[temp];
					}
				}
			}
			out.println("Sequence " + seq++);
			if (blow) {
				out.println("Fuse was blown.");
			} else {
				out.println("Fuse was not blown.");
				out.println("Maximal power consumption was " + maxPower + " amperes.");

			}
			out.println();
		}
		out.close();
		scan.close();
	}
}


hmishra2250
New poster
Posts: 1
Joined: Tue May 12, 2015 11:46 am

Re: 661 - Blowing Fuses

Post by hmishra2250 » Tue May 12, 2015 11:53 am

Can somebody help !
I have literally tried everything !!!

Code: Select all

#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
int n,m,cap,t=0;
while(t++,scanf("%d %d %d",&n,&m,&cap)==3&&(n||m||cap))
{
	if(t>1)
	printf("\n");
	int *v=new int[n+1];
	int temp,max=-1,ans=0,flag=0;
	bool *b=new bool[n+1];
	for(int i=0;i<n;i++)
	{
	cin>>temp;
	v[i]=temp;
	b[i]=0;
	}
	for(int i=0;i<m;i++)
	{
	cin>>temp;
	temp--;
	if(b[temp]==0)
	{
		b[temp]=1;
		ans+=v[temp];
	}
	else
	{
		b[temp]=0;
		ans-=v[temp];
	}
	if(ans>max) max=ans;
	if(ans>cap) flag=1;
	}
	printf("Sequence %d\n",t);
	if(flag) printf("Fuse was blown.\n");
	else
	printf("Fuse was not blown.\nMaximal power consumption was %d amperes.\n",max);
	delete[]b;
	delete[]v;
}
}

Post Reply

Return to “Volume 6 (600-699)”