P1063 数字串
2016-03-22 22:52
274 查看
本以为要动规什么的,结果居然是一边录,一边算
也许,也许…….
当然,因为没有
出现了wa
哼哼,这次我可是开足了空间
代码如下
也许,也许…….
当然,因为没有
if (answer!=n) { cout << answer << endl; } else { cout << "NO" << endl; }
出现了wa
哼哼,这次我可是开足了空间
代码如下
// 13_P1063 数字串.cpp : 定义控制台应用程序的入口点。
//
/*
P1063 数字串
时间: 1000ms / 空间: 131072KiB / Java类名: Main
描述
给你一个长度为n的数字串,数字串里会包含1-m这些数字。如果连续的一段数字子串包含了1-m这些数字,则称这个数字字串为NUM串。
你的任务是求出长度最短的NUM串是什么,只需要输出这个长度即可。
1<=n,m<=200000
输入格式
第一行给定n和m。
第二行n个数,表示数字串,数字间用空格隔开。
输出格式
如果存在NUM串则输出最短NUM串长度,否则输出“NO”。
测试样例1
输入
5 3
1 2 2 3 1
输出
3
*/
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
int n, m;
int a[2000000], b[2000000];
void print(int *c)
{
for (int i = 0; i < n; i++)
{
cout << setw(5) << c[i];
if (i%5==4)
{
cout << endl;
}
}
cout << endl;
}
int main()
{
int begin, end;
begin = 0;
end = 0;
int num = 0;
cin >> n >> m;
int answer = n;
for (int i = 0; i < n; i++)
{
cin >> a[i];
if (b[ a[i]-1 ]==0)
{
num++;
}
b[a[i]
4000
-1]++;
end++;
while(b[ a[begin]-1 ]>1)
{
//cout <<"b a"<< b[a[begin] - 1] << " " << a[begin] - 1 << endl;
b[a[begin]-1]--;
begin++;
//cout << b[a[begin] - 1] << endl;
//print(b);
}
if (num == m)
{
answer = min(answer, end - begin);
//cout << end << " " << begin << " " << end - begin << endl;
}
}if (answer!=n) { cout << answer << endl; } else { cout << "NO" << endl; }
return 0;
}
相关文章推荐
- MMDrawerController 与 StoryBoard 构建和谐抽屉效果
- birt报表与现有系统的集成
- 价值评价系统的由来
- 微信企业号开发(八) -jssdk的使用(调用微信拍照)
- hdu1205吃糖果(鸽巢原理)
- 学习笔记
- 第六十天
- 我原来还在这
- [android] 显示意图激活另外一个activity
- 表格table
- js获取某个div的style
- Js版带表盘的时钟
- C语言的一个语法糖
- wordpress建站日记(一)
- 操作系统模仿CMD
- angular-Scope
- 计算机 ——点右键——〉管理——windows找不到文件
- linux中的awk的详解
- 第4周项目5编程序
- [Set]——逻辑梳理