【HDU 3328】【数据结构】Flipper

前端之家收集整理的这篇文章主要介绍了【HDU 3328】【数据结构】Flipper前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。



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


@H_403_29@
  • #include"stdio.h"
  • #include"stack"
  • #include"queue"
  • usingnamespacestd;
  • intmain(intargc,charconst*argv[])
  • {
  • intn;
  • intcas=1;
  • while(~scanf("%d",&n)&&n)
  • getchar();
  • intlnum=1;
  • intrnum=n;
  • intPoker[105];
  • stack<int>s1,s2,s3;
  • charsta,ope;
  • for(inti=1;i<=n;++i)
  • scanf("%c",&sta);
  • if(sta=='D')
  • Poker[i]=0;
  • else
  • Poker[i]=1;
  • }
  • s1.push(1);
  • s2.push(n);
  • inti=1;i<n;++i)
  • if(ope=='L')
  • {
  • intj=1;j<=lnum;++j)
  • if(Poker[j])
  • Poker[j]=0;
  • Poker[j]=1;
  • lnum++;
  • if(lnum==rnum)
  • while(!s2.empty())
  • inttemp2=s2.top();
  • s2.pop();
  • s1.push(temp2);
  • }
  • while(!s1.empty())
  • inttemp1=s1.top();
  • s1.pop();
  • s3.push(temp1);
  • break;
  • queue<int>temp;
  • temp.push(lnum);
  • temp.push(temp1);
  • while(!temp.empty())
  • inttemp1=temp.front();
  • temp.pop();
  • s1.push(temp1);
  • if(ope=='R')
  • intj=n;j>=rnum;--j)
  • if(Poker[j])
  • Poker[j]=0;
  • else
  • Poker[j]=1;
  • rnum--;
  • if(lnum==rnum)
  • while(!s1.empty())
  • inttemp1=s1.top();
  • s1.pop();
  • s2.push(temp1);
  • while(!s2.empty())
  • inttemp2=s2.top();
  • s2.pop();
  • s3.push(temp2);
  • break;
  • int>temp;
  • temp.push(rnum);
  • temp.push(temp2);
  • while(!temp.empty())
  • inttemp2=temp.front();
  • temp.pop();
  • s2.push(temp2);
  • printf("Pile%d\n",cas++);
  • intnum;
  • inta[1000];
  • intb[1000];
  • intbnum=1;
  • while(!s3.empty())
  • inttemp=s3.top();
  • b[bnum++]=temp;
  • s3.pop();
  • scanf("%d",&num);
  • inti=0;i<num;++i)
  • printf("Card%disaface",a[i]);
  • if(Poker[b[a[i]]])
  • printf("up");
  • printf("down");
  • printf("%d.\n",b[a[i]]);
  • return0;
  • }
  • 原文链接:https://www.f2er.com/datastructure/382457.html

    猜你在找的数据结构相关文章