[2016-04-09] [Codeforces] [660] B [Seating on Bus]

Source: Internet
Author: User

    • Time: 2016-04-09-23:29:47 Saturday
    • Title Number: [2016-04-09][codeforces][660][b][seating on Bus]
    • Main topic: Seated in a specified order, out of the seat in a specified order, asking the order of the last out seat
    • Analysis: Direct 4 queue simulations once again
  
 
  1. #include<cstdio>
  2. #include<queue>
  3. using namespace std;
  4. queue<int> q[4];
  5. int main(){
  6. int n,m;
  7. scanf("%d%d",&n,&m);
  8. int i = 1;
  9. for(;i <= 2*n && i <= m;++i)
  10. q[i&1].push(i);
  11. for(;i<=4*n && i<= m;++i)
  12. q[(i&1) + 2].push(i);
  13. while (! q [ 0 . empty () | | ! q [ 1 . empty () | |! q [ 3 . empty () | |! q [ 2 . empty ()) {
  14. if(!q[3].empty()){
  15. printf("%d ",q[3].front());q[3].pop();
  16. }
  17. if(!q[1].empty()){
  18. printf("%d ",q[1].front());q[1].pop();
  19. }
  20. if(!q[2].empty()){
  21. printf("%d ",q[2].front());q[2].pop();
  22. }
  23. if(!q[0].empty()){
  24. printf("%d ",q[0].front());q[0].pop();
  25. }
  26. }
  27. return 0;
  28. }


From for notes (Wiz)

[2016-04-09] [Codeforces] [660] B [Seating on Bus]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.