zoukankan      html  css  js  c++  java
  • Codeforces 787B. Not Afraid

    Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them. 

    There are n parallel universes participating in this event (n Ricks and n Mortys). I. e. each of n universes has one Rick and one Morty. They're gathering in m groups. Each person can be in many groups and a group can contain an arbitrary number of members.

    Ricks and Mortys have registered online in these groups. So, a person can have joined a group more than once (developer of this website hadn't considered this possibility).

    Summer from universe #1 knows that in each parallel universe (including hers) exactly one of Rick and Morty from that universe is a traitor and is loyal, but no one knows which one. She knows that we are doomed if there's a group such that every member in that group is a traitor (they will plan and destroy the world). 

    Summer knows that if there's a possibility that world ends (there's a group where all members are traitors) she should immediately cancel this event. So she wants to know if she should cancel the event. You have to tell her yes if and only if there's at least one scenario (among all 2n possible scenarios, 2 possible scenarios for who a traitor in each universe) such that in that scenario the world will end.

    Input

    The first line of input contains two integers n and m (1 ≤ n, m ≤ 104) — number of universes and number of groups respectively.

    The next m lines contain the information about the groups. i-th of them first contains an integer k (number of times someone joined i-th group, k > 0) followed by k integers vi, 1, vi, 2, ..., vi, k. If vi, j is negative, it means that Rick from universe number  - vi, j has joined this group and otherwise it means that Morty from universe number vi, j has joined it.

    Sum of k for all groups does not exceed 104.

    Output

    In a single line print the answer to Summer's question. Print "YES" if she should cancel the event and "NO" otherwise.

    水题,用map很轻松就过了,结果想试试用用bitset一直不过,才发现是自己读题不仔细,即便是一个宇宙的同一个人也可以参加一组多次(a person can have joined a group more than once)我读的时候下意识以为是不同宇宙的就略过了这句。结果就一直错

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    #define SIZE 30005
    
    bitset<SIZE> bs;
    int ok = 0,n,m;
    const int DELTA = 10000;
    int main()
    {
      // freopen("test.in","r",stdin);
      ios::sync_with_stdio(false);
      cin >> n >> m;
      for (int i=1;i<=m;i++){
        int nums;
        cin >> nums;
        int oks = 0;
        bs.reset();
        for (int j=1;j<=nums;j++){
          int now;
          cin >> now;
          bs.set(now + DELTA);
          if (bs.test(DELTA - now)){
            oks = 1;
          }
        }
        if (!oks){
          ok = 1;
        }
      }
    
      (ok)? printf("YES"): printf("NO");
      return 0;
    }
    View Code
  • 相关阅读:
    QT:浮动的饼状统计图(自绘不规则窗口)
    在QTableView中使用各种自定义委托
    QT:使用“状态模式”绘制界面
    Linux IO控制命令生成
    C++ new和delete实现原理——new和delete最终调用malloc和free
    Qt中如何 编写插件 加载插件 卸载插件
    QT:用QSet储存自定义结构体的问题——QSet和STL的set是有本质区别的,QSet是基于哈希算法的,要求提供自定义==和qHash函数
    两种方法:VS2008下C++窗体程序显示控制台的方法——在QT程序中使用cout和cin
    把自定义控件集成到Qt Designer中
    关闭Windows 2008下面应用程序出错后的提示
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/7473951.html
Copyright © 2011-2022 走看看