zoj 3045 Random or Shuffle 狗模拟

Random or Shuffle Time Limit: 2 Seconds       Memory Limit: 65536 KB

Many media players, both software and hardware, support some kind of random mechanism, which allows the users to hear their songs in a random order. This also shows the variety of life in a special part -- few would like to listen to their songs in a fixed order every day. The most popular random mechanism is shuffle. When shuffle is turned on, the media player generates a random order (permutation) for the songs in the playlist before it is going to be played, and the songs will be played in the generated order one by one. When all songs in the list have been played, a new order is generated, and so on. Some media players also support another random mechanism named random. In this mode the player will choose a random song to be played next when the last song is finished. Some may think that random mode is not suitable for playing music since some songs may not be played forever. But obviously the probability is nearly zero, and I prefer random mode since it demonstrates the variety of life better. In this problem, given the sequence of song names you heard from the beginning, you're asked to determine which random mechanism the media player may use.

Input

Input of each test case contains a sequence of song names. The first line contains a single integer N (1 <= N <= 10000) indicating the size of the song sequence. Each of the following N lines contains a name of a song. The names will not be empty and their lengths will not exceed 50. You can assume the names of songs in a playlist are distinct.

There's a blank line between every two successive cases. Processing to the end of file.

Output

For each sequence, if it can only be produced in shuffle mode, print "Shuffle" in a single line; if it can only be produced in random mode, print "Random" in a single line; if it can be produced in either mode, print "Either". If neither mechanism can produce the sequence, print "Neither" instead.

Sample Input

4
Titanic Suite
The Portrait
My Heart Will Go on
Epilogue - The Deep and Timeless Sea

5
1000 Words
Epilogue ~Reunion~
Wind Crest ~The Three Trails~
Wind Crest ~The Three Trails~
Eternity ~Memories of Light and Waves~

Sample Output

Either
Random
Author:  XIAO, Dong
Source:  ZOJ Monthly, September 2008


题意:输入n,接下来是n首歌的歌名。 判断,如果播放歌的顺序是这样的,那播放模式 是 列表随机播放,或者随机播放,或者都可能,或者都不是。

做法:因为是列表随机的情况是被包括在随机播放里的。所以要么是都可能输出either,或者只可能是随机播放ramdon。


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <malloc.h>
#include <ctype.h>
#include <math.h>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#include <stack>
#include <queue>
#include <vector>
#include <deque>
#include <set>
#include <map>
#define INF 999999999
#define eps 0.00001
#define LL __int64d
#define pi acos(-1.0)



#include<stdio.h>
#include<iostream>
#include<string>
#include<map>
using namespace std;
map<string,int>my;


int main()
{
	int n;
	string str;
	while(scanf("%d",&n)!=EOF)
	{
		getchar();
		my.clear();
		int flag=0;//Either
		int dijilun=0;
		for(int i=0;i<n;i++)
		{
			getline(cin,str);


			int tem=++my[str];

			//tem 这首歌 第tem次出现   dijilun 现在是第几轮
			if(dijilun==tem||dijilun+1==tem)
			{}
			else
				flag=1;//只能radom


			dijilun=max(tem,dijilun);
		}
		for(map<string,int>::iterator it=my.begin();it!=my.end();it++)
        {
            if(dijilun-1>(it->second))
                flag=1;
        }
		if(flag)
		{
			puts("Random");

		}
		else
			puts("Either");
	}

	return 0;
}














你可能感兴趣的:(模拟,ACM)