Codeforces Round #561 (Div. 2) E. The LCMs Must be Large(数学)

传送门

 

题意:

  有 n 个商店,第 i 个商店出售正整数 ai

  Dora 买了 m 天的东西,第 i 天去了 si 个不同的个商店购买了 si 个数;

  Dora 的对手 Swiper 在第 i 天去了 Dora 未去的商店购买了 n-si 个数;

  问在这m天里,是否存在序列a,使得这 m 天都满足 LCM(Dora购买的数) > LCM(Swiper购买的数);

题解:

  参考自(

  ①如果存在两天,在这两天中得到的数字集合不存在交集,那么肯定是无解的。
  ②如果任意两天之间都存在交集时,一定有解(还是不太理解)。

AC代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn=1e4+50;
 4 
 5 int n,m;
 6 bitset<maxn>b;
 7 vector<bitset<maxn> >vs;
 8 
 9 char *Solve()
10 {
11     for(int i=0;i < vs.size();++i)
12         for(int j=0;j < vs.size();++j)
13             if(!(vs[i]&vs[j]).any())
14                 return "impossible";
15     return "possible";
16 }
17 int main()
18 {
19     scanf("%d%d",&m,&n);
20     for(int i=1;i <= m;++i)
21     {
22         int tot,s;
23         scanf("%d",&tot);
24         b.reset();
25         for(int j=1;j <= tot;++j)
26         {
27             scanf("%d",&s);
28             b.set(s);
29         }
30         vs.push_back(b);
31     }
32     puts(Solve());
33 
34     return 0;
35 }
View Code

此处代码用到了一个STL中的一个骚操作bitset<>,详解戳这里

这个操作是我在看大神代码中看到的,tql;

STL也太强大了叭qwq!

  

posted @ 2019-05-21 09:15  HHHyacinth  阅读(284)  评论(0编辑  收藏  举报