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