Problem F. Wiki with String
Input file: standard input Time limit: 1 second
Output file: standard output Memory limit: 256 megabytes
现在有一个字符串s, s中只包含数字字符0-9,现在需要输出一个子字符串k满足以下条件:
条件1: k包含0-9中所有的数字字符;
条件2:在所有符合要求的子字符串中, k的长度最小;
条件3:如果存在多个满足条件1和条件2的子字符串,请输出字典序最小的那个子字符串。
Input
输入一个字符串s,且s的长度不大于106
Output
输出符合要求的子字符串k;如果不存在符合要求的子字符串,请输出-1
Samples

standard input standard output
00123489765 0123489765
1234567890123456789 0123456789
123456789123 -1

思路:采用双指针和贪心的思想,利用set判断当前的子字符串是否符合条件

第一个指针从前到后扫描一遍,第二个指针贪心的往前移动

 #include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_set> using namespace std ; unordered_set<char> us ;
string s ;
int cnt[] ; int main(){ cin >> s ; int la = s.size(),l=,flag = 0x3f3f3f3f ;
int idx = ;
string tmp,ans ;
for(int i=;i<la;i++){
us.insert(s[i]) ;
cnt[s[i]-''] ++ ;
while(cnt[s[l]-'']>){//如果当前的子字符串内存在重复字符,贪心的让l++,因为新子字符串的长度一定比原子字符串的长度来的短
cnt[s[l]-''] -- ;
l++ ;
}
if(us.size() == ){
if(i-l+<flag){
flag = i-l+ ;
ans = s.substr(l,i-l+) ;
}else if(flag == i-l+){
tmp = s.substr(l,i-l+) ;
if(tmp<ans){
ans = tmp ;
}
}
idx ++ ;
}
}
if(idx){
cout << ans << endl ;
}else{
cout << - << endl ;
} return ; }

...

Problem F. Wiki with String的更多相关文章

  1. 实验12:Problem F: 求平均年龄

    Home Web Board ProblemSet Standing Status Statistics   Problem F: 求平均年龄 Problem F: 求平均年龄 Time Limit: ...

  2. The Ninth Hunan Collegiate Programming Contest (2013) Problem F

    Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...

  3. Codeforces Gym 100002 Problem F "Folding" 区间DP

    Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...

  4. Codeforces Gym 100286F Problem F. Fibonacci System 数位DP

    Problem F. Fibonacci SystemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...

  5. Problem F: Exponentiation

    Problem F: ExponentiationTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 4 Solved: 2[Submit][Status][W ...

  6. Problem F: 合唱比赛开始了!

    Problem F: 合唱比赛开始了! Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 440  Solved: 201[Submit][Status][ ...

  7. 几何入门合集 gym101968 problem F. Mirror + gym102082 Problem F Fair Chocolate-Cutting + gym101915 problem B. Ali and Wi-Fi

    abstract: V const & a 加速 F. Mirror 题意 链接 问题: 有n个人在y=0的平面上(及xoz平面).z=0平面上有一面镜子(边平行于坐标轴).z=a平面上有q个 ...

  8. Problem F Plug It In!

    题目链接:https://cn.vjudge.net/contest/245468#problem/F 大意:给你插座和电器的对应关系,有多个电器对应一个插座的情况,但是一个插座只能供一个电器使用,现 ...

  9. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem F. Matrix Game

    题目: Problem F. Matrix GameInput file: standard inputOutput file: standard inputTime limit: 1 secondM ...

随机推荐

  1. Delphi RSA加解密【 (RSA公钥加密,私钥解密)、(RSA私钥加密,公钥解密)、MD5加密、SHA加密】

    作者QQ:(648437169) 点击下载➨delphi RSA加解密 [Delphi RSA加解密]支持 (RSA公钥加密,私钥解密).(RSA私钥加密,公钥解密).MD5加密.SHA1加密.SHA ...

  2. angular复习笔记3-组件

    组件Component 组件是构成angular应用的核心,angular的有序运行依赖于组件的协同工作,组件之于angular应用就像是汽车和汽车零部件的意思. 概述 近几年的前端发展迅速,各种工程 ...

  3. dump net core lldb 安装

    原文https://www.cnblogs.com/calvinK/p/9263696.html centos7下安装lldb,dotnet netcore 进程生成转储文件,并使用lldb进行分析 ...

  4. centos7安装face_recognition踩各种坑

    要在阿里云服务器上部署face_recognition.用的是centos7.  千辛万苦啊.感谢网上的各种解答.回报社会,我也把各种坑写下了.整理的有点乱.不过仔细看,有干货的. 感谢这个博主Fat ...

  5. 全网最easy的better-scroll实现上拉加载和下拉刷新

    前言 移动端页面常见的一种效果:下拉刷新(pulldownrefresh)和上拉加载(pullupload),目的都是为了增强用户的体验效果,因此各种移动端滑动插件也是层出不穷,今天小编也在这里给大家 ...

  6. Linux添加硬盘创建新的逻辑卷方式

    有同仁看了上文<Linux添加硬盘扩充已有分区存储空间方式>一文后,提出疑问,现在很多云服务器本来没有逻辑卷,添加数据盘后需要自行添加,如何处理? 此文将以某云服务器为例,详细进行解说. ...

  7. mysql 设置查看字符集

    MySQL查看和修改字符集的方法   一.查看字符集 1.查看MYSQL数据库服务器和数据库字符集 方法一:show variables like '%character%';方法二:show var ...

  8. .NET Framework 项目多环境下配置文件web.config

    解决jenkins自动构建发布的问题,统一从git/svn库中获取项目文件,根据不同配置编译发布到多个运行环境中. 转自:https://www.cnblogs.com/hugogoos/p/6426 ...

  9. GNS3、Wireshark、SecureCRT 环境部署

    本次GNS3环境部署教程基于官方推荐的稳定版1.5.4.初次接触此软件,详细的使用方法不是很清楚,所以以此作为学习记录,仅供参考,后期补充. 软件介绍 GNS3 GNS3是一款具有图形化界面可以运行在 ...

  10. cadvisor应用

    cadvisor主页:https://github.com/google/cadvisor 容器主页:https://hub.docker.com/r/google/cadvisor cAdvisor ...