当前位置:网站首页>C. Qualification Rounds(思维,特情)
C. Qualification Rounds(思维,特情)
2022-07-30 04:09:00 【小酒窝.】
C. Qualification Rounds
题意
给定 n * m 的 01 矩阵。
问,是否可以从中挑选出若干行,满足:
- 对于每一列来说,挑选出的所有行中,1 的个数最多是总行数的一半。
1 ≤ n ≤ 1 0 5 , 1 ≤ k ≤ 4 1 ≤ n ≤ 10^5, 1 ≤ k ≤ 4 1 ≤ n ≤ 105,1 ≤ k ≤ 4
思路
也就是说,每一列 0 的个数要大于等于 1 的个数。
考虑特殊情况,最多只需要看两行。
如果发现存在一行全是 0,肯定满足。
如果发现存在两行,每一列至少有一个 0,那么也是满足的。
也就是找,是否存在两行,其对应位置相与之后,所有位置都为 0。也就是,将每一行转为二进制之后,是否存在两行相与为0。
n 最大为 10^5,但是 k 最大为 4,所以最多有 2^4 种行,二进制枚举 0到2^4,看哪些二进制出现过,二重循环暴力出现过的二进制看是否相与为 0。
Code
#include<bits/stdc++.h>
using namespace std;
#define Ios ios::sync_with_stdio(false),cin.tie(0)
const int N = 200010, mod = 1e9+7;
int T, n, m;
int a[N], f[N];
signed main(){
Ios;
cin >> n >> m;
int flag = 0;
for(int i=1;i<=n;i++)
{
int x = 0;
for(int j=0;j<m;j++)
{
int t; cin >> t;
if(t) x += 1<<j;
}
f[x] = 1;
if(x == 0) flag = 1; //仅有一个都为0的行都满足,提前标记
}
for(int i=0;i<1<<m;i++)
{
if(!f[i]) continue;
for(int j=i+1;j<1<<m;j++)
{
if(!f[j]) continue;
if((i & j) == 0) flag = 1; //注意 & 比 == 的优先级低,要加括号!!
}
}
if(flag) cout << "YES\n";
else cout << "NO\n";
return 0;
}
经验
一开始做的时候倒是想只拿两行的情况,但是也没手推一下,觉得不行就没再想。。
其实该画画的,如果画不出来别的情况那这样就是满足的,或者能直接证明最好。
所以有了思路一定要再想想,不要直接否定,也不要盲目肯定,先画画几个样例再说!说不定就是对的!!
还有就是要注意运算符优先级,注意 & 的优先级比 == 低,判断 i&j 是否为 0 是要加括号!
还有注意 i & (1<<j) 不一定是 0 或 1,而 i >> j & 1 的结果才是 0 或 1。
(i >> j & 1) == 0 这里也要加括号!
边栏推荐
- Why is the Kirin 9000 5G version suddenly back in stock?
- Anti-shake and throttling
- Redis "super explanation!!!!!!"
- Redis server启动后会做哪些操作?
- Mini Program Graduation Works WeChat Points Mall Mini Program Graduation Design Finished Product (8) Graduation Design Thesis Template
- Forum management system
- Arrays and Structures
- The implementation and basic operation of sub-database sub-table, ER table, global table, fragmentation rules, global sequence, etc. in MyCat
- When the EasyNVR platform is cascaded to the EasyCVR, why can't the video be played after a while?
- Roperties class configuration file & DOS to view the host network situation
猜你喜欢

小程序毕设作品之微信积分商城小程序毕业设计成品(5)任务书
![[ 云原生之谜 ] 云原生背景 && 定义 && 相关技术详解?](/img/eb/0cd6891fcc00d2c01ba8bd7f8d0822.png)
[ 云原生之谜 ] 云原生背景 && 定义 && 相关技术详解?

(redistribute, special comprehensive experiment ospf area)

(6) "Digital Electricity" - Diodes and CMOS Gate Circuits (Introduction)

ospf map

小程序毕设作品之微信积分商城小程序毕业设计成品(6)开题答辩PPT

Mini Program Graduation Works WeChat Points Mall Mini Program Graduation Design Finished Product (2) Mini Program Function

How does the AI intelligent security video platform EasyCVR configure the simultaneous transmission of audio and video?

sqlmap use tutorial Daquan command Daquan (graphics)

小程序毕设作品之微信二手交易小程序毕业设计成品(7)中期检查报告
随机推荐
小程序毕设作品之微信积分商城小程序毕业设计成品(2)小程序功能
恐造成下一个“千年虫”的闰秒,遭科技巨头们联合抵制
TCP congestion control technology and acceleration principle of BBR
高并发框架 Disruptor
RRU、BBU、AAU
Mini Program Graduation Works WeChat Points Mall Mini Program Graduation Design Finished Product (2) Mini Program Function
SQL introduction of the first lecture -- MySQL 8.0.29 installation tutorial (Windows 64 - bit)
[Switch] Protocol-Oriented Programming in Swift: Introduction
Usage of exists in sql
函数的底层机制
【驱动】udev设置GPIO加载后所有者、所属组和权限
Charles 替换 接口响应信息
flutter 记录学习不一样的动画(二)
Pytorch framework learning record 4 - the use of datasets (torchvision.dataset)
Boutique: Taobao/Tmall Get Order Details API for Purchased Products
SQLSERVER merges subquery data into one field
Mysql version upgrade, copy the Data file directly, the query is very slow
CMake installation and testing
小程序毕设作品之微信积分商城小程序毕业设计成品(1)开发概要
golang中如何比较struct,slice,map是否相等以及几种对比方法的区别