题面

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

分析

考虑不满足条件的情况:假如子集\(x_i\)和\(x_j\)完全不相交,会出现矛盾

因为\(gcd(x_i)>gcd(a-x_i),gcd(x_j)>gcd(a-x_j)\),我们又知道\(x_j=a-x_i\),因此上式可以化为\(gcd(x_i)>gcd(x_j),gcd(x_j)>gcd(x,y)\),矛盾

代码

#include<iostream>
#include<cstdio>
#define maxm 55
#define maxn 10005
using namespace std;
int m,n;
int a[maxm][maxn];
int main() {
int sz,x;
scanf("%d %d",&m,&n);
for(int i=1; i<=m; i++) {
scanf("%d",&sz);
for(int j=1; j<=sz; j++) {
scanf("%d",&x);
a[i][x]=1;
}
}
for(int i=1; i<=m; i++) {
for(int j=1; j<=m; j++) {
bool flag=true;
for(int k=1; k<=n; k++) {
if(a[i][k]==1&&a[j][k]==1) {
flag=false;
}
}
if(flag) {
printf("impossible\n");
return 0;
}
}
}
printf("possible");
}

Codeforces 1166E(思维)的更多相关文章

  1. Codeforces 424A (思维题)

    Squats Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Statu ...

  2. Codeforces 1060E(思维+贡献法)

    https://codeforces.com/contest/1060/problem/E 题意 给一颗树,在原始的图中假如两个点连向同一个点,这两个点之间就可以连一条边,定义两点之间的长度为两点之间 ...

  3. Queue CodeForces - 353D (思维dp)

    https://codeforces.com/problemset/problem/353/D 大意:给定字符串, 每一秒, 若F在M的右侧, 则交换M与F, 求多少秒后F全在M左侧 $dp[i]$为 ...

  4. codeforces 1244C (思维 or 扩展欧几里得)

    (点击此处查看原题) 题意分析 已知 n , p , w, d ,求x , y, z的值 ,他们的关系为: x + y + z = n x * w + y * d = p 思维法 当 y < w ...

  5. CodeForces 1166E The LCMs Must be Large

    题目链接:http://codeforces.com/problemset/problem/1166/E 说明 LCM(一个集合) 为这个集合中所有元素的最小公倍数. 如果$A \subseteq B ...

  6. CodeForces - 417B (思维题)

    Crash Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status ...

  7. CodeForces - 417A(思维题)

    Elimination Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit  ...

  8. CodeForces 625A 思维

    题意是说一个人喝酒 有两种办法 买塑料瓶的 a块钱 喝了就没了 或者是买玻璃瓶的b块钱 喝完还能卖了瓶子c块钱 求最多能喝多少瓶 在开始判断一次 a与b-c的关系 即两种方式喝酒的成本 如果a< ...

  9. Vladik and Complicated Book CodeForces - 811B (思维实现)

    Vladik had started reading a complicated book about algorithms containing n pages. To improve unders ...

随机推荐

  1. Azkaban和Oozie的区别

    Azkaban和Oozie的区别: 当前,实际生产中最流行的两种Hadoop工作流引擎是Azkaban与Oozie.但活跃度最高的当是Azkaban了,下面对两者的异同之处作如下对比. 功能对比 Az ...

  2. Taro -- 获取用户手机号

    1. 安装 Taro 脚手架工具 安装 Taro 开发工具 @tarojs/cli 使用 npm 或者 yarn 全局安装 $ npm install -g @tarojs/cli $ yarn gl ...

  3. idea hibernate console 执行hql报错

    报错信息 hql> select a from GDXMZD a[2019-08-29 13:45:01] org.hibernate.service.spi.ServiceException: ...

  4. sed 搜索并替换

    find . -type f -exec sed -i "s/std=c++11/std=c++14/g" {} \; 搜索当前目录下的文件,把std=c++11替换成std=c+ ...

  5. Python3解leetcode Average of Levels in Binary Tree

    问题描述: Given a non-empty binary tree, return the average value of the nodes on each level in the form ...

  6. shell学习----正则表达式

    在使用sed和gawk时如果能够熟练的使用正则表达式,可以准确的过滤到自己需要的信息 Linux中,有两种流行的正则表达式引擎: POSIX基础正则表达式,BRE引擎 POSIX扩展正则表达式,ERE ...

  7. LRU management

    LRU management 字典树用来查找值,实现map<string,int>操作 tips:tot必须从一开始QAQ #include<bits/stdc++.h> us ...

  8. 【CDN+】 Hive 入门 以及Handoop 系统认知

    前言 本文主要介绍Hive 的基础概念,以及Handoop的大体架构,组件依赖,对于大数据有个总体的认识 Hive 基础概念 官网:https://hive.apache.org/ The Apach ...

  9. JS - 迭代协议

    Iteration protocols | MDN 可迭代协议(iterable protocol) 迭代器协议(iterator protocol)

  10. Mybatis入门之MyBatis项目案例

    一.项目案例演示 后台管理系统用户数据维护平台 所有用户数据查询 单个用户数据查询 用户数据修改(完善资料) 锁定用户账号 删除用户账号 彻底删除用户账号 二.数据库数据准备工作 数据库:mysql ...