Algorithm to improve the time limit of the old granny over the street: 1.0s memory limit: 256.0MBA total of 5 red scarves, numbered A, B, C, D, E, the grandmother was one of them to help cross the road.
Five red scarves speak each other:
A: Neither I nor e have helped granny
B: Granny is a C and E, one of them helped me through the street.
C: Granny's been helped by me and D.
D:b and C are not helping granny across the street.
E: I didn't help grandma.
It is known that there are five red scarves and only 2 people are telling the truth, who helped the old lady through the street?
If there are multiple answers, output in one line, separated by a space between the numbers.
For example
A B C D E (which is obviously not the correct answer)
1 /*2 Ideas:3 A, B, C, D, e are represented by an array, the initial value is 0 tables are false, circulation, in turn, set a-e as the truth. 4 Note that each time you loop, remember to clear the previous hypothesis 0.5 */6#include <stdio.h>7#include <string.h>8 intMain () {9 inta[5];//five red scarves are respectively indicatedTen for(intI=0;i<5; i++){ OneMemset (A,0,sizeof(a));//Each loop begins to clear the array 0 A intsum=0;//the number of people who told the truth was initially 0 . -a[i]=1; - if(a[0]==0&& a[4]==0) sum++;//A said words the if(a[2]==1|| a[4]==1) sum++;//B said words - if(a[2]==1|| a[3]==1) sum++;//C said words - if(a[1]==0&& a[2]==0) sum++;//D say. - if(a[4]==0) sum++;//E said the words + if(sum==2){ -printf"%c",'A'+i); + } A } at}
C language · Help Granny cross the street