当前位置: 首页 > news >正文

CodeForces 226C The table[贪心]

一直找和是负的行/者列取反就行了....

可以发现每次取反负的行或者列一定会让矩阵和至少增加2 所以这个过程一定会结束,因为 值域 n m都很小 复杂度 \(O(n \times 10^6)\) (维护一下每行的和每列的和)

偷懒写了个最坏 \(O(n^2\times 10^6)\) 的过了

其实我感觉无法构造出让复杂度达到上界的矩阵

int n, m;
int a[105][103];
bool cnt[205];
void init() {

}
int check() {
  int pre = 0;
  lo1(i, n) {
    pre = 0;
    lo1(j, m) pre += a[i][j];
    if (pre < 0) return i;
  }
  lo1(i, m) {
    pre = 0;
    lo1(j, n) pre += a[j][i];
    if (pre < 0) return i + n;
  }
  return 0;
}
void solve() {
  n = in, m = in;
  lo1(i, n) lo1(j, m) in, a[i][j];
  int ss;
  while (ss = check()) {
    cnt[ss] ^= 1;
    if (ss > n) {
      ss -= n;
      lo1(i, n) a[i][ss] *= -1;
    }
    else lo1(i, m) a[ss][i] *= -1;
  }
  vint ans;
  lo1(i, n) if (cnt[i]) ans.pb(i);
  out, (int)(ans.size()), ' ';
  for (auto it : ans) out, it, ' ';
  puts(""), ans.clear();
  lo1(i, m) if (cnt[i + n]) ans.pb(i);
  out, (int)(ans.size()), ' ';
  for (auto it : ans) out, it, ' ';
}

转载于:https://www.cnblogs.com/storz/p/10463475.html

相关文章:

  • ThinkPHP 发布 5.1.35 版本,常规更新
  • 网页错误是不会报错的
  • 遇到Vue CLI网站显示异常
  • 教你从头写游戏服务器框架
  • C# 免费离线人脸识别 2.0 Demo
  • IDEA中使用Remote来远程调试程序
  • 15-Flink实战项目之实时热销排行
  • 随笔之python下载与安装
  • print(1,2,3,sep=':')的输出结果是?
  • windows下安装jdk与jmeter
  • 上海瀚示—电力仓库的电子货位标签应用
  • 宕机的阿里云们正在杀死运维?
  • 算法图解之广度优先算法
  • uboot内存布局(平台imx6 uboot2016)
  • 【干货】Kafka实现淘宝亿万级数据统计(下)
  • (ckeditor+ckfinder用法)Jquery,js获取ckeditor值
  • CSS魔法堂:Absolute Positioning就这个样
  • js中的正则表达式入门
  • PHP CLI应用的调试原理
  • Sass 快速入门教程
  • Unix命令
  • use Google search engine
  • v-if和v-for连用出现的问题
  • Vue 2.3、2.4 知识点小结
  • WePY 在小程序性能调优上做出的探究
  • 成为一名优秀的Developer的书单
  • 工作中总结前端开发流程--vue项目
  • 欢迎参加第二届中国游戏开发者大会
  • 理解在java “”i=i++;”所发生的事情
  • 微信端页面使用-webkit-box和绝对定位时,元素上移的问题
  • 为什么要用IPython/Jupyter?
  • 想使用 MongoDB ,你应该了解这8个方面!
  • ​​​​​​​​​​​​​​Γ函数
  • ​软考-高级-信息系统项目管理师教程 第四版【第23章-组织通用管理-思维导图】​
  • #LLM入门|Prompt#2.3_对查询任务进行分类|意图分析_Classification
  • ( 10 )MySQL中的外键
  • (003)SlickEdit Unity的补全
  • (04)Hive的相关概念——order by 、sort by、distribute by 、cluster by
  • (11)MATLAB PCA+SVM 人脸识别
  • (2)STM32单片机上位机
  • (附源码)springboot工单管理系统 毕业设计 964158
  • (附源码)springboot建达集团公司平台 毕业设计 141538
  • (算法)求1到1亿间的质数或素数
  • (转)C语言家族扩展收藏 (转)C语言家族扩展
  • (最全解法)输入一个整数,输出该数二进制表示中1的个数。
  • .net core webapi Startup 注入ConfigurePrimaryHttpMessageHandler
  • .NET 同步与异步 之 原子操作和自旋锁(Interlocked、SpinLock)(九)
  • .NetCore项目nginx发布
  • .Net转前端开发-启航篇,如何定制博客园主题
  • /bin/bash^M: bad interpreter: No such file ordirectory
  • @Import注解详解
  • [ CTF ] WriteUp- 2022年第三届“网鼎杯”网络安全大赛(白虎组)
  • [AI]文心一言爆火的同时,ChatGPT带来了这么多的开源项目你了解吗
  • [C#]C# OpenVINO部署yolov8图像分类模型
  • [C/C++] -- 二叉树