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 ...
随机推荐
- 在Eclipse中运行OSGI工程出错的解决方案
今天学习OSGI的过程中按照书上所述搭建好第一个helloworld插件工程,运行的过程中出现下面所示的错误: !SESSION 2014-06-09 21:04:49.038 ----------- ...
- 小程序的事件 bindtap bindinput
一.bindtap事件 在wxml文件里绑定: <view class='wel-list' bindtap='TZdown'> <image src="/images/w ...
- ICCV2021 | 简单有效的长尾视觉识别新方案:蒸馏自监督(SSD)
前言 本文提出了一种概念上简单但特别有效的长尾视觉识别的多阶段训练方案,称为蒸馏自监督(Self Supervision to Distillation, SSD).在三个长尾识别基准:Ima ...
- uWSGI和WSGI之间的关系
一.WSGI 协议 WSGI:是一种协议规范,起到规范参数的作用,就像告诉公路一样,规定超车靠右行,速度不低于90km/h,等.但这一切都是对双方进行沟通,比如,重庆到武汉这条高速路,这儿重庆和武汉就 ...
- Nginx配置FTP
目录 一.简介 二.配置 一.简介 ftp有单独的服务,但配置并不轻松.相对于比较熟悉的nginx,做ftp要容易很多. 二.配置 添加一个server字段 server { listen 8888; ...
- linux小应用 —— 日志过滤
先说问题,统计一个日志文件中去重之后的ip地址的个数.其实这是一个非常常见也比较简单的问题,其中我个人认为最主要的应该是匹配ip地址是这个问题的核心.剩下的就是对linux命令的熟练程度的问题了.首先 ...
- 前置任务(Project)
<Project2016 企业项目管理实践>张会斌 董方好 编著 在[前置任务列]中编辑任务关联,这是个正经的设置. 说他"正经",是因为在[手动模式]下,这个设置也是 ...
- CF390A Inna and Alarm Clock 题解
Content 平面内有 \(n\) 个整点 \((x_i,y_i)\).每次可以去掉一行或一列的点,问最少去几次(按行去点或按列去点二者只能选择一种). 数据范围:\(1\leqslant n\le ...
- LuoguB2101 计算矩阵边缘元素之和 题解
Content 给定一个 \(m\times n\) 的矩阵,求矩阵边缘元素之和. 数据范围:\(1\leqslant m,n\leqslant 100\). Solution 对于新手来说,看到这题 ...
- Linux(centos7)设置docker服务开机自启动以及容器自启动
docker服务开机自启动 systemctl enable docker 设置容器自启动 可以在运行的时候通过设置--restart 参数 docker run --restart always - ...