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 877 (Div. 2) 题解

    写了两题了,先总结一下吧。。。看了三题,都是思维题构造题,搞心态真的搞心态。。。感觉自己屁都不会,完全没有动力。。。有的有思路但是写不出来,但是思路不够成熟,练的题太少,其实这场到B题就卡住了,C题也是,题意都能读懂,但是思考的方向不对,很焦虑

    2024年02月10日
    浏览(13)
  • 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日
    浏览(8)
  • 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日
    浏览(8)
  • 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日
    浏览(10)
  • 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日
    浏览(7)
  • Educational Codeforces Round 148 (Rated for Div. 2) 题解

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

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

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

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

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

    2023年04月25日
    浏览(9)
  • Codeforces Round 882 (Div. 2)

    Codeforces Round 882 (Div. 2)

    目录 A. The Man who became a God  题目分析: B. Hamon Odyssey 题目分析: C. Vampiric Powers, anyone? 题目分析:  n个人分成k组,每一组的力量都是 这样的,那么如果分成k组那么就会有k-1个力量不被统计,将力量总和减去前k-1个最大的力量就是最小的结果   将数组分组,每个组内进行按位与

    2024年02月05日
    浏览(13)
  • Codeforces Round 881 (Div. 3)

    给定一个数组,给每个元素涂色。求最大的代价。 代价为每个颜色的代价和。 每个颜色的代价为涂了该颜色的元素的极差。 因为是极差,每个元素要么对答案有正的贡献,要么有负的贡献,要么无贡献。且正负贡献的个数要相同。 因为要最大值,自然就是想有正贡献的是最

    2024年02月09日
    浏览(21)

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

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

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

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

二维码1

领取红包

二维码2

领红包