[HDU 3328] [Data Structure] Flipper

is a problem of flipping the brand. It is a little cumbersome to write, because it is only a laboratory water problem, so it is not optimized. L is flipped from the far left and overlaid on the second pile, and so on, the simulation is just fine.

[cpp]< /strong> view plain copy

< span> print? View code piece on CODE derived to my code piece

  1. #include”stdio.h”
  2. #include “stack”
  3. #include”queue “
  4. using namespacestd;
  5. intmain(intargc,charconst*argv[])
  6. {
  7. intn;
  8. int< span style="margin:0px; padding:0px; border:none; background-color:inherit">cas=1;
  9. while(~scanf(“%d”,&n)&&n)
  10. {}< /span>
  11. getchar();
  12. intlnum=1;
  13. intrnum=n; /span>
  14. intPoker [105];
  15. stack<int> s1,s2,s3;
  16. < li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(153,153,153); list- style:decimal-leading-zero outside; color:rgb(85,85,85); line-height:18px; background-color:rgb(245,250,226)"> charsta,ope;

  17. for(inti = 1; i < = N; ++i)
  18. {
  19. scanf(“%c”,&sta);
  20. if(sta==‘D’) ​​/span>
  21. Poker[i]=0;
  22. else
  23. Poker[i]=1;
  24. < /li>
  25. getchar();
  26. s1.push(1); < /li>
  27. s2.push(n);
  28. for< span style="margin:0px; padding:0px; border:none; background-color:inherit"> (inti=1;i
  29. {
  30. scanf(< span class="string" style="margin:0px; padding:0px ; border:none; color:red; background-color:inherit">“%c”,&ope );
  31. if(ope= =‘L’)
  32. {
  33. for( int< /span>j=1;j<=lnum;++j) li>
  34. {
  35. if(Poker[j])
  36. Poker[j]=0;
  37. else
  38. Poker[j]=1;
  39. lnum++;
  40. if(lnum==rnum)
  41. while(!s2.empty())< /li>
  42. inttemp2=s2.top();
  43. s2.pop(); s2.pop(); padding:0px; border:none; color:black; background-color:inherit”>
  44. s1.push(temp2);
  45.                     }  
  46. < li style="margin:0px!important; padding:0px 3px 0px 10px!important; border-top:none; border-right:none; border-bottom:none; border-left:3px solid rgb(153,153,153); list- style:decimal-leading-zero outside; color:rgb(85,85,85); line-height:18px; background-color:rgb(245,250,226)">                     while(!s1.empty())  

  47.                     {  
  48.                         int temp1=s1.top();  
  49.                         s1.pop();  
  50.                         s3.push(temp1);  
  51.                     }  
  52.                     break;  
  53.                 }  
  54.                 queue <int> temp;  
  55.                 temp.push(lnum);  
  56.                 while(!s1.empty())  
  57.                 {  
  58.                     int temp1=s1.top();  
  59.                     s1.pop();  
  60.                     temp.push(temp1);  
  61.                 }  
  62.                 while(!temp.empty())  
  63.                 {  
  64.                     int temp1=temp.front();  
  65.                     temp.pop();  
  66.                     s1.push(temp1);  
  67.                 }  
  68.             }  
  69.             if(ope==‘R’)  
  70.             {  
  71.                 for (int j = n; j >= rnum; –j)  
  72.                 {  
  73.                     if(Poker[j])  
  74.                         Poker[j]=0;  
  75.                     else  
  76.                         Poker[j]=1;  
  77.                 }  
  78.                 rnum–;  
  79.                 if(lnum==rnum)  
  80.                 {  
  81.                     while(!s1.empty())  
  82.                     {  
  83.                         int temp1=s1.top();  
  84.                         s1.pop();  
  85.                         s2.push(temp1);  
  86.                     }  
  87.                     while(!s2.empty())  
  88.                     {  
  89.                         int temp2=s2.top();  
  90.                         s2.pop();  
  91.                         s3.push(temp2);  
  92.                     }  
  93.                     break;  
  94.                 }  
  95.                 queue <int> temp;  
  96.                 temp.push(rnum);  
  97.                 while(!s2.empty())  
  98.                 {  
  99.                     int temp2=s2.top();  
  100.                     s2.pop();  
  101.                     temp.push(temp2);  
  102.                 }  
  103.                 while(!temp.empty())  
  104.                 {  
  105.                     int temp2=temp.front();  
  106.                     temp.pop();  
  107.                     s2.push(temp2);  
  108.                 }  
  109.             }  
  110.         }  
  111.         printf(“Pile %d
    ,cas++);  
  112.         int num;  
  113.         int a[1000];  
  114.         int b[1000];  
  115.         int bnum=1;  
  116.         while(!s3.empty())  
  117.         {  
  118.             int temp=s3.top();  
  119.             b[bnum++]=temp;  
  120. < span style="margin:0px; padding:0px; border:none; color:black; background-color:inherit">            s3.pop();  
  121.         }  
  122.         scanf(“%d”,&num);  
  123.         for (int i = 0; i < num; ++i)  
  124.         {  
  125.             scanf(“%d”,&a[ i]);  
  126.         }  
  127.         for (int i = 0; i < num; ++i)  
  128.         {  
  129.             printf(“Card %d is a face “,a[i]);  
  130.             if(Poker[b[a[i]]])  
  131.                 printf(“up “);  
  132.             else  
  133.                 printf(“down “);  
  134.             printf(“%d.
    ,b[a[i]]);  
  135.         }  
  136.   
  137.   
  138.           
  139.     }  
  140.     return 0;  
  141. }  

就是一个翻牌子的问题,写的略繁琐,因为只是实验室水题,所以不优化了,L是从最左翻面并且覆盖到第二堆上,以此类推,模拟就好。

[cpp]  view plain  copy

 print ? 在CODE上查看代码片 派生到我的代码片

  1. #include “stdio.h”  
  2. #include “stack”  
  3. #include “queue”  
  4. using namespace std;  
  5. int main(int argc, char const *argv[])  
  6. {  
  7.     int n;  
  8.     int cas=1;  
  9.     while(~scanf(“%d”,&n) && n)  
  10.     {  
  11.         getchar();  
  12.         int lnum=1;  
  13.         int rnum=n;  
  14.         int Poker[105];  
  15.         stack <int> s1,s2,s3;  
  16.         char sta,ope;  
  17.         for (int i = 1; i <= n; ++i)  
  18.         {  
  19.             scanf(“%c”,&sta);  
  20.             if(sta==‘D’)  
  21.                 Poker[i]=0;  
  22.             else  
  23.                 Poker[i]=1;  
  24.         }  
  25.         getchar();  
  26.         s1.push(1);  
  27.         s2.push(n);  
  28.   
  29.         for (int i = 1; i < n; ++i)  
  30.         {  
  31.             scanf(“%c”,&ope);  
  32.             if(ope==‘L’)  
  33.             {  
  34.                 for (int j = 1; j <= lnum; ++j)  
  35.                 {  
  36.                     if(Poker[j])  
  37.                         Poker[j]=0;  
  38.                     else  
  39.                         Poker[j]=1;  
  40.                 }  
  41.                 lnum++;  
  42.                 if(lnum==rnum)  
  43.                 {  
  44.                     while(!s2.empty())  
  45.                     {  
  46.                         int temp2=s2.top();  
  47.                         s2.pop();  
  48.                         s1.push(temp2);  
  49.                     }  
  50.                     while(!s1.empty())  
  51.                     {  
  52.                         int temp1=s1.top();  
  53.                         s1.pop();  
  54.                         s3.push(temp1);  
  55.                     }  
  56.                     break;  
  57.                 }  
  58.                 queue <int> temp;  
  59.                 temp.push(lnum);  
  60.                 while(!s1.empty())  
  61.                 {  
  62.                     int temp1=s1.top();  
  63.                     s1.pop();  
  64.                     temp.push(temp1);  
  65.                 }  
  66.                 while(!temp.empty())  
  67.                 {  
  68.                     int temp1=temp.front();  
  69.                     temp.pop();  
  70.                     s1.push(temp1);  
  71.                 }  
  72.             }  
  73.             if(ope==‘R’)  
  74.             {  
  75.                 for (int j = n; j >= rnum; –j)  
  76.                 {  
  77.                     if(Poker[j])  
  78.                         Poker[j]=0;  
  79.                     else  
  80.                         Poker[j]=1;  
  81.                 }  
  82.                 rnum–;  
  83.                 if(lnum==rnum)  
  84.                 {  
  85.                     while(!s1.empty())  
  86.                     {  
  87.                         int temp1=s1.top();  
  88.                         s1.pop();  
  89.                         s2.push(temp1);  
  90.                     }  
  91.                     while(!s2.empty())  
  92.                     {  
  93.                         int temp2=s2.top();  
  94.                         s2.pop();  
  95.                         s3.push(temp2);  
  96.                     }  
  97.                     brea k;  
  98.                 }  
  99.                 queue <int> temp;  
  100.                 temp.push(rnum);  
  101.                 while(!s2.empty())  
  102.                 {  
  103.                     int temp2=s2.top();  
  104.                     s2.pop();  
  105.                     temp.push(temp2);  
  106.                 }  
  107.                 while(!temp.empty())  
  108.                 {  
  109.                     int temp2=temp.front();  
  110.                     temp.pop();  
  111.                     s2.push(temp2);  
  112.                 }  
  113.             }  
  114.         }  
  115.         printf(“Pile %d
    ,cas++);  
  116.         int num;  
  117.         int a[1000];  
  118.         int b[1000];  
  119.         int bnum=1;  
  120.         while(!s3.empty())  
  121.         {  
  122.             int temp=s3.top();  
  123.             b[bnum++]=temp;  
  124.             s3.pop();  
  125.         }  
  126.         scanf(“%d”,&num);  
  127.         for (int i = 0; i < num; ++i)  
  128.         {  
  129.             scanf(“%d”,&a[i]);  
  130.         }  
  131.         for (int i = 0; i < num; ++i)  
  132.         {  
  133.             printf(“Card %d is a face “,a[i]);  
  134.             if(Poker[b[a[i]]])  
  135.                 printf(“up “);  
  136.             else  
  137.                 printf(“down “);  
  138.             printf(“%d.
    ,b[a[i]]);  
  139.         }  
  140.   
  141.   
  142.           
  143.     }  
  144.     return 0;  
  145. }  

[cpp]  view plain  copy

 print ? 在CODE上查看代码片 派生到我的代码片

  1. #include “stdio.h”  
  2. #include “stack”  
  3. #include “queue”  
  4. using namespace std;  
  5. int main(int argc, char const *argv[])  
  6. {  
  7.     int n;  
  8.     int cas=1;  
  9.     while(~scanf(“%d”,&n) && n)  
  10.     {  
  11.         getchar();  
  12.         int lnum=1;  
  13.         int rnum=n;  
  14.         int Poker[105];  
  15.         stack <int> s1,s2,s3;  
  16.         char sta,ope;  
  17.         for (int i = 1; i <= n; ++i)  
  18.         {  
  19.             scanf(“%c”,&sta);  
  20.             if(sta==‘D’)  
  21.                 Poker[i]=0;  
  22.             else  
  23.                 Poker[i]=1 ;  
  24.         }  
  25.         getchar();  
  26.         s1.push(1);  
  27.         s2.push(n);  
  28.   
  29.         for (int i = 1; i < n; ++i)  
  30.         {  
  31.             scanf(“%c”,&ope);  
  32.             if(ope==‘L’)  
  33.             {  
  34.                 for (int j = 1; j <= lnum; ++j)  
  35.                 {  
  36.                     if(Poker[j])  
  37.                         Poker[j]=0;  
  38.                     else  
  39.                         Poker[j]=1;  
  40.                 }  
  41.                 lnum++;  
  42.                 if(lnum==rnum)  
  43.                 {  
  44.                     while(!s2 .empty())  
  45.                     {  
  46.                         int temp2=s2.top();  
  47.                         s2.pop();  
  48.                         s1.push(temp2);  
  49.                     }  
  50.                     while(!s1.empty())  
  51.                     {  
  52.                         int temp1=s1.top();  
  53.                         s1.pop();  
  54.                         s3.push(temp1);  
  55.                     }  
  56.                     break;  
  57.                 }  
  58.                 queue <int> te mp;  
  59.                 temp.push(lnum);  
  60.                 while(!s1.empty())  
  61.                 {  
  62.                     int temp1=s1.top();  
  63.                     s1.pop();  
  64.                     temp.push(temp1);  
  65.                 }  
  66.                 while(!temp.empty())  
  67.                 {  
  68.                     int temp1=temp.front();  
  69.                     temp.pop();  
  70.                     s1.push(temp1);  
  71.                 }  
  72.             }  
  73.             if(ope==‘R’)  
  74.             {  
  75.                 for (int j = n; j >= rnum; –j)  
  76.                 {  
  77.                     if(Poker[j])  
  78.                         Poker[j]=0;  
  79.                     else  
  80.                         Poker[j]=1;  
  81.                 }  
  82.                 rnum–;  
  83.                 if(lnum==rnum)  
  84.                 {  
  85.                     while(!s1.empty())  
  86.                     {  
  87.                         int temp1=s1.top();  
  88.                         s1.pop();  
  89.                         s2.push(temp1);  
  90.                     }  
  91.                     while(!s2.empty())  
  92.                     {  
  93.                         int temp2=s2.top();  
  94.                         s2.pop();  
  95.                         s3.push(temp2);  
  96.                     }  
  97.                     break;  
  98.                 }  
  99.                 queue <int> temp;  
  100.                 temp.push(rnum);  
  101.                 while(!s2.empty())  
  102.                 {  
  103.                     int temp2=s2.top();  
  104.                     s2.pop();  
  105.                     temp.push(temp2);  
  106.                 }  
  107.                 while(!temp.empty())  
  108.                 {  
  109.                     int temp2=temp.front();  
  110.                     temp.pop();  
  111.                     s2.push(temp2);  
  112.                 }  
  113.             }  
  114.         }  
  115.         printf(“Pile %d
    ,cas++);  
  116.         int num;  
  117.         int a[1000];  
  118.         int b[1000];  
  119.         int bnum=1;  
  120.         while(!s3.empty())  
  121.         {  
  122.             int temp=s3.top();  
  123.             b[bnum++]=temp;  
  124.             s3.pop();  
  125.         }  
  126.         scanf(“%d”,&num);  
  127.         for (int i = 0; i < num; ++i)  
  128.         {  
  129.             scanf(“%d”,&a[i]);  
  130.         }  
  131.         for (int i = 0; i < num; ++i)  
  132.         {  
  133.             printf(“Card %d is a face “,a[i]);  
  134.             if(Poker[b[a[i]]])  
  135.                 printf(” up “);  
  136.             else  
  137.                 printf(“down “);  
  138.             printf(“%d.
    ,b[a[i]]);  
  139.         }  
  140.   
  141.   
  142.           
  143.     }  
  144.     return 0;  
  145. }  

[cpp]  view plain  copy

 print ? 在CODE上查看代码片 派生到我的代码片

[cpp]  view plain  copy

 print ? 在CODE上查看代码片 派生到我的代码片

Leave a Comment

Your email address will not be published.