Codeforces 549B Looksery Party

Looksery Party

Solution:

  仔细分析一下会发现每个人都会发一条消息给自己这个条件非常重要!

这个条件保证了一定会有解,而且解法也要从这里入手。

当我们拿到一个猜测的答案序列的时候,假设这个序列没有0,那我们一个人都不需要邀请。

存在0的时候先邀请答案是0的人,然后对在它联系人列表的人的答案进行减一操作,这样操作之后可能会让一些数减小到0,但是因为每个人能联系自己,必然可以将所有的0减掉,所以必然存在解。只要把我们选择的人记录下来就好。

#include <bits/stdc++.h>

using namespace std;
const int N = 109;
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 = 1; i <= n; ++i ) {
        cin >> st;
        for( int j = 0; j < n; ++j ) {
            G[i][j + 1] = ( st[j] == ‘1‘ );
        }
    }
    for( int i = 1; i <= n; ++i ) {
        cin >> a[i];
        if( a[i] == 0 ) q.push_back( i );
    }

    while( !q.empty() ) {
        int x = q.front();
        q.pop_front();
        if( use[x] ) continue;
        use[x] = 1;
        ans.push_back( x );
        for( int i = 1; i <= n; i++ ) {
            if( !use[i] && G[x][i] ) {
                if( --a[i] == 0 ) q.push_back( i );
            }
        }
    }
    cout << ans.size() << endl;
    for( int &i : ans ) {
        cout << i << " ";
    }
}

时间: 2024-08-01 22:49:16

Codeforces 549B Looksery Party的相关文章

codeforces #549 Looksery Cup 部分题解

掉Rating快乐~~ A.Face Detection 题目大意:给定一个n?m的矩阵,求有多少2?2的子矩形满足单词"face"的每个字母在矩形中恰好出现一次 签到题 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 55 using namespace std; int n,m,ans; char map[M

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

#include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cmath> #include <iostream> using namespace std; bool fun(double l1,double r1,double l2,double r2){ return (l1 <= r2 && l1

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 determinant is equal to zero. The norm ||A|| of a matrix A is defined as a maximum of absolute values of its elements. You are given a matrix . Consider any

codeforces Looksery Cup 2015 D. Haar Features

The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th

Codeforces Round #286 (Div. 1) A. Mr. Kitayuta, the Treasure Hunter DP

链接: http://codeforces.com/problemset/problem/506/A 题意: 给出30000个岛,有n个宝石分布在上面,第一步到d位置,每次走的距离与上一步的差距不大于1,问走完一路最多捡到多少块宝石. 题解: 容易想到DP,dp[i][j]表示到达 i 处,现在步长为 j 时最多收集到的财富,转移也不难,cnt[i]表示 i 处的财富. dp[i+step-1] = max(dp[i+step-1],dp[i][j]+cnt[i+step+1]) dp[i+st

Codeforces 772A Voltage Keepsake - 二分答案

You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power store