题目链接:The Longest Straight

就是一个模拟就是这样,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;
}

  

FZU 2216 The Longest Straight 模拟的更多相关文章

  1. FZU 2216——The Longest Straight——————【二分、枚举】

    Problem 2216 The Longest Straight Accept: 17    Submit: 39Time Limit: 1000 mSec    Memory Limit : 32 ...

  2. FZU 2216 The Longest Straight(最长直道)

    Description 题目描述 ZB is playing a card game where the goal is to make straights. Each card in the dec ...

  3. FZU 2216 The Longest Straight 二分

    0可以表示任何1到m的数,求一个最长的连续上升序列长度 因为m的范围在10w,所以以每个节点为起点 进行二分,复杂度mlogm 思路:b[i]表示到 1 到 i 有几个数没有出现,二分的时候注意加等号 ...

  4. The Longest Straight(二分,离散化)

     Problem 2216 The Longest Straight Accept: 7    Submit: 14 Time Limit: 1000 mSec    Memory Limit : 3 ...

  5. FZU-2216 The Longest Straight(尺取法)

     Problem 2216 The Longest Straight Accept: 523    Submit: 1663Time Limit: 1000 mSec    Memory Limit ...

  6. The Longest Straight(FZUoj2216)

     Problem 2216 The Longest Straight Accept: 82    Submit: 203Time Limit: 1000 mSec    Memory Limit : ...

  7. 福建省赛--Problem E The Longest Straight(标记+二分)

    Problem E The Longest Straight Accept: 71    Submit: 293 Time Limit: 1000 mSec    Memory Limit : 327 ...

  8. FZU 2032 Log函数问题 模拟小数加法

    题目链接:Log函数问题 2 / 49 Problem G FZU 2032 Log函数问题 不知道为什么...比赛时高精度难倒了一票人...成功搞出大新闻... 试了一下直接double相加超时,然 ...

  9. FZU 1078 计算循环冗余码【模拟】

    计算机网络中采用循环冗余码来校验数据的正确性.其原理是:发送方计算出待发送的二进制数据的循环冗余码,并随同原数据一起发送到接收方:接收方通过重新计算接收到的数据的循环冗余码,并和收到的循环冗余码进行比 ...

随机推荐

  1. T-SQL Apply的用法

    SQL Server 2005 新增 cross apply 和 outer apply 联接语句,增加这两个东东有啥作用呢? 我们知道有个 SQL Server 2000 中有个 cross joi ...

  2. bootstrap学习笔记<一>(bootstrap用法)

    首先引入bootstrap官网链接:http://www.bootcss.com/ bootstrap 3下载地址:http://v3.bootcss.com/getting-started/#dow ...

  3. linux2.6内核compat_ioctl函数

    一.内核原型(linux2.6.28-7) long (*compat_ioctl)(struct tty_struct *tty, struct file * file,               ...

  4. python操作postgresql数据库

    import psycopg2 conn = psycopg2.connect(database=") cur = conn.cursor() cur.execute("CREAT ...

  5. 认识Service

    Service相对于Activity可在后台运行,五显示界面,在activity退出的情况下仍能运行. 一.新建一个空的工程,命名为learnService 二.新建一个service,并添加如下所示 ...

  6. HashMap遍历

    package com.jackey.topic; import java.util.ArrayList;import java.util.HashMap;import java.util.Itera ...

  7. HTML介绍、文档基本结构、meta标签、HTML标记的语法

    一.HTML的介绍 Hyper Text Mark-up Language 超文本标记语言,是一种描述性标记语言(不是编程语言),主要用于描述网页(可以有图像,文字,声音,等..)但没有交互性 HTM ...

  8. java中的堆内存和栈内存

    Java把内存分成两种: 一种叫做栈内存 一种叫做堆内存 栈内存 : 在函数中定义的一些基本类型的变量和对象的引用变量都是在函数的栈内存中分配.当在一段代码块中定义一个变量时,java就在栈中为这个变 ...

  9. WebDriver 在使用 CSS Selector 与 XPath 在查找元素时如何取舍

    开发在做Web系统时,用的是css div划分层,使用jQuery 选取元素.

  10. 在cocos code ide的基础上构建自己的lua开发调试环境

    对于一种语言,其所谓开发调试环境, 大体有以下两方面的内容: 1.开发, 即代码编写, 主要是代码提示.补齐, 更高级一点的如变量名颜色等. 2.调试, 主要是运行状态下断点.查看变量.堆栈等. 现在 ...