题意:有n个有小写字母组成的字符串,将部分小写字母改成对应的大写字母,注意某种小写字母更改,所有的这种小写字母都会更改。若能使这给定的n个字符串符合字典序由小到大排序,则输出Yes,并输出需要修改的字母。定义所有的大写字母字典序小于小写字母。

分析:

1、起决定作用的是前后两个字符串中第一个不同的字母。每个字母要么小写要么大写,显然2-sat问题。

2、假设前后两个串中第一个不同的字母分别为a,b。

当a < b 时,只有a < B矛盾。则当a为小写时,b一定为小写。b为大写时,a一定为大写。由此建边。

当a  > b时,a > b, A > B, a > B,都矛盾,因此,若a为小写,修改为大写,若b为大写,修改为小写。由此建边。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 100000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
vector<int> v[MAXN], G[MAXN << 1], rG[MAXN << 1], vs;
bool used[MAXN << 1];
int cmp[MAXN << 1];
int n, m;
vector<int> ans;
void addedge(int from, int to){
G[from].push_back(to);
rG[to].push_back(from);
}
void dfs(int v){
used[v] = true;
for(int i = 0; i < G[v].size(); ++i){
if(!used[G[v][i]]) dfs(G[v][i]);
}
vs.push_back(v);
}
void rdfs(int v, int k){
used[v] = true;
cmp[v] = k;
for(int i = 0; i < rG[v].size(); ++i){
if(!used[rG[v][i]]) rdfs(rG[v][i], k);
}
}
void scc(){
memset(used, false, sizeof used);
vs.clear();
for(int v = 2; v <= (m << 1 | 1); ++v){
if(!used[v]) dfs(v);
}
memset(used, false, sizeof used);
int k = 0;
for(int i = vs.size() - 1; i >= 0; --i){
if(!used[vs[i]]) rdfs(vs[i], k++);
}
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 0; i < n; ++i){
int l, x;
scanf("%d", &l);
for(int j = 0; j < l; ++j){
scanf("%d", &x);
v[i].push_back(x);
}
}
for(int i = 1; i < n; ++i){
int id = -1;
int tmp = min(v[i - 1].size(), v[i].size());
for(int j = 0; j < tmp; ++j){
if(v[i - 1][j] != v[i][j]){
id = j;
break;
}
}
if(id == -1){
if(v[i - 1].size() > v[i].size()){
printf("No\n");
return 0;
}
}
else if(v[i - 1][id] < v[i][id]){
addedge(v[i - 1][id] << 1, v[i][id] << 1);
addedge(v[i][id] << 1 | 1, v[i - 1][id] << 1 | 1);
}
else{
addedge(v[i - 1][id] << 1, v[i - 1][id] << 1 | 1);
addedge(v[i][id] << 1 | 1, v[i][id] << 1);
}
}
scc();
for(int i = 2; i <= 2 * m; ++i){
if(cmp[i] == cmp[i + 1]){
printf("No\n");
return 0;
}
}
printf("Yes\n");
for(int i = 2; i <= 2 * m; i += 2){
if(cmp[i] < cmp[i + 1]){
ans.push_back(i >> 1);
}
}
int len = ans.size();
printf("%d\n", len);
if(len){
for(int i = 0; i < len; ++i){
if(i) printf(" ");
printf("%d", ans[i]);
}
printf("\n");
}
return 0;
}

  

CodeForces - 876E National Property(2-sat)的更多相关文章

  1. Codeforces 875C National Property(拓扑排序)

    题目链接  National Property 给定n个单词,字符集为m 现在我们可以把其中某些字母变成大写的.大写字母字典序大于小写字母. 问是否存在一种方案使得给定的n个单词字典序不下降. 首先判 ...

  2. Codeforces 876E National Property ——(2-SAT)

    在这题上不是标准的“a或b”这样的语句,因此需要进行一些转化来进行建边.同时在这题上点数较多,用lrj大白书上的做法会T,因此采用求强连通分量的方法来求解(对一个点,如果其拓扑序大于其为真的那个点,则 ...

  3. Codeforces 828B Black Square(简单题)

    Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n × m. ...

  4. 1114 Family Property (25 分)

    1114 Family Property (25 分) This time, you are supposed to help us collect the data for family-owned ...

  5. Codeforces C. Maximum Value(枚举二分)

    题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. 【刷题-PAT】A1114 Family Property (25 分)

    1114 Family Property (25 分) This time, you are supposed to help us collect the data for family-owned ...

  7. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) E. National Property(2-sat)

    E. National Property time limit per test 1 second memory limit per test 512 megabytes input standard ...

  8. CodeForces 215B Olympic Medal(数学啊)

    题目链接:http://codeforces.com/problemset/problem/215/B Description The World Programming Olympics Medal ...

  9. CodeForces 993B Open Communication(STL 模拟)

    https://codeforces.com/problemset/problem/993/b 这题不难,暴力就能过,主要是题意太难懂了 题意: 现在有两个人,每个人手中有一对数,第一个人手中的数是n ...

随机推荐

  1. el-dialog 如何自定义大小样式

    使用属性:custom-class 然后在css中根据这个类型编写指定的样式即可(比如宽高) 举例:

  2. win10的guard占内存过高

    转自:https://zhidao.baidu.com/question/1180883495203481459.html win10的guard占内存过高,

  3. cubic-bezier 个人学习理解

    cubic-bezier 三次贝塞尔曲线函数,是一种动画的速度曲线.根据动画设置的时间,速度相应变化 四个点 P0,P1,P2,P3,其中P0是起点,坐标(0,0),P3是终点,坐标(1,1) PI和 ...

  4. Struts配置文件报错"元素类型为 "package" 的内容必须匹配"

    报错信息 元素类型为 "package" 的内容必须匹配 "(result-types?,interceptors?,default-interceptor-ref?,d ...

  5. 吴裕雄--天生自然PythonDjangoWeb企业开发:解决ModuleNotFoundError: No module named 'config'报错

    使用创建完模块应用之后python manage.py startapp test_app,您应该进入settings.py并将其注册到

  6. day 10 作业

    # 2.写函数,接收n个数字,求这些参数数字的和. def sum_func(*args): total = 0 for i in args: total += i return total prin ...

  7. SpringBoot 获得 properties 文件中数据方式

    参考:https://blog.csdn.net/qq_37171353/article/details/78005845

  8. NB-IOT学习

    一 信号穿透力强,覆盖面广(基站少成本低).低功耗(eDRX/PSM省电技术).适合小流量时延要求不高(10s.) 二 主要芯片: 华为:Hi2110/2115,基于此的模组有:中移的M5310 移芯 ...

  9. docker基础镜像ubuntu添加jdk1.8

    首先pull ubuntu18.04 docker pull ubuntu:18.04 下载jdk1.8 jdk-8u191-linux-x64.tar.gz 创建Dockerfile文件 编写文件如 ...

  10. nacos 日志问题 ERR-CODE: [NACOS-0002], Type: [环境问题]

    nacos配置中心配置后,项目启动正常,运行项目也正常,但是总是打印如下日志: 2019-10-11 15:44:09.792 [com.alibaba.nacos.client.Worker.lon ...