FZU 2216 The Longest Straight 模拟
2016-04-05 20:42
591 查看
题目链接:The Longest Straight
就是一个模拟就是这样,T_T然而当时恶心的敲了好久,敲完就WA了,竟然有这么简单的方法,真是感动哭了.......xintengziji...zhishang...
模拟和暴力也都是有黑科技的..
附黑科技代码:
就是一个模拟就是这样,T_T然而当时恶心的敲了好久,敲完就WA了,竟然有这么简单的方法,真是感动哭了.......xintengziji...zhishang...
模拟和暴力也都是有黑科技的..
附黑科技代码:
#include<stdio.h> #include<queue> #include<iostream> #include<string.h> #include<algorithm> using namespace std; const int maxn = 100005; int vis[maxn]; int main() { int t; scanf("%d", &t); while (t--) { int n, m; std::queue<int> que; scanf("%d%d", &n, &m); memset(vis, 0, sizeof(vis)); for (int i = 0; i < n; ++i) { int a; scanf("%d", &a); vis[a]++; } int joker = vis[0]; int longest = 0; int nlenght = 0; for (int i = 1; i <= m; ++i) { // cout << i << "===\n"; if (vis[i] == 0) // 当前数字没有出现过 { if (que.size() < joker) // 还有0可用 { que.push(i); ++nlenght; } else if (!que.empty()) // 除了第一次遍历 保证所有的0在开始计数以前就已经用完了。 { int j = que.front(); que.pop(); que.push(i); nlenght = i - j; } else if (joker == 0) { // 这种情况只有在joker==0时会出现 nlenght = 0; } } else { ++nlenght; } longest = std::max(longest, nlenght); } printf("%d\n", longest); } return 0; }
相关文章推荐
- notifier chain — 内核通知链【转】
- UVA11374 Airport Express(SPFA求最短路)
- LeetCode-217&219&220.Contains Duplicate
- cf 345-B - Beautiful Paintings 暴力什么的太水了
- 172. Factorial Trailing Zeroes
- ZYJ_MainActivity
- WSP_mainActivity
- Main()方法
- adb连接时出现如下错误CreateProcess failure, error 2 * could not start server *
- UVa 507 - Jill Rides Again
- Xcode localization failed to read a strings file问题原因
- CMS GC时出现promotion failed跟concurrent mode failure
- 俄罗斯Mail.Ru云端部署视频的技术架构解析
- AIDL[1] 什么是AIDL?
- http://blog.csdn.net/emoven/article/details/12999265
- SDL2-2.0.4出现Could not initialize SDL : No available video device
- [LeetCode-70] Climbing Stairs
- How to use AIDL
- RAID 0 1 5 6 0+1
- POJ 3580 OpenJ_Bailian 4090 SuperMemo (伸展树模版)