您的位置:首页 > 其它

lightoj 1374 Confusion in the Problemset

2016-01-14 21:49 381 查看
题目就是说有n页纸,有n个页码,由于存在某些问题导致页码和平时的不一样,这里每页的页码指的是这页前面或者后面还有多少页,问给定的这些页码是否可以排列出来满足上面条件的序列。主意的是页码的范围是<=10^6,n <= 10000。

ps:开始想错了,一位需要将大于n或者小于0的数进行hash,结果wa了三发没懂为啥,,,太蠢了,题目没懂

点击打开题目链接

/*****************************************
Author      :Crazy_AC(JamesQi)
Time        :2015
File Name   :
*****************************************/
// #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <climits>
using namespace std;
#define MEM(x,y) memset(x, y,sizeof x)
#define pk push_back
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> ii;
const double eps = 1e-10;
const int inf = 1 << 30;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 10010;
int A[maxn];
int t,icase = 0;
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
memset(A, 0,sizeof A);
int x;
for (int i = 1;i <= n;++i){
scanf("%d",&x);
if (x > n || x < 0) continue;
A[x] += 1;
}
bool flag = true;
for (int i = 1;i <= n;++i){
int first = i - 1;//指示前面有first页
int second = n - i;//指示后面有second页
if (A[first] > 0){
A[first]--;
}else if (A[second] > 0){
A[second]--;
}
else{
flag = false;
break;
}
}
printf("Case %d: ", ++icase);
if (flag) printf("yes\n");
else printf("no\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: