Codeforces 861D - Polycarp's phone book

861D - Polycarp‘s phone book

思路:用map做的话,只能出现一次循环,否则会超时。

代码:

#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
map<string,int> ma;
string ans[70005];
int main(){
    int n;
    string s,nu;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        ans[i+1] = "";
        for(int j=0;j<9;j++){
            nu = "";
            for(int k=j;k<9;k++){
                nu += s[k];
                if(ma[nu] && ma[nu]!=i+1) ma[nu]=-1;
                else ma[nu] = i+1;
            }
        }
    }
    for(auto it : ma){
        if(it.s!=-1)
            if(ans[it.s]=="" || ans[it.s].size()>it.f.size() )
                ans[it.s] = it.f;
    }
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<endl;
    return 0;
}

Codeforces 861D - Polycarp's phone book

时间: 2024-10-10 04:10:51

Codeforces 861D - Polycarp's phone book的相关文章

CodeForces 1005D Polycarp and Div 3(思维、贪心、dp)

http://codeforces.com/problemset/problem/1005/D  题意: 给一个仅包含数字的字符串,将字符串分割成多个片段(无前导0),求这些片段里最多有多少是3的倍数 思路一(贪心): from:https://blog.csdn.net/islittlehappy/article/details/81006849 一个数是3的倍数,则各位的和能被3整除. 对于单独的一个数字,如果是3的倍数,则ans++ 否则,考虑连续的两个数字,如果是,则ans++ 如果第三

CodeForces 723C Polycarp at the Radio (题意题+暴力)

题意:给定 n 个数,让把某一些变成 1-m之间的数,要改变最少,使得1-m中每个数中出现次数最少的尽量大. 析:这个题差不多读了一个小时吧,实在看不懂什么意思,其实并不难,直接暴力就好,n m不大.很明显最后1-m中次数最长的应该是n/m, 所以我们把大于n/m的都变成小于等于的,把这 n 个数中大于 m 的也变成,但是并不需要都变,只要满足每个数都是大于等于n/m就好了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000&

CodeForces 723C Polycarp at the Radio

构造. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #incl

CodeForces 659F Polycarp and Hay

#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include&

CodeForces - 864B Polycarp and Letters

题意:已知长度为n的字符串,求最大的位置集合,使集合内的每个位置所对应的都是小写字母且各不相同,而且相邻位置间无大写字母. #include<bits/stdc++.h> #define Min(a, b) ((a < b) ? a : b) #define Max(a, b) ((a < b) ? b : a) typedef long long LL; typedef unsigned long long ULL; const int INT_INF = 0x3f3f3f3f;

Codeforces VK Cup 2015 Wild Card Round 1 (AB)

比赛链接:http://codeforces.com/contest/522 A. Reposts time limit per test:1 second memory limit per test:256 megabytes One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started

Codeforces Round #434 (Div. 2)

Codeforces Round #434 (Div. 2) codeforces 858A. k-rounding[水] 题意:已知n和k,求n的最小倍数x,要求x后缀至少有k个0. 题解:答案就是10^k和n的最小公倍数. 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<cmath> 5 using namespace std; 6 typedef long

Codeforces Round #568 (Div. 2)B

B. Email from Polycarp 题目链接:http://codeforces.com/contest/1185/problem/B 题目: Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more

B - Email from Polycarp

Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one sy