LightOJ-1374 confusion in the Problemset (analog)

Source: Internet
Author: User
LightOJ-1374 confusion in the Problemset
Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld &%llu

Submit Status

Description

A small confusion in a problem set may ruin the whole contest. So, the very most of the problem setters try their best-to-remove any kind of ambiguity from the set. But sometimes it isn't that important. For example, the mock contest of ICPC Dhaka Regional. As it is a mock contest so we were not this serious with the set. We printed problems, problemAIn Page 1 and problemBIn Page 2. Then we remembered this we had to give rule of the contest too. Thus We printed the rule page. But we do not notice the rule page is printed with page 2. We were stapling 3 pages together. First rule page, then problemAAnd at the last problemB. So, the written page numbers were, 2, 1 and 2. This looked odd. But we already printed all the pages and if we are want to fix the issue we had no other-the-to-print all the three pages. One among us suggested an explanation, "well, first 2 means there is 2 pages after the this page. 1 also means there is 1 page after this page. But the 2 on last page means there is 2 pages before this page. " Interesting observation indeed! So we came up with a rule which are, page numberings of all theNPages is valid, if the page number at a page denotes number of page before this page or number of page after this page.

So with this rule, {3, 1, 2, 0} are valid but {3, 3, 1, 3} are not valid.

Input

Input starts with an integer T (≤60), denoting the number of test cases.

Each case starts with a line an integer n (1≤n≤10000) denoting the number of pages in the Problem-set. The next line contains n space separated integers denoting the page number written on the pages. The integers lie in the range [0, 106].

Output

For each case, print the case number and "yes" if the page can be shuffled somehow to meet the given restriction S. Otherwise print "No".

Sample Input

2

4

0 3 1 2

4

1 3 3 3

Sample Output

Case 1:yes

Case 2:no

Source problem setter:md. Mahbubul Hasan Special thanks:md. Towhidul Islam Talukder, Jane Alam Jan//test instructions: Enter an n, then enter n number a[ I] n number of inputs A[i] indicates that there are several numbers in front of this number, or there are several numbers behind the number. Idea: Record the number of each count, and then use a layer for the simulation of each position should be placed on the line

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream >
#define N 10010
using namespace std;
int a[n];
int main ()
{
	int t,t=1,n,m,i;
	scanf ("%d", &t);
	while (t--)
	{
		scanf ("%d", &n);
		memset (A,0,sizeof (a));
		for (i=0;i<n;i++)
		{
			scanf ("%d", &m);
			a[m]++;
		}
		int flag=0;
		for (i=1;i<=n;i++)
		{
			if (A[n-i])
				a[n-i]--;
			else if (a[i-1])
				a[i-1]--;
			else
			{
				flag=1;
				break;
			}
		}
		printf ("Case%d:", t++);
		if (flag)
			printf ("no\n");
		else
			printf ("yes\n");
	}
	return 0;
}


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.