题目链接:http://codeforces.com/problemset/problem/1166/E

说明

  1. LCM(一个集合) 为这个集合中所有元素的最小公倍数。
  2. 如果$A \subseteq B,LCM(A) \leq LCM(B)$。

题目大意

  给定由 n 个整数组成的集合 A 。现给定 m 组集合,每个集合 Si 都是 A 的一个真子集,求是否存在集合 A 使得对$\forall_{1 \leq i \leq m} \ 不等式LCM(S_i) > LCM(A - S_i)恒成立$。

分析

  考虑任意两个不同集合 Si 和 Sj,它们有两种可能情况:
  1. 无交集:$LCM(S_i) \geq LCM(A - S_i) \geq LCM(S_j) 和 LCM(S_j) \geq LCM(A - S_j) \geq LCM(S_i)矛盾$,所以只要有两个集合没有交集,A就不存在。
  2. 有交集:有交集一不一定存在 A 呢?不晓得,只能说可能,反正题目只需要输出可不可能。
  PS:用 set 做超时,自己写位图吧。

代码如下

 #include <bits/stdc++.h>
using namespace std; #define INIT() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) #define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl #define LOWBIT(x) ((x)&(-x)) #define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin()) #define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a)) #define MP make_pair
#define PB push_back
#define ft first
#define sd second template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
} template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x: v)
in >> x;
return in;
} template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]" << "\n";
return out;
} inline int gc(){
static const int BUF = 1e7;
static char buf[BUF], *bg = buf + BUF, *ed = bg; if(bg == ed) fread(bg = buf, , BUF, stdin);
return *bg++;
} inline int ri(){
int x = , f = , c = gc();
for(; c<||c>; f = c=='-'?-:f, c=gc());
for(; c>&&c<; x = x* + c - , c=gc());
return x*f;
} typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef pair< int, int > PII;
typedef pair< string, int > PSI;
typedef set< int > SI;
typedef vector< int > VI;
typedef map< int, int > MII;
typedef pair< LL, LL > PLL;
typedef vector< LL > VL;
typedef vector< VL > VVL;
const double EPS = 1e-;
const LL inf = 0x7fffffff;
const LL infLL = 0x7fffffffffffffffLL;
const LL mod = 1e18 + ;
const int maxN = 1e4 + ;
const LL ONE = ;
const LL evenBits = 0xaaaaaaaaaaaaaaaa;
const LL oddBits = 0x5555555555555555; struct BitMap{
char bm[maxN >> ]; // 把第 x 位设置为 1
void set(int x){
bm[x >> ] |= 0x80 >> (x & 0x07);
}
// 把第 x 位设置为 1
void clear(int x){
bm[x >> ] &= ~(0x80 >> (x & 0x07));
}
// 获得第 x 位值
bool get(int x){
return bm[x >> ] & (0x80 >> (x & 0x07));
} bool operator& (const BitMap &x) const{
Rep(i, maxN >> ) if(bm[i] & x.bm[i]) return true;
return false;
} bool operator| (const BitMap &x) const{
Rep(i, maxN >> ) if(bm[i] | x.bm[i]) return true;
return false;
}
}; int m, n, s;
BitMap bitMask[];
bool ans = true; int main(){
INIT();
cin >> m >> n;
Rep(i, m) {
cin >> s;
Rep(j, s) {
int x;
cin >> x;
bitMask[i].set(x);
}
} Rep(i, m) {
For(j, i + , m - ) {
if(bitMask[i] & bitMask[j]) continue;
ans = false;
i = m;
break;
}
} if(ans) cout << "possible" << endl;
else cout << "impossible" << endl;
return ;
}

CodeForces 1166E The LCMs Must be Large的更多相关文章

  1. CF1166E The LCMs Must be Large

    CF1166E The LCMs Must be Large 构造趣题 正着推其实很不好推 不妨大力猜结论 如果两两集合都有交,那么一定可以 证明: 1.显然如果两个集合没有交,一定不可以 2.否则给 ...

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

    传送门 题意: 有 n 个商店,第 i 个商店出售正整数 ai: Dora 买了 m 天的东西,第 i 天去了 si 个不同的个商店购买了 si 个数: Dora 的对手 Swiper 在第 i 天去 ...

  3. 【36.86%】【codeforces 558B】Amr and The Large Array

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. codeforces 558B B. Amr and The Large Array(水题)

    题目链接: B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes in ...

  5. CodeForces 1152F2 Neko Rules the Catniverse (Large Version)

    题目链接:http://codeforces.com/problemset/problem/1152/F2 题目大意 见http://codeforces.com/problemset/problem ...

  6. Codeforces 1166E(思维)

    题面 有一个长度为n的序列a,有m次操作.每一次操作一个人选a的一个子集x,另一个人会选x的补集y.且x集合中的数的最小公倍数比y集合中的数的最小公倍数大.现在给出所有x,判断是否有一个序列a满足条件 ...

  7. 降智严重——nowcoder练习赛46&&codeforces #561 Div2

    两场比赛降智不停,熬夜爆肝更掉rating nowcoder: https://ac.nowcoder.com/acm/contest/894#question T1:水题 T2:考虑a和b的子区间! ...

  8. codeforces631B

    Print Check CodeForces - 631B Kris works in a large company "Blake Technologies". As a bes ...

  9. Codeforces Round #312 (Div. 2)B. Amr and The Large Array 暴力

    B. Amr and The Large Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

随机推荐

  1. js滚动页面到固定位置进行操作

    $(window).scroll(function () { var scrollTop = $(this).scrollTop(); var scrollHeight = $("#div& ...

  2. /etc/X11/xorg.conf

    # This configuration file was broken by system-config-keyboard Section "ServerLayout" Iden ...

  3. base64和Xxtea的加密和解密

    base64和Xxtea的加密和解密 数据加密是web数据安全的一种方式,前几天拿到一个base64+xxtea加密的数据,现在在这里整理一下使用的过程.首先当然是全网站找解密方法,但是最后的结果不是 ...

  4. Git 学习第四天

    我们已经知道,通过命令 git remote add origin git@github.com/Your.name/file.git 可以连接远程仓库,那么,假如我现在想切换另个一远程仓库的连接应该 ...

  5. 豆瓣图书Top250

    从豆瓣图书Top250抓取数据,并通过词云图展示 导入库 from lxml import etree #解析库 import time #时间 import random #随机函数 import ...

  6. Quartz CronTrigger 整配置说明

    Quartz cron 表达式的格式向下支持到秒级别的计划,而 UNIX cron 计划仅支持至分钟级.  Quartz用cron 表达式存放执行计划,引用了cron表达式的CronTrigger在计 ...

  7. ArcGis基础—shapefile矢量文件与lyr图层文件之间有何区别?

    shapefile (.shp) 是一种矢量数据存储格式,用于存储地理要素的位置.形状和属性. shapefile 存储在一组相关文件中,并包含一个要素类. 图层文件 (.lyr) 是存储源数据集路径 ...

  8. to meet you Java多线程与并发

    2: hotspot中对象在内存的布局是分3部分 对象头 实例数据 对其填充 这里主要讲对象头:一般而言synchronized使用的锁对象是存储在对象头里的,对象头是由Mark Word和Class ...

  9. docker Dockerfile学习---构建redis环境

    1.创建项目目录并下载包及文件 mkdir centos_redis cd centos_redis wget http://download.redis.io/releases/redis-5.0. ...

  10. 基于LNMP架构部署wordpress

    [root@localhost ~]# yum -y install unzip[root@localhost ~]# unzip wordpress-5.2.3.zip[root@localhost ...