lightoj 1374 Confusion in the Problemset
来源:互联网 发布:无人机航线规划算法 编辑:程序博客网 时间:2024/06/10 08:09
题目就是说有n页纸,有n个页码,由于存在某些问题导致页码和平时的不一样,这里每页的页码指的是这页前面或者后面还有多少页,问给定的这些页码是否可以排列出来满足上面条件的序列。主意的是页码的范围是<=10^6,n <= 10000。
ps:开始想错了,一位需要将大于n或者小于0的数进行hash,结果wa了三发没懂为啥,,,太蠢了,题目没懂
点击打开题目链接
/*****************************************Author :Crazy_AC(JamesQi)Time :2015File 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_backtypedef 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;}
0 0
- lightoj 1374 Confusion in the Problemset
- lightoj 1374 - Confusion in the Problemset 贪心
- LightOJ - 1374 Confusion in the Problemset (模拟)
- UVALive 5963 Confusion in the Problem Set 思维题、Interesting
- Confusion in Java 1
- Confusion in Java 2
- UVALive 5963 (LA 5963) Confusion in the Problem Set 二分图匹配 (或 YY)
- To avoid user confusion, app version updates must utilize the iOS built-in update mechanism.
- LightOJ 1216 Juice in the Glass
- Confusion
- confusion
- Nt vs. Zw - Clearing Confusion On The Native API
- End-User Microsoft BI Tools – Clearing up the confusion
- Circle in Square LightOJ
- lightOJ 1382 The Queue
- CodeForces Round #202 (Div. 2) / ProblemSet 349B - B. Color the Fence 【贪心】
- LightOJ 1022 Circle in Square
- LightOj 1334 - Genes in DNA
- Java中的BIO、NIO、AIO(NIO2)
- elasticsearch评分进阶
- 【codeforces 111C】 Petya and Spiders
- 【bzoj1560】【jsoi2009】【火星藏宝图】【dp】
- android中的回调
- lightoj 1374 Confusion in the Problemset
- leetcode笔记:Find Median from Data Stream
- Leetcode236: Interleaving String
- iOS程序员从小白到大神必读资料汇总(一)
- 详细整理:UITableView优化技巧
- Linux read / write详解
- 2016年想创业?这十五家投资机构今年最看好什么?
- 清除缓存
- XML入门