题意:给定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. Codevs 3409 搬礼物

    时间限制: 1 s 空间限制: 64000 KB 题目等级 : 青铜 Bronze   题目描述 Description 小浣熊松松特别喜欢交朋友,今年松松生日,就有N个朋友给他送礼物.可是要把这些礼 ...

  2. BZOJ1693: [Usaco2007 Demo]Asteroids

    n<=500 *n的格子,给m<=10000个格子有人,一炮可以清掉一行或一列的人(莫名的爽!)求最少几炮干掉所有人. 经典二分图模型!行成点,列成点,一个点就连接一行一列,表示这一行或这 ...

  3. linux 安装报错:pkg-config not found

    linux 安装报错:pkg-config not found 使用编译安装时,在执行./configure时报如下错误: ... ... checking for pkg-config... no ...

  4. Python()- 面向对象三大特性----封装

    封装: [封装]         隐藏对象的属性和实现细节,仅对外提供公共访问方式.[好处] 1. 将变化隔离: 2. 便于使用:3. 提高复用性: 4. 提高安全性:[封装原则]      1. 将 ...

  5. 寒武纪camp Day4

    补题进度:7/11 A(博弈论) 略 B 待填坑 C(贪心) 题意: 一个序列是good的当且仅当相邻两个数字不相同.给出一个长度为n的数列,每个数字是ai.定义一种操作就是把a中某个元素拿到首位去, ...

  6. 如何使用eclipse for c/c++ 配置环境编写第一个C程序

    因为VS太大还要安装太多的插件,,,所以想用eclipse编写C语言... 1.下载eclipse for c/c++版本  去官网即可下载   https://www.eclipse.org/dow ...

  7. http 连接失败重连机制

    1.我们做web开发时,需要经常使用httpclient来请求http服务,有时为了安全起见,服务提供方会提供多个http地址,这样如果我们请求某个ip出现异常,可以重试其他的ip地址,来尽量保证系统 ...

  8. 将oracle10g 升级至10.2.0.4

    http://blog.csdn.net/launch_225/article/details/7221489 一.单实例环境,全时长一个半钟多. 详细图文说明到这下载 1.停止所有oracle相关进 ...

  9. HNU 12834 Thread Tree

    递归输出即可了 #include<bits/stdc++.h> using namespace std; struct tree{     int dot;     string s; } ...

  10. Direct Buffer vs. Heap Buffer

    1. 劣势:创建和释放Direct Buffer的代价比Heap Buffer得要高. 2. 差别:Direct Buffer不是分配在堆上的,它不被GC直接管理(但Direct Buffer的JAV ...