虽然是xjbg的题目,但是并不很好做。

  题意不难理解。读入有点麻烦。做法是先正着推每段对话的?可能是谁说的,然后反过来选择即可。正推时,其中vis数组表示谁已经被用过了,cnt表示该组当前可以选择几个,choose[i][j]表示第i段对话中,选择第j个名字作为说话者是不是可能的。

  那么正推时就不难理解了,首先要这个名字没出现在他说的话中,然后1.这是第一段话,2.前一段对话中这个名字不是被选择作为说话者的,3.前一段对话选了好几个(因此我可以选择这个名字作为说话者而不重复,因为前一段对话可以选另外一个名字)。这三个条件任意一个满足即可。

  然后反过来选择时,从最后一个开始,选择其可行的,当前这段对话这个名字是作为说话者了以后,前一段对话显然这个名字不能再作为说话者,因此需要更新choose数组。然后就写完了。(没有什么算法,但是也不好写。。)

  具体见代码:

 #include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;
const int N = + ; int cnt[N];
int choose[N][N];
int vis[N];
string name[N];
string ss[N]; bool isok(char c)
{
if(c>='' && c<='') return ;
if(c>='a' && c<='z') return ;
if(c>='A' && c<='Z') return ;
return ;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(cnt,,sizeof(cnt));
memset(choose,,sizeof(choose));
map<string, int> M;
int n;scanf("%d",&n);
char s[];
for(int i=;i<=n;i++)
{
scanf(" %s",s);
string str = (string)s;
M[str] = i;
name[i] = str;
}
int m;scanf("%d",&m);getchar();
int k = ;
for(int i=;i<=m;i++)
{
int flag = ;
memset(vis,,sizeof(vis));
string str = "";
string now = "";
getline(cin, str);
ss[i] = str;
int sz = str.length();
for(int j=;j<sz;j++)
{
if(isok(str[j]))
{
now = now + str[j];
}
else if(now != "")
{
if(str[] != '?')
{
cnt[i] = ;
choose[i][M[now]] = ;
j = sz;
flag = ;
}
else
{
if(M[now] != )
{
vis[M[now]] = ;
}
now = "";
}
}
}
if(now != "" && M[now] != ) vis[M[now]] = ;
if(flag) continue;
int t = ;
for(int j=;j<=n;j++)
{
if(!vis[j] && (i== || cnt[i-] > || !choose[i-][j]))
{
choose[i][j] = ;
cnt[i]++;
t = ;
}
}
k = k || t;
} if(k) {puts("Impossible");continue;}
vector<string> ans;
for(int i=m;i>=;i--)
{
ss[i].erase(, ss[i].find(':'));
for(int j=;j<=n;j++)
{
if(choose[i][j])
{
if(i > ) choose[i-][j] = ;
ans.push_back(name[j] + ss[i]);
break;
}
}
}
if(ans.size() != m) {puts("Impossible");continue;}
for(int i=ans.size()-;i>=;i--) cout << ans[i] << endl;
}
return ;
}

CodeForces 754C Vladik and chat ——(xjbg)的更多相关文章

  1. Codeforces Round #390 (Div. 2) C. Vladik and chat(dp)

    http://codeforces.com/contest/754/problem/C C. Vladik and chat time limit per test 2 seconds memory ...

  2. CodeForces 755D PolandBall and Polygon ——(xjbg)

    每次连线,起点和终点之间,每一个被点亮的点,这些点都能连出去两条线,因此可以增加的块数+2(1这个点除外,因为只有连出的点没有连进的点),计算起点和终点之间有几个点被点亮即可,然后1这个点特判一下.感 ...

  3. CodeForces 754C Vladik and chat (DP+暴力)

    题意:给定n个人的m个对话,问能不能找一个方式使得满足,上下楼层人名不同,并且自己不提及自己. 析:首先预处理每一层能有多少个user可选,dp[i][j] 表示第 i 层是不是可以选第 j 个use ...

  4. Codeforces Round #219 (Div. 1)(完全)

    戳我看题目 A:给你n个数,要求尽可能多的找出匹配,如果两个数匹配,则ai*2 <= aj 排序,从中间切断,分成相等的两半后,对于较大的那一半,从大到小遍历,对于每个数在左边那组找到最大的满足 ...

  5. Codeforces 1301B Motarack's Birthday(二分)

    题目链接:http://codeforces.com/problemset/problem/1301/B 思路: (1)都是-1的情况 (2)只有一个除-1之外的数 (3)至少有两个除-1之外的不同的 ...

  6. Codeforces 997A Convert to Ones(思维)

    https://codeforces.com/problemset/problem/997/A 题目大意: 给定一串0-1序列,定义两种操作: 操作一:选取一连续串倒置. 操作二:选取一连续串把进行0 ...

  7. codeforces 286 E. Ladies' Shop (FFT)

    E. Ladies' Shop time limit per test 8 seconds memory limit per test 256 megabytes input standard inp ...

  8. [CodeForces - 296D]Greg and Graph(floyd)

    Description 题意:给定一个有向图,一共有N个点,给邻接矩阵.依次去掉N个节点,每一次去掉一个节点的同时,将其直接与当前节点相连的边和当前节点连出的边都需要去除,输出N个数,表示去掉当前节点 ...

  9. codeforces 380A Sereja and Prefixes (递归)

    题目: A. Sereja and Prefixes time limit per test 1 second memory limit per test 256 megabytes input st ...

随机推荐

  1. MyBatis 示例-主键回填

    测试类:com.yjw.demo.PrimaryKeyTest 自增长列 数据库表的主键为自增长列,在写业务代码的时候,经常需要在表中新增一条数据后,能获得这条数据的主键 ID,MyBatis 提供了 ...

  2. 解决go mod或go get时`x509: certificate signed by unknown authority`错误

    一般go get私有仓库时会出现如下错误: go: xxx@v0.0.0-20190918102752-bb51b27911ca: unrecognized import path "xxx ...

  3. C++性能榨汁机之伪共享

    C++性能榨汁机之伪共享 来源  http://irootlee.com/juicer_false_sharing/ 前言 在多核并发编程中,如果将互斥锁的争用比作“性能杀手”的话,那么伪共享则相当于 ...

  4. centos7 firewall指定IP与端口、端段访问(常用)

    https://blog.csdn.net/yipianfuyunsm/article/details/99998332 https://www.cnblogs.com/co10rway/p/8268 ...

  5. 使用js输出1000以内的水仙花数

    什么是水仙花数 水仙花数(Narcissistic number)也被称为超完全数字不变数(pluperfect digital invariant, PPDI).自恋数.自幂数.阿姆斯壮数或阿姆斯特 ...

  6. mybatis整合spring下的的各种配置文件

    1.applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans ...

  7. 0502 xss

    playload <script>window.open('http://n00p.me/cookie.php?cookie='+document.cookie)</script&g ...

  8. SSISDB7:当前正在运行的Package及其Executable

    PM问:“Vic,现在ETL Job跑到哪一个Package了,正在执行哪个Task?”,第一次遇到这个问题时,一下就懵逼了,只能硬着头皮说:“我看看”. 在做项目开发时,这个问题很常见,但是,被很多 ...

  9. mock.js学习之路(二)easy-mock(Vue中使用)

    1.easy-mock建立外部数据,注册账号,创建数据,详细使用过程参照https://www.easy-mock.com/docs文档说明 2.项目中如何引入使用 ①配置一下config.index ...

  10. IDEA 运行报错:WARN: Establishing SSL connection

    使用JDBC连接数据库时出现报错, 报错内容:Wed Sep 26 14:30:31 CST 2018 WARN: Establishing SSL connection without server ...