CodeForces 730H Delete Them (暴力)

题意:给定n个名字,然后让你删除 m 个,且这m个必须满足同一个表达式且其他的不满足,问你能不能找到一个满足条件。

析:很明显首先知道的是这 m 个如果第 i 个位置相同,那么就肯定选这个位置是最好的,如果第 i 个位置不同,那么就一定是 ?,最后再判断,除了m其他的是不是也满足这个式子就好。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e2 + 100;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline int gcd(int a, int b){ return b ? gcd(b, a%b) : a; }
inline int lcm(int a, int b){ return a * b / gcd(a, b); }
inline bool is_in(int r, int c){
    return r >= 0 && r < n && c >= 0 && c < m;
}
vector<string> v;
bool a[105];

int main(){
    while(scanf("%d %d", &n, &m) == 2){
        v.clear();
        string s;
        for(int i = 0; i < n; ++i){
            cin >> s;
            v.push_back(s);
        }
        memset(a, false, sizeof a);
        vector<string> vv;
        for(int i = 0; i < m; ++i){
            int x;
            cin >> x;
            a[x-1] = true;
            vv.push_back(v[x-1]);
        }
        bool ok = true;
        for(int i = 1; i < m; ++i)  if(vv[i].size() != vv[i-1].size()){
            ok = false;
            break;
        }
        if(!ok){  puts("No");  continue; }
        string ans;
        for(int i = 0; i < vv[0].size(); ++i){
            bool is = true;
            for(int j = 1; j < m; ++j){
                if(vv[0][i] != vv[j][i]){ is = false;  break; }
            }
            string s(1, vv[0][i]);
            ans += is ? s : "?";
        }
        for(int i = 0; i < n; ++i){
            if(v[i].size() != ans.size() || a[i])  continue;
            bool is = true;
            for(int j = 0; j < ans.size(); ++j){
                if(ans[j] != '?' && ans[j] != v[i][j]){ is = false;  break; }
            }
            if(is){ ok = false;  break; }
        }
        if(!ok){  puts("No");  continue; }
        puts("Yes");
        cout << ans << endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/dwtfukgv/p/5998312.html