Topic Input Requirements:
2 2 10//device number n next operand m fuse can withstand maximum current C
5//electrical current of 1
7//2 of electricity
1//Reversing switch 1
2//Reversing switch 2
Idea: Set a flag array, remember to enter a data set each time, reset to 0,flag starting from 1, Flag[1]...flag[n] analog switch state
Each device's current is stored in the CI array, starting from 1 to save Ci[1], save to ci[n], regardless of ci[0],n<=20, give a number greater than 21
Then, using a For loop, read the device serial number, if the Flag[dev]==0,flag reverse to open, Ci_total plus the corresponding serial number of the device's current Ci[dev]
Device serial number Dev 1 2 3 4 5 6
Ci[] Device counterpart current 7 4 5 9 2 8
flag[] Device status 0 0 1 0 1 0
Array sequence 0 1 &NBSP;2 &NBSP ; 3 4 5 6
#include <stdio.h> #include <stdlib.h> #include <string.h>int main () {int n,m,c,i,count=0; int flag[25],ci[1000]; while (scanf ("%d%d%d", &n,&m,&c)!=eof) {int ci_total=0; if (n==0&&m==0&&c==0) break; memset (flag,0,sizeof (flag)); for (i=1;i<n+1;i++) {scanf ("%d", &ci[i]); } int max=0; for (i=1;i<m+1;i++) {int dev; scanf ("%d", &dev); if (flag[dev]==0) {flag[dev]=1;//reverses state ci_total+=ci[dev];//} else {flag[dev]=0; Ci_total-=ci[dev]; if (Ci_total>max)//If in the process, there is a max>c situation, the next data input can only make him higher, not smaller, so, even more than the current greater than the number of Max, the loop will be >c Max=ci_total; Did not encounter max>c no chant} if (max>c) {printf ("Sequence%d\n", ++count); printf ("Fuse was BloWn.\n "); printf ("\ n"); } else {printf ("Sequence%d\n", ++count); printf ("Fuse is not blown.\n"); printf ("Maximal power consumption was%d amperes.\n", Max); printf ("\ n"); }} return 0;}
WA three times, reason memset function not clear
Memset included in header file: #include <string.h>, string handler function
memset (array address, value to be assigned, array size to be assigned, usually sizeof (array name) or sizeof (FLAG[0]*M))
sizeof (FLAG[0]*M) indicates that the array is assigned a value of M elements starting at the given address
poj1484---to determine if the fuse is blown