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的更多相关文章

  1. Codeforces 549B. Looksery Party[构造]

    B. Looksery Party time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  2. CF 549B Looksery Party

    题面 解题思路 如果a数组全部>0,那么都不去即可.从这个角度出发,每次选出a[i]为0的,让它们去更新a数组,相当于拓补排序. 代码 #include<iostream> #inc ...

  3. 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 ...

  4. 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 ...

  5. codeforces Looksery Cup 2015 H Degenerate Matrix 二分 注意浮点数陷阱

    #include <cstdio> #include <cstring> #include <algorithm> #include <string> ...

  6. 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 ...

  7. Looksery Cup 2015 A. Face Detection 水题

    A. Face Detection Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/pro ...

  8. Looksery Cup 2015 B. Looksery Party 暴力

    B. Looksery Party Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/pro ...

  9. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

随机推荐

  1. leecode 回文字符串加强版

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  2. [Ruby on Rails Issue] When Setting Sqlite version on the Gemfile, Show error "An error occurred while installing sqlite3 ",

    Issue: Gem files will remain installed in /tmp/bundler20140825-31835-p0c0p/sqlite3-1.3.9/gems/sqlite ...

  3. 【转】Flask快速入门

    迫不及待要开始了吗?本页提供了一个很好的 Flask 介绍,并假定你已经安装好了 Flask.如果没有,请跳转到 安装 章节. 一个最小的应用 一个最小的 Flask 应用看起来会是这样: from ...

  4. php 生成mysql数据字典代码

    由于项目开发用了比较多的表 ,为了快速获取数据字典,通过php代码的方式来获取表结构和表注释.代码如下: <?php /** * 生成mysql数据字典 */ header ( "Co ...

  5. 【设计模式 - 22】之策略模式(Strategy)

    1      模式简介 在策略模式中,一个类的行为或其算法可以在运行时改变.策略模式定义了一系列算法,把它们一个个封装起来,并且使它们可以互相替换. 策略模式的优点: 1)        算法可以自由 ...

  6. 【转】Eclipse上安装GIT插件EGit及使用

    http://yufenfei.iteye.com/blog/1750124 一.Eclipse上安装GIT插件EGit Eclipse的版本eclipse-java-helios-SR2-win32 ...

  7. ios7新特性实践

    一 iOS 7 新特性:视图控制器切换API 二 iOS 7系列译文:认识 TextKit 三 iOS 7系列译文:iOS7的多任务处理 四 iOS7 最佳实践:一个天气应用案例(上) 五 iOS7 ...

  8. java基础入门-arraylist存储开销

    今天我们来看一下arraylist的存储开销,由于在项目其中,我尝试了一个很大的arraylist.然后内存爆了 所以我看了下源代码.原来arraylist的存储开销是比較大的,先上代码 import ...

  9. iOS CoreData (1)

    下面开始学习一下CoreData. Core Data不是一个关系型数据库,也不是关系型数据库管理系统(RDBMS). Core Data 为数据变更管理.对象存储.对象读取恢复的功能提供了支持. 它 ...

  10. 装有Win7系统的电脑在局域网不能共享的解决方案

    Win7系统的网络功能比XP有了进一步的增强,使用起来也相对清晰.但是由于做了很多表面优化的工作,使得底层的网络设置对于习惯了XP系统的人来说变得很不适应,其中局域网组建就是一个很大的问题.默认安装系 ...