题意:给定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. apache + DSO -动态共享对象(DSO)

    http://www.jinbuguo.com/apache/menu22/dso.html

  3. codeforces 892E(离散化+可撤销并查集)

    题意 给出一个n个点m条边的无向联通图(n,m<=5e5),有q(q<=5e5)个询问 每个询问询问一个边集{Ei},回答这些边能否在同一个最小生成树中 分析 要知道一个性质,就是权值不同 ...

  4. Java实验--课上提到的随机数生成原理简单实现(不利用库生成随机数的简单算法)

    对于随机数的实验,根据课程上的教程,有如下的公式: 对应的变量参数的说明: 其中对应的Mouduls变量对应的就是公式中a的值,在公式中的含义就是相当于要循环多少个数才重复的一个值. Multipli ...

  5. apache移植

    我下载的是httpd-2.2.9.tar.gz 1. 解压httpd-2.2.9.tar.gz到/mnt/apps目录下.tar -zxvf httpd-2.2.9.tar.gz 2. 建立与http ...

  6. Java生成验证码并进行验证(转)

    本文转自http://blog.csdn.net/worm0527/article/details/51030864 一.实现思路 使用BufferedImage用于在内存中存储生成的验证码图片 使用 ...

  7. 学习swift从青铜到王者之swift结构体和类08

    定义 // 定义类 class StudentC{ } // 定义结构体 struct StudentS{ } 定义存储属性 // 定义类 class StudentC{ var name:Strin ...

  8. CentOS 更改Apache默认网站目录

    http://www.osyunwei.com/archives/789.html引言:Apache默认的网站目录是在/var/www/html, 现在要把网站目录更改到/home/wwwroot/w ...

  9. BZOJ 1091([SCOI2003]分割多边形-分割直线)

    1091: [SCOI2003]分割多边形 Time Limit: 1 Sec  Memory Limit: 162 MB Submit: 223  Solved: 82 [Submit][id=10 ...

  10. linuxc线程信号-pthread_cond_wait理解

    pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t*mutex)函数 传入的參数mutex用于保护条件,由于我们在调用pthread_con ...