题目链接: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. 导出EXCEL(带数据)

    /* * 导出EXCEL * @param req * @param resp * @param model * @param info * @return */ @RequestMapping(va ...

  2. eclipse git项目的冲突文件处理

    https://jingyan.baidu.com/article/3c48dd34895a07e10ae35871.html

  3. 牛客网暑期ACM多校训练营(第五场) Agpa (最大化平均值)

    题目大意: 给定 n 门课以及它们的学分和绩点,定义总绩点是所有课的加权平均数,给定一个数 k, 你可以删除最多 k 门课,求你的总绩点最大能到多少 分析: 上面是牛客的官方题解,其实就是移项, 然后 ...

  4. js滚动到顶部底部代码

    <!DOCTYPE HTML> <html> <head> <meta charset=UTF-8> <title>SCROLL</t ...

  5. HIve分组查询返回每组的一条记录

    select a.lng,a.lat from (select row_number() over ( partition by uid,grid_id) as rnum,weighted_centr ...

  6. 解决spring boot中普通类中使用service为null 的方法

    我使用的是springboot+mybatisplus +mysql1.创建一个SpringUtil工具类 import org.springframework.beans.BeansExceptio ...

  7. 提升R代码运算效率的11个实用方法

    提升R代码运算效率的11个实用方法 众所周知,当我们利用R语言处理大型数据集时,for 循环语句的运算效率非常低.有许多种方法可以提升你的代码运算效率,但或许你更想了解运算效率能得到多大的提升.本文将 ...

  8. Dubbo入门到精通学习笔记(四):持续集成管理平台之Maven私有库和本地库的安装与配置

    文章目录 介绍 Maven私有库和本地库的安装与配置 Nexus安装 Nexus 配置(登录后) 介绍 如果构建的Maven项目本地仓库没有对应的依赖包,那么就会去Nexus私服去下载, 那么如果Ne ...

  9. php ZipArchive 压缩整个文件夹

    // Get real path for our folder $rootPath = realpath('folder-to-zip'); // Initialize archive object ...

  10. 30-Ubuntu-用户权限-01-用户和权限的基本概念

    1.用户 用户是Linux系统工作中重要的一环,用户管理包括用户和组管理. 在Linux系统中,不论是由本机或是远程管理登录系统,每个系统都必须拥有一个账号,并且对于不同的系统资源拥有不同的使用权限. ...