Codeforces Div.2 1798B Three Sevens题解

这篇具有很好参考价值的文章主要介绍了Codeforces Div.2 1798B Three Sevens题解。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

题目:

传送门

B. Three Sevens

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Lottery "Three Sevens" was held for m days. On day i, ni people with the numbers ai,1,…,ai,ni,participated in the lottery.

It is known that in each of the m days, only one winner was selected from the lottery participants. The lottery winner on day i was not allowed to participate in the lottery in the days from i+1 to m.

Unfortunately, the information about the lottery winners has been lost. You need to find any possible list of lottery winners on days from 11 to m or determine that no solution exists.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤50000). The description of the test cases follows.

The first line of each test case contains a single integer m (1≤m≤50000) — the number of days in which the lottery was held.

Next, for each i from 11 to m, follows a two-line block of data.

The first line of each block contains a single integer ni (1≤ni≤50000) — the number of lottery participants on day i.

The second line of the block contains integers ai,1,…,ai,ni (1≤ai,j≤50000) — lottery participants on day i. It is guaranteed that all the numbers ai,1,…,ai,ni are pairwise distinct.

It is guaranteed that the sum of ni over all blocks of all test cases does not exceed 5000050000.

Output

For each test case, if there is no solution, print a single integer −1−1.

Otherwise, print mintegers p1,p2,…,pm (1≤pi≤50000) — lottery winners on days from 11 to m. If there are multiple solutions, print any of them.

Sample 1

Inputcopy Outputcopy
 

3

3

4

1 2 4 8

3

2 9 1

2

1 4

2

2

1 2

2

2 1

4

4

1 2 3 4

1

1

1

4

1

3

8 2 1 
-1
2 1 4 3 

 Note

In the first test case, one of the answers is [8,2,1][8,2,1] since the participant with the number 88 participated on day 11, but did not participate on days 22 and 33; the participant with the number 22 participated on day 22, but did not participate on day 33; and the participant with the number 11 participated on day 33. Note that this is not the only possible answer, for example, [8,9,4][8,9,4] is also a correct answer.

In the second test case, both lottery participants participated on both days, so any possible lottery winner on the day 11 must have participated on the day 22, which is not allowed. Thus, there is no correct answer.

In the third test case, only one participant participated on days 22, 33, 44, and on day 11 there is only one participant who did not participate in the lottery on days 2,3,42,3,4 — participant 22, which means [2,1,4,3][2,1,4,3] is the only correct answer to this test case.


分析:

就是给几个数组,分别对应天数,如果一个数在第一天出现了,第二天没出现,可能就是这小子中奖了,然后答案就是输出可能的中奖名单。


文章来源地址https://www.toymoban.com/news/detail-465933.html

#include<bits/stdc++.h>
using namespace std;
int m, n;
set<int> st[50005];
int ans[50005];

void sol() 
{
    cin >> m;
    for (int i = 1; i <= m; i++) 
    {
        st[i].clear();
        cin >> n;
        for (int j = 1; j <= n; j++) 
        {
            int x;
            cin >> x;
            st[i].insert(x);
        }
    }

    set<int> tot;
    for (int i = m; i >= 1; i--) 
    {
        bool flag = false;
        for (int x : st[i]) 
        {
            if (tot.find(x) == tot.end()) 
            {
                flag = true;
                ans[i] = x;
            }
            tot.insert(x);
        }
        if (!flag) 
        {
            printf("-1\n");
            return;
        }
    }

    for (int i = 1; i <= m; i++) 
    {
        printf("%d ", ans[i]);
    }
    printf("\n");
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        sol();
    }
}

到了这里,关于Codeforces Div.2 1798B Three Sevens题解的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • Codeforces Round 875 (Div. 1) 题解

    You are given two arrays a and b both of length n. Your task is to count the number of pairs of integers ( i , j ) (i,j) ( i , j ) such that 1 ≤ i j ≤ n 1≤ij≤n 1 ≤ i j ≤ n and a i ⋅ a j = b i + b j a_i⋅a_j=b_i+b_j a i ​ ⋅ a j ​ = b i ​ + b j ​ 。 1 ≤ a i , b i ≤ n 1≤a_i,b_i≤n 1 ≤ a i ​ , b i ​ ≤ n 考虑 m i n ( a i

    2024年02月08日
    浏览(30)
  • Educational Codeforces Round 145 Div. 2 题解

    目录 A. Garland(签到) 题面翻译 思路: 代码 B. Points on Plane(数学) 题面翻译 思路: 代码 C. Sum on Subarray(构造) 题面翻译: 思路: 代码 D. Binary String Sorting 题面翻译 思路: 代码 You have a garland consisting of 4 colored light bulbs, the color of the i-th light bulb is si. Initially, all the l

    2023年04月09日
    浏览(9)
  • Educational Codeforces Round 147 div2题解

    目录 A. Matching(签到) 思路: 代码:  B. Sort the Subarray(签到) 思路: 代码: C. Tear It Apart(枚举) 思路: 代码: D. Black Cells(模拟) 思路:  代码一: 代码二:(模仿自\\\"AG\\\"佬) An integer template is a string consisting of digits and/or question marks. A positive (strictly greater than 0) in

    2023年04月21日
    浏览(11)
  • Codeforces Round 888 (Div. 3)(视频讲解全部题目)

    Codeforces Round 888 (Div. 3)(视频讲解全部题目)

    @[TOC](Codeforces Round 888 (Div. 3)(视频讲解全部题目)) Codeforces Round 888 (Div. 3)(A–G)全部题目详解

    2024年02月15日
    浏览(11)
  • Educational Codeforces Round 134 (Div.2) D 题解

    D. Maximum AND 给定两组序列 (a) (b) ,长度为 (n) ,现有一新序列 (c) ,长度也为 (n) 。 其中, (c_i = a_i oplus b_i) 。 定义 (f(a,b) = c_1c_2……c_n) 。 现在你可以随意编排 (b) 序列的顺序,求 (f(a,b)) 的最大值。 以下位运算均是二进制。 由于按位与的运算结果是越来越小的

    2024年02月06日
    浏览(10)
  • Educational Codeforces Round 148 (Rated for Div. 2) 题解

    总结:5.21下午VP一场,死在了A题,给我wa崩溃了,浪费了差不多一个小时,BC还挺顺畅,虽然C题是在结束后不久交上去的。。。。 思路:其实思路很简单, “ The string s a palindrome ”, 题目已经说了所给的为回文字符串,所以直接判断一半 有几种字符 即可(开始的时候计算整

    2024年02月06日
    浏览(13)
  • Codeforces 918(div4)

    注意一下判断 是否为平方数的方法;也要记得开long long 正序写 讨论的情况比较多,所以选择倒叙看;

    2024年02月03日
    浏览(10)
  • Codeforces Round 874 (Div. 3)

    Codeforces Round 874 (Div. 3)

    用最少的长度为2的字符串按一定规则拼出s。规则是:前一个字符串的尾与后一个字符串的首相同。 统计s中长度为2的不同字符串数量。 给定数组a[n]和b[n],重排b后,令任意|ai−bi|≤k成立(1≤k≤n)数据保证一定有解。 将a和b分别按从小到大的顺序匹配便是最优的,一定能满足

    2024年02月05日
    浏览(14)
  • Codeforces Round 871 (Div. 4)

    Codeforces Round 871 (Div. 4)

    给定n个长度为10的字符串,问其与codeforces字符串的对应下标字母不同的个数。 对于每个字符串从前往后依次和“codeforces”对应字符比较然后统计不同字母数即可 给定长度为n的数组,问连续相邻为0的最大长度 维护一个全局最大长度res,和当前连续序列的长度cnt。从前往后扫

    2024年02月03日
    浏览(10)
  • Codeforces Round 866 (Div. 2)

    给出一个仅由_或^组成的字符串,你可以在任意位置添加_或^字符,使得字符串满足: 任意字符要么属于^_^的一部分,要么属于^^的一部分。求最少添加的字符数量。 对于_我们只需处理没有组成^_^的_: ①如果_在首位置且左边没有^则添加^ ②如果_在尾位置且右边没有^则添加

    2023年04月25日
    浏览(11)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包