CF858D Polycarp's phone book
题意翻译
有 n 个长度为 9 且只包含数字字符互不相同的串。
需要对于每个串找到一个长度最短的识别码,使得这个识别码当且仅当为这个串的子串。
题目分析
因为范围不是非常大,所以可以将子串筛出来
然后用STL统计即可
#include<bits/stdc++.h>
using namespace std;
int n;
string s[70005];
map<string,vector<int> >rec;
map<string,int >vis;
vector<string>cklfuck[70005];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
cin>>s[i];
vis.clear();
for(int j=0;j<s[i].size();j++)
{
string ckl;
for(int k=j;k<s[i].size();k++)
{
ckl+=s[i][k];
if(!vis[ckl])
{
vis[ckl]=1;
rec[ckl].push_back(i);
}
}
}
}
for(map<string,vector<int> >::iterator it=rec.begin();it!=rec.end();it++)
{
pair<string,vector<int> >pi=(*it);
vector<int>saeds=pi.second;
if(saeds.size()==1)
{
string sf=(*it).first;
vector<int>::iterator id=saeds.begin();
int key=*id;
cklfuck[key].push_back(sf);
}
}
for(int i=1;i<=n;i++)
{
int mini=0x3f3f3f3f;
int keyi;
for(int j=0;j<cklfuck[i].size();j++)
{
string cjg=cklfuck[i][j];
if(mini>cjg.size())
{
mini=cjg.size();
keyi=j;
}
// cout<<cklfuck[i][j];
// printf("\n");
}
cout<<cklfuck[i][keyi];
printf("\n");
}
}
CF858D Polycarp's phone book的更多相关文章
- cf723c Polycarp at the Radio
Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be re ...
- codeforces 723C : Polycarp at the Radio
Description Polycarp is a music editor at the radio station. He received a playlist for tomorrow, th ...
- Codeforces 723C. Polycarp at the Radio 模拟
C. Polycarp at the Radio time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...
- Codeforces Round #375 (Div. 2) C. Polycarp at the Radio 贪心
C. Polycarp at the Radio time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces Round #346 (Div. 2) F. Polycarp and Hay 并查集
题目链接: 题目 F. Polycarp and Hay time limit per test: 4 seconds memory limit per test: 512 megabytes inp ...
- Polycarp's problems
Polycarp's problems time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforce B. Polycarp and Letters
B. Polycarp and Letters time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- [Codeforces 864B]Polycarp and Letters
Description Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s con ...
- 贪心 C - Polycarp's New Job
Polycarp has recently got himself a new job. He now earns so much that his old wallet can't even sto ...
随机推荐
- Oracle存储过程游标for循环怎么写
一.不带参数的游标for循环 首先编写存储过程的整体结构,如下: create or replace procedure test_proc is v_date date; --变量定义 begin ...
- Unity——WegGL打包问题
Rendering设置 Gamma和Linear颜色空间,两者有色差,Gamma有个2.25左右的修正值: WebGL2.0可用的情况,只支持Deferred Render延迟渲染,且只支持Linea ...
- DevOps的分与合
一.抽象的 DevOps DevOps 是使软件开发和 IT 团队之间的流程自动化的一组实践,以便他们可以更快,更可靠地构建,测试和发布软件.DevOps 的概念建立在建立团队之间协作文化的基础上,这 ...
- pipeline groovy
目录 一.变量 一.变量 1.直接定义 def x="abc" 2.从脚本执行结果赋值变量 branch = "/jen_script/return-branch.sh ...
- Linux命令执行过程
目录 一.命令分类 二.命令执行顺序 三.命令分类及查找基本命令 四.命令执行过程 一.命令分类 Linux命令分为两类,具体为内部命令和外部命令 内部命令: 指shell内部集成的命令,此类命令无需 ...
- IO中同步异步,阻塞与非阻塞 -- 通俗篇
一.同步与异步 同步/异步, 它们是消息的通知机制 1. 概念解释 A. 同步 所谓同步,就是在发出一个功能调用时,在没有得到结果之前,该调用就不返回. 按照这个定义,其实绝大多数函数都是同步调用(例 ...
- vim 默认配置
vim ~/.vimrc 然后输入常用的需要用的命令,然后保存,这个每次启动VIM都会自动配置.当然你也可以在VIM里面按":"之后输入如下命令,但是下次启动之后设置就会丢失了. ...
- axios 高级封装
import axios from 'axios'; import qs from 'qs'; const Unit = { async getApi(ajaxCfg){ let data = awa ...
- JS判断是否为“YYYYMMDD”式的日期
function isDate8(sDate) { if (!/^[0-9]{8}$/.test(sDate)) { return false; } var year, month, day; yea ...
- 【LeetCode】320. Generalized Abbreviation 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS 日期 题目地址:https://leetcod ...