Codeforces 534D Handshakes Construction simulation greedy

Source: Internet
Author: User

Test instructions: People in turn into the hall, the last person will and inside all the people shook hands, in the hall there are three people in which lost Jin can walk out of the hall. Give each of you the number of times you shook hands when entering the hall. Let you ask for an entry order.

Problem-solving ideas: The game is used to push forward from behind. It is difficult to find a direct simulation from the trip.

Problem Solving Code:

1 //File name:d.cpp2 //Author:darkdream3 //Created time:2015 April 13 Monday 01:30 17 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> -#include <queue> - #defineLL Long Long -  - using namespacestd; - intN; in inta[200005]; - intpoint[2000005]; to intans[200005]; +queue<int> qu[200000]; - intMain () { thescanf"%d",&n); *      for(inti =1; I <= N;i + +) $     {Panax Notoginsengscanf"%d",&a[i]); - Qu[a[i]].push (i); the     } +     intj =0 ;  A      for(inti =1; I <= N;i + +){ the          while(Qu[j].empty () && J >=3) +J-=3;  -         if(Qu[j].empty ()) $         { $Puts"impossible\n"); -             return 0 ;  -         } theAns[i] =Qu[j].front (); - Qu[j].pop ();Wuyi++J; the     } -Puts"possible\n"); Wu      for(inti =1; I <= N;i + +) -printf (i = =1?"%d":"%d", Ans[i]); About return 0; $}
View Code

Codeforces 534D Handshakes Construction simulation greedy

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.