LightOJ - 1374 Confusion in the Problemset (模拟)

39 篇文章 0 订阅
LightOJ - 1374
Time Limit: 2000MSMemory Limit: 32768KB64bit IO Format: %lld & %llu

Submit Status

Description

A small confusion in a problem set may ruin the whole contest. So, most of the problem setters try their best to remove any kind of ambiguity from the set. But sometimes it is not that important. For example, the mock contest of ICPC Dhaka Regional. As it is mock contest so we are not that serious with the set. We printed two problems, problem A in Page 1 and Problem B in Page 2. Then we remembered that we had to give rule of the contest too. Thus we printed the rule page. But we did not notice that the rule page was printed with Page 2. We were stapling 3 pages together. First rule page, then Problem A and at the last Problem B. So, the written page numbers were, 2, 1 and 2. This looked odd. But we already printed all the pages and if we want to fix the issue we had no other way but to print all the three pages. One among us suggested an explanation, "Well, first 2 means there are 2 pages after this page. 1 also means there is 1 page after this page. But the 2 in last page means there are 2 pages before this page." Interesting observation indeed! So we came up with a rule which is, page numberings of all the n pages are 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} is valid but {3, 3, 1, 3} is 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 pages can be shuffled somehow to meet the given restrictions. 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
//题意:输入一个n,接下来输入n个数a[i]
输入的n个数a[i]表示在这个数前面有几个数或者是在这个数后面有几个数。
//思路:
将每个数的个数记录一下,再用一层for模拟每个位置应该放的数就行了

#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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值