题意:给定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;
}

CodeForces 730H Delete Them (暴力)的更多相关文章

  1. 【CodeForces 730H】Delete Them

    BUPT 2017 summer training (for 16) #1E 题意 找到匹配要删除的文件名们但不匹配其它文件名们的表达式.其中?匹配所有字符,其它字符匹配本身. 题解 如果某个位置出现 ...

  2. codeforces 724B Batch Sort(暴力-列交换一次每行交换一次)

    题目链接:http://codeforces.com/problemset/problem/724/B 题目大意: 给出N*M矩阵,对于该矩阵有两种操作: (保证,每行输入的数是 1-m 之间的数且不 ...

  3. codeforces 897A Scarborough Fair 暴力签到

    codeforces 897A Scarborough Fair 题目链接: http://codeforces.com/problemset/problem/897/A 思路: 暴力大法好 代码: ...

  4. Codeforces A. Playlist(暴力剪枝)

    题目描述: Playlist time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  5. [codeforces 200 A Cinema]暴力,优化

    题意大致是这样的:有一个有n行.每行m个格子的矩形,每次往指定格子里填石子,如果指定格子里已经填过了,则找到与其曼哈顿距离最小的格子,然后填进去,有多个的时候依次按x.y从小到大排序然后取最小的.输出 ...

  6. Codeforces Gym 100531D Digits 暴力

    Problem D. Digits 题目连接: http://codeforces.com/gym/100531/attachments Description Little Petya likes ...

  7. CodeForces 589B Layer Cake (暴力)

    题意:给定 n 个矩形是a*b的,问你把每一块都分成一样的,然后全放一块,高度都是1,体积最大是多少. 析:这个题,当时并没有完全读懂题意,而且也不怎么会做,没想到就是一个暴力,先排序,先从大的开始选 ...

  8. Codeforces Gym 100418K Cards 暴力打表

    CardsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action? ...

  9. Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861A k-rounding【暴力】

    A. k-rounding time limit per test:1 second memory limit per test:256 megabytes input:standard input ...

随机推荐

  1. 只有代码不会撒谎,如何通过Spring boot源码查看其对于各个框架的默认配置

    我发现很多开发对于看源码都有种恐惧心理,其实不必这样,大部分优秀的源码写的都挺直观的,很多时候,你在搜索引擎上搜到的一些东西并不一定是对的,但源码肯定造不了假,毕竟不管你怎么想,它就在那里,该是什么意 ...

  2. Codeforces917C. Pollywog

    $n \leq 1e8$个石头,$x \leq 8$个蝌蚪一开始在最左边$x$个石子,要跳到最右的$x$个,每次只能最左边的蝌蚪跳一次,一个石头不能站两个蝌蚪,跳可以跳$1到k,x \leq k \l ...

  3. BZOJ4580: [Usaco2016 Open]248

    n<=248个数字,可以进行这样的操作:将相邻两个相同的数字合并成这个数字+1,求最大能合成多少. f(i,j)--区间i到j能合成的最大值,f(i,j)=max(f(i,k)+1),f(i,k ...

  4. Xcode 全局搜索失效的问题

    早上手一快不知点了什么,然后全局搜索的功能就不起作用了.百度了一下才知道,原来把搜索范围给改了,改回来如下:

  5. 通过XMLHttpRequest,ActiveXObject实现ajax请求

    今天学习了原生的ajax请求.我将涉及到的ajax请求方法封装成了一个对象: var xhr={     getXHR:function(){         var XHR = null;      ...

  6. POJ 1502 水 dij

    题意:给N,表示N个节点. 给半个邻接矩阵,本身到本身的距离是0,边是双向的.当两个节点之间没有直接的边连接的时候,用x表示. 问从第一个节点到其他所有节点至少花费的时间. 这题唯一的处理是处理邻接矩 ...

  7. Spring实战Day1

    为什么要学习使用Spring ------为了全方面简化Java开发 如何简化开发呢? 1.基于POJO[简单老式Java对象(Plain Old Java object)]的轻量级和最小侵入性编程, ...

  8. powerDigner使用

    PowerDesigner是一款功能非常强大的建模工具软件,足以与Rose比肩,同样是当今最著名的建模软件之一.Rose是专攻UML对象模型的建模工具,之后才向数据库建模发展,而PowerDesign ...

  9. openstack swift middleware开发

    首先MiddleWare核心代码,这段代码卸载swift的源代码目录下,~/swift/swift/common/middleware下新建deletionpreventing.py: import ...

  10. CentOS 6.X配置 NFS以及启动和mount挂载

    一.环境介绍: 服务器:centos 192.168.1.225 客户端:centos 192.168.1.226 二.安装: NFS的安装配置:centos 5 : yum -y install n ...