首页 > ACM题库 > HDU-杭电 > hdu 2661 BrokenLED[解题报告]hoj
2014
02-12

hdu 2661 BrokenLED[解题报告]hoj

BrokenLED

问题描述 :

You know, there are more and more LED Displays used for show numbers in everywhere, a general product is like the left picture below, called as 7 segments LED, because it can show all the digitals from 0 to 9 with 7 segments as the right picture below.

There are many 7 segment LED displays in our restraint, so we can view the money left in our sunny card. Unfortunately, some displays always with one or more segment are broken, that means, the segment which should be light up when it display a digital can’t work. For example, if the ‘a’ segment is broken, then ’7′ and ’1′ will be displayed as ’1′ either.
Now, Bob who is standing on front of a broken LED display want to know, how many possible results would be the number on the display. For example, with a LED display which it’s all ‘a’ segments were broken, "11" would be 4 possible results which are "11", "17", "71" and "77". Note that pre-zeros are valid, for example, "0001" is equal to "1" or "01".

输入:

There are multiply test cases, every case start with a single integers N in the first line, that is how many LED in this case, the second line is a string shows which segment is broken in the LED from ‘a’ to ‘g’, good segment will replace as ‘-’, the follow N lines will hold a string in each line to show numbers from left to right, which shows the lighted segment in the i-th LED. (1 <= N <= 9)
Input will end with a single line which N == -1.

输出:

There are multiply test cases, every case start with a single integers N in the first line, that is how many LED in this case, the second line is a string shows which segment is broken in the LED from ‘a’ to ‘g’, good segment will replace as ‘-’, the follow N lines will hold a string in each line to show numbers from left to right, which shows the lighted segment in the i-th LED. (1 <= N <= 9)
Input will end with a single line which N == -1.

样例输入:

2 
a------ 
--c--f- 
--c--f- 
-1 

样例输出:

Case 1: 4


#include<iostream>using namespace std;//用位表示,如果某个显示是属于某个数字的且这个数组是属于这个显示和bug的并集//那么有可以取该中数字,这里的属于就是“|” char c[11];int a[11];//存显示的数据 int b[11];//模板 int bug;int s[11];//模板 int main(){    int i,j,k,t,r,n,count=1,len,temp,x,y;    s[1]=1;s[2]=2;s[3]=4;s[4]=8;s[5]=16;s[6]=32;s[7]=64;//abcdefg    b[0]=119;b[1]=36;b[2]=93;b[3]=109;b[4]=46;b[5]=107;b[6]=123;b[7]=37;b[8]=127;b[9]=111;    while(scanf("%d",&n)!=EOF)    {          if(n==-1)break;          memset(a,0,sizeof(a));          scanf("%s",c);          len=strlen(c);          bug=0;          for(i=0;i<len;i++)          {              if(c[i]!=’-')              {                 bug=bug+s[c[i]-’a'+1];                 }                           }    //          cout<<bug<<endl;              for(i=1;i<=n;i++)          {              scanf("%s",c);              len=strlen(c);              for(j=0;j<len;j++)              {                  if(c[j]!=’-')a[i]+=s[c[j]-’a'+1];                                }//              cout<<"a["<<i<<"]="<<a[i]<<endl;                               }             r=1;          for(i=1;i<=n;i++)          {              x=(bug|a[i]);              t=0;              for(j=0;j<=9;j++)              {                  y=(b[j]|a[i]);                  temp=(x|b[j]);                               if((y==b[j])&&(x==temp))t++;                               }                           r=r*t;                  }              printf("Case %d: %d\n",count++,r);                                           }    return 0;    }
解题参考:http://hi.baidu.com/foreverlin1204/item/049814ce09bd7913b77a2455


  1. 第一题是不是可以这样想,生了n孩子的家庭等价于n个家庭各生了一个1个孩子,这样最后男女的比例还是1:1

  2. 第二个方法挺不错。NewHead代表新的头节点,通过递归找到最后一个节点之后,就把这个节点赋给NewHead,然后一直返回返回,中途这个值是没有变化的,一边返回一边把相应的指针方向颠倒,最后结束时返回新的头节点到主函数。

  3. Thanks for taking the time to examine this, I really feel strongly about it and love studying a lot more on this topic. If possible, as you acquire experience