1374 - Confusion in the Problemset
Time Limit: 2 second(s) Memory Limit: 32 MB

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

Output for Sample Input

2

4

0 3 1 2

4

1 3 3 3

Case 1: yes

Case 2: no

Notes

  1. For case 1, the pages can be shuffled in several ways so that the page numbering is valid. One of the valid shuffles is 3, 1, 2, 0.
  2. For case 2, there is no valid way to shuffle these.

PROBLEM SETTER: MD. MAHBUBUL HASAN
SPECIAL THANKS: MD. TOWHIDUL ISLAM TALUKDER, JANE ALAM JAN
题意:n个数字,问能否把这些数字放在合适的位置,每个位置的数字有两种含义:他前面有a[i]个数字或者他后面有a[i]个数字;
思路:
先将给的数统计到数组中,然后重前到后扫一遍,因为两个位置是对称的,要么选i+1,要么选n-i-1;所以当前的为置这两种情况选那个都行。
 1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<stdlib.h>
6 #include<queue>
7 #include<set>
8 #include<vector>
9 #include<map>
10 using namespace std;
11 int ans[20000];
12 int flag[1000005];
13 int main(void)
14 {
15 int i,j,k;
16 int s;
17 scanf("%d",&k);
18 for(s=1; s<=k; s++)
19 {
20 int n,m;memset(flag,0,sizeof(flag));
21 scanf("%d",&n);
22 for(i=0; i<n; i++)
23 {
24 scanf("%d",&ans[i]);
25 flag[ans[i]]++;
26 }
27 int ask=0;
28 for(i=0;i<n;i++)
29 {
30 int q=i;
31 int p=n-i-1;
32 if(flag[q])
33 {
34 flag[q]--;
35 }
36 else if(flag[p])
37 {
38 flag[p]--;
39 }
40 else ask=1;
41 }
42 printf("Case %d: ",s);
43 if(ask)
44 printf("no\n");
45 else printf("yes\n");
46 }
47 return 0;
48 }

最新文章

  1. Visual Studio中安装viemu后,vim vax 快捷键大全
  2. Codeforces Round #389 Div.2 E. Santa Claus and Tangerines
  3. mssql的日期函数,如何取得当前年月日,当前时间,当前月份,当前天数,一年中第几天?
  4. ACM训练场
  5. python一个注意的地方
  6. MySQL Date 函数
  7. 新版本 JSAPI微信支付V3 C# DEMO
  8. Discuz 5.x/6.x/7.x投票SQL注入分析
  9. Codeforces Round #333 (Div. 2) B. Approximating a Constant Range st 二分
  10. C# FileStream复制大文件
  11. centos nginx
  12. Android MVC MVP
  13. httpd页面用户访问认证控制
  14. Sqlite数据库添加数据以及查询数据方法
  15. 【转】How to append current date and timestamp to filename in shell script
  16. SpringBoot,Security4, redis共享session,分布式SESSION并发控制,同账号只能登录一次
  17. Vlan ---虚拟局域网
  18. DataTable数据存储问题
  19. 利用正则表达式实现python强口令检测
  20. [CXF REST标准实战系列] 一、JAXB xml与javaBean的转换

热门文章

  1. js获取中国省市区,省市筛选、省市、省市筛选联动。【C#】【js】
  2. springcloud - alibaba快速上手 - 更新完毕
  3. 分类模型性能的评判方法-ROC分析
  4. MediaPlayer详解
  5. 【Python】【Basic】【数据类型】基本数据类型
  6. CentOS6设置Django开发环境
  7. matplotlib 画图中图和次坐标轴
  8. 【C/C++】习题3-3 数数字/算法竞赛入门经典/数组和字符串
  9. 06 - Vue3 UI Framework - Dialog 组件
  10. pipeline是什么?