Codeforces 549B Looksery Party
Solution:
仔细分析一下会发现每个人都会发一条消息给自己这个条件非常重要!
这个条件保证了一定会有解,而且解法也要从这里入手。
当我们拿到一个猜测的答案序列的时候,假设这个序列没有0,那我们一个人都不需要邀请。
存在0的时候先邀请答案是0的人,然后对在它联系人列表的人的答案进行减一操作,这样操作之后可能会让一些数减小到0,但是因为每个人能联系自己,必然可以将所有的0减掉,所以必然存在解。只要把我们选择的人记录下来就好。
#include <bits/stdc++.h> using namespace std;
const int N = ;
deque<int> q;
int a[N], G[N][N], use[N];
int n;
vector<int> ans;
string st; int main()
{
cin >> n;
for( int i = ; i <= n; ++i ) {
cin >> st;
for( int j = ; j < n; ++j ) {
G[i][j + ] = ( st[j] == '' );
}
}
for( int i = ; i <= n; ++i ) {
cin >> a[i];
if( a[i] == ) q.push_back( i );
} while( !q.empty() ) {
int x = q.front();
q.pop_front();
if( use[x] ) continue;
use[x] = ;
ans.push_back( x );
for( int i = ; i <= n; i++ ) {
if( !use[i] && G[x][i] ) {
if( --a[i] == ) q.push_back( i );
}
}
}
cout << ans.size() << endl;
for( int &i : ans ) {
cout << i << " ";
}
}
Codeforces 549B Looksery Party的更多相关文章
- Codeforces 549B. Looksery Party[构造]
B. Looksery Party time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- CF 549B Looksery Party
题面 解题思路 如果a数组全部>0,那么都不去即可.从这个角度出发,每次选出a[i]为0的,让它们去更新a数组,相当于拓补排序. 代码 #include<iostream> #inc ...
- codeforces Looksery Cup 2015 H Degenerate Matrix
The determinant of a matrix 2 × 2 is defined as follows: A matrix is called degenerate if its determ ...
- codeforces Looksery Cup 2015 D. Haar Features
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viol ...
- codeforces Looksery Cup 2015 H Degenerate Matrix 二分 注意浮点数陷阱
#include <cstdio> #include <cstring> #include <algorithm> #include <string> ...
- codeforces Looksery Cup 2015 C. The Game Of Parity
There are n cities in Westeros. The i-th city is inhabited by ai people. Daenerys and Stannis play t ...
- Looksery Cup 2015 A. Face Detection 水题
A. Face Detection Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/pro ...
- Looksery Cup 2015 B. Looksery Party 暴力
B. Looksery Party Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/pro ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
随机推荐
- 2D游戏编程3—GDI
WM_PAINT消息触发程序重新绘制界面,过程如下: PAINTSTRUCT ps; // used in WM_PAINT HDC hdc; // handle to ...
- AsyncSocket的使用
AsyncSocket使用流程 安装AsyncSocket 拷贝AsyncSocket类到项目 使用AsyncSocket set delegate @interface NetWork : NSOb ...
- 获得URl信息
public class GetUrlInfo { public static void printfInfo(URL url)throws Exception { ...
- oracle删除当前用户下所有表
1.如果有删除用户的权限,则可以: drop user user_name cascade; 加了cascade就可以把用户连带的数据全部删掉. 删除后再创建该用户.--创建管理员用户create u ...
- 2 weekend110的zookeeper的原理、特性、数据模型、节点、角色、顺序号、读写机制、保证、API接口、ACL、选举、 + 应用场景:统一命名服务、配置管理、集群管理、共享锁、队列管理
在hadoop生态圈里,很多地方都需zookeeper. 启动的时候,都是普通的server,但在启动过程中,通过一个特定的选举机制,选出一个leader. 只运行在一台服务器上,适合测试环境:Zoo ...
- Bash For Loop Examples
How do I use bash for loop to repeat certain task under Linux / UNIX operating system? How do I set ...
- eclipse 反编译class 文件 插件-jad
1.下载 jad.exe http://pan.baidu.com/s/1i3Ga33n 2.下载jadeclipse http://pan.baidu.com/s/1bn4H1iZ 放在ecli ...
- Mockito测试
Mockito 一 mockito基本概念 Mock测试是单元测试的重要方法之一,而Mockito作为一个流行的Mock框架,简单易学,且有非常简洁的API,测试代码的可读性很高. Mock测试就是在 ...
- java读取配置文件
java 读取文件可以用字节流和字符流. 由于一个汉字占两个字节,所以如果配置文件中有汉字,用字节流读取,会出现乱码. 用字符流则不会出现乱码. 配置文件 b.properties 文件如下: fam ...
- thymelef 布局 fragment
需求:布局页面, 把首页分成四个页面: header footer ,content ,aside ,从githua 下载的原型, 所有内容是在一起的,这里拆分, 重用, 减少代码量 做法: 新建页 ...