zoukankan      html  css  js  c++  java
  • VK Cup 2016

    C. Promocodes with Mistakes

    题目连接:

    http://www.codeforces.com/contest/637/problem/C

    Description

    During a New Year special offer the "Sudislavl Bars" offered n promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all the promocodes differ.

    As the "Mosquito Shelter" opens only at 9, and partying in Sudislavl usually begins at as early as 6, many problems may arise as to how to type a promotional code without errors. It is necessary to calculate such maximum k, that the promotional code could be uniquely identified if it was typed with no more than k errors. At that, k = 0 means that the promotional codes must be entered exactly.

    A mistake in this problem should be considered as entering the wrong numbers. For example, value "123465" contains two errors relative to promocode "123456". Regardless of the number of errors the entered value consists of exactly six digits.

    Input

    The first line of the output contains number n (1 ≤ n ≤ 1000) — the number of promocodes.

    Each of the next n lines contains a single promocode, consisting of exactly 6 digits. It is guaranteed that all the promocodes are distinct. Promocodes can start from digit "0".

    Output

    Print the maximum k (naturally, not exceeding the length of the promocode), such that any promocode can be uniquely identified if it is typed with at most k mistakes.

    Sample Input

    2
    000000
    999999

    Sample Output

    2

    Hint

    题意

    给你n个只含有6个数字的串。

    然后现在他们规定了一个东西,如果这两个串只有小于等于k个位置不同,就认为是一样的。

    现在要你规定一个k,使得下列的n个串都必须视作不同。

    输出最大的k。

    题解:

    数据范围才1000,所以直接暴力就好了……

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    string s[1005];
    int main()
    {
        int n;scanf("%d",&n);
        int ans = 6;
        for(int i=0;i<n;i++)
            cin>>s[i];
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                int tmp = 0;
                for(int k=0;k<6;k++)
                    if(s[i][k]!=s[j][k])
                        tmp++;
                ans=min(ans,(tmp-1)/2);
            }
        }
        cout<<ans<<endl;
    }
  • 相关阅读:
    C++学习笔记----2.4 C++对象的内存模型
    C++学习笔记(2)---2.5 C++函数编译原理和成员函数的实现
    C++学习笔记(1)-构造函数与析构函数
    学习笔记(5)---数学运算
    学习笔记(4)---协方差和特征向量的意义
    学习笔记(3)---安装SVM问题及解决方法
    学习笔记(2)---Matlab 图像处理相关函数命令大全
    数据增删查改操作总结
    表操作总结
    touch命令修改时间
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5289932.html
Copyright © 2011-2022 走看看