CF549BLooksery Party题解
题目描述
The Looksery company, consisting of nn staff members, is planning another big party. Every employee has his phone number and the phone numbers of his friends in the phone book. Everyone who comes to the party, sends messages to his contacts about how cool it is. At the same time everyone is trying to spend as much time on the fun as possible, so they send messages to everyone without special thinking, moreover, each person even sends a message to himself or herself.
Igor and Max, Looksery developers, started a dispute on how many messages each person gets. Igor indicates nnnumbers, the i -th of which indicates how many messages, in his view, the i -th employee is going to take. If Igor guesses correctly at least one of these numbers, he wins, otherwise Max wins.
You support Max in this debate, so you need, given the contact lists of the employees, to determine whether there is a situation where Igor loses. Specifically, you need to determine which employees should come to the party, and which should not, so after all the visitors send messages to their contacts, each employee received a number of messages that is different from what Igor stated.
(P.s感谢@luogu.org_悠悠我昕 提供翻译)
Looksery 公司由 n 名员工所组成,每个员工都有自己的电话和联系人列表。
最近,公司打算举办一场大型派对,每位到场的员工,都会向他的联系人发送消息,来说明这场派对有多炫酷。由于每个人都想花尽量多的时间来享受派对时光,他们会不假思索地向所有联系人发送消息,甚至包括他们自己。
Looksery 公司的开发者 Igor 和 Max 就每个人收到了多少条消息展开了争论. Igor 钦点了 n 个数字,其中第 i 个数字表示 Igor 认为第 i 个人收到的消息条数。如果 Igor 猜到了至少 1 个数字就算他胜利,否则 Max 胜利。
作为 Max 的支持者,你需要根据员工的联系人列表,确定是否存在 Igor 会输的情况。具体来说,你需要确定哪些人应该参加派对,使得派对结束后,任意一个人收到的消息条数与 Igor 所给出的不同。
输入输出格式
输入格式:
The first line contains a single integer nn ( 1<=n<=100 ) — the number of employees of company Looksery.
Next nn lines contain the description of the contact lists of the employees. The i -th of these lines contains a string of length nn , consisting of digits zero and one, specifying the contact list of the i -th employee. If the j -th character of the ii -th string equals 1, then the j -th employee is in the i -th employee's contact list, otherwise he isn't. It is guaranteed that the ii -th character of the ii -th line is always equal tThe last line contains nn space-separated integers: a1,a2,...,an( 0<=ai<=n), where ai represents the number of messages that the i -th employee should get according to Igor.
第一行一个正整数 n(1≤n≤100) ,表示 Looksery 公司的员工数量。
接下来 n 行描述了所有员工的联系人列表,每行为一个长度为 n 的字符串。若第 i 行的第 j 个字符为 1 ,则第 j名员工在第 i 名员工的联系人列表中,否则就不在。特别地,第 i 个人总是自己的联系人列表中。
最后一行 n 个由空格隔开的数字 a1,a2,...,an(0≤ai≤n) ,表示 Igor 所认为的每个员工会收到的消息数量。
输出格式:
In the first line print a single integer m — the number of employees who should come to the party so that Igor loses the dispute.
In the second line print m space-separated integers — the numbers of these employees in an arbitrary order.
If Igor wins the dispute in any case, print -1.
If there are multiple possible solutions, print any of them.
第一行一个整数 m 表示参加派对的人数。
第二行 m 个正整数,表示参加派对的员工的编号。
如果有多种方案满足条件,输出其中任意一种即可。
如果 Igor 无论如何都会赢,输出 -1 。
题解
对于这道题,我们可以先证明一下没有无解的情况:
【反证】假设存在无解情况,则存在当n个人都进入邀请方案时存在一个a[i] = 0,而这与a[i] = 0时才可以进入邀请方案相矛盾所以不存在无解情况。
由此我们可以考虑一下这道题的贪心策略:
如果不存在任何a[i]==0那么,当所有人都不进入邀请方案时一定满足条件。
如果存在某一a[i]!=0那么,因为如果i进入邀请方案,则他会给每一个他认识的人发送消息(包括他自己),这就可以使他收到的信息不为0,而同样他会更新其他他认识的人所不应该收到的短信数量,则会造成有新的a[k]==0只需要用队列记录一下,依次处理即可。
代码
#include <bits/stdc++.h>
using namespace std; const int MAX = ;
vector<int> v[MAX], worker;
queue<int> q;
int a[MAX], vis[MAX];
int main()
{
// freopen("CF549B.in", "r", stdin);
// freopen("CF549B.out", "w", stdout); int n, x;
char s[MAX];
scanf("%d", &n);
for(int i = ; i <= n; ++ i)
{
scanf("%s", s + );
for(int j = ; j <= n; ++ j)
if(s[j] == '') v[i].push_back(j);
}
for(int i = ; i <= n; ++ i)
{
scanf("%d", &a[i]);
if(a[i] == ) q.push(i);
}
for(;!q.empty();)
{
x = q.front(); q.pop();
worker.push_back(x);
for(int i = ; i < v[x].size(); ++ i)
{
int y = v[x][i];
a[y] --;
if(a[y] == ) q.push(y);
}
}
printf("%d\n", worker.size());
for(int i = ; i < worker.size(); ++ i)
printf("%d ", worker[i]);
printf("\n");
return ;
}
总结与反思
对于一些贪心我们通常的考虑是从一般情况入手,但是这道题他却需要我们构造出一组符合条件的特解,然后把大多数的一般情况都划归到这个特解上来,这是我们所需要了解的一种解题思路。
CF549BLooksery Party题解的更多相关文章
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- poj1399 hoj1037 Direct Visibility 题解 (宽搜)
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...
- 网络流n题 题解
学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...
- CF100965C题解..
求方程 \[ \begin{array}\\ \sum_{i=1}^n x_i & \equiv & a_1 \pmod{p} \\ \sum_{i=1}^n x_i^2 & ...
随机推荐
- my33_内存满导致mysqld被kill
监控报警发现MGR的一个节点故障,查看时发现LVS已经发生切换,LVS切到了MGR新的写节点上了,排查原因 /var/log/message Mar :: db10 kernel: crond inv ...
- AUTO Uninstaller【教程】AUTODESK系列软件MAYA,3DSMAX,CAD,INVENTOR,REVIT修复卸载工具 Windows x64位
小伙伴是不是遇到 MAYA/CAD/3DSMAX/INVENTOR/REVIT 安装失败或者安装不了的问题了呢?AUTODESK系列软件着实令人头疼,MAYA/CAD/3DSMAX/INVENTOR/ ...
- 牛客网Java刷题知识点之垃圾回收算法过程、哪些内存需要回收、被标记需要清除对象的自我救赎、对象将根据存活的时间被分为:年轻代、年老代(Old Generation)、永久代、垃圾回收器的分类
不多说,直接上干货! 首先,大家要搞清楚,java里的内存是怎么分配的.详细见 牛客网Java刷题知识点之内存的划分(寄存器.本地方法区.方法区.栈内存和堆内存) 哪些内存需要回收 其实,一般是对堆内 ...
- TOJ 3744 Transportation Costs
描述 Minya Konka decided to go to Fuzhou to participate in the ACM regional contest at their own expen ...
- 8086实时时钟实验(二)——《x86汇编语言:从实模式到保护模式》读书笔记06
上次我们说了代码,这次我们说说怎样看到实验结果. 首先编译源文件(我的源文件就在当前路径下,a盘和c盘在上一级目录下): nasm -f bin c08_mbr.asm -o c08_mbr.bin ...
- 使用mini-define实现前端代码的模块化管理
这篇文章主要介绍了使用mini-define实现前端代码的模块化管理,十分不错的一篇文章,这里推荐给有需要的小伙伴. mini-define 依据require实现的简易的前端模块化框架.如果你不想花 ...
- 项目搭建系列之三:SpringMVC框架下使用Ehcache对象、数据缓存
注明:该文章为以前写的文章,这里只更改了标题,无GitHub源码下载. 一.准备工作 如果已经成功搭建SpringMVC环境,那么就可以进入Ehcache的准备工作了.1.下载jar包 Ehca ...
- scss-变量作用域
SCSS之所以便利,是因为它具有了编程语言的某些特性. 让原本规则刻板的CSS变的灵活起来,下面介绍一下SCSS中的作用域概念. 几乎所有编程语言都有作用域概念的涉及,原理大同小异,SCSS中的也是如 ...
- 在 CentOS 上安装 node.js
进入到 /usr/local/ 目录中: cd /usr/local/ 创建 nodejs 文件夹: mkdir -p nodejs 进入到 nodejs 目录中: cd nodejs 下载 node ...
- 菜鸟学习Spring——SpringMVC注解版将URL中的参数转成实体
一.概述 将URL中参数转成实体在我们项目中用的很多比如界面提交表单请求后台的Contorller的时候通过URL传递了一串参数到后台,后台通过Spring让界面的字段与实体的字段映射来实现给后台的实 ...