Problem Description

Harry Potter has a difficult homework. Given a rectangular table, consisting of n × m cells. Each cell of the table contains the integer. Harry knows how to use two spells: the first spell change the sign of the integers in the selected row, the second — in the selected column. Harry's task is to make non-negative the sum of the numbers in each row and each column using these spells.

Alone, the boy can not cope. Help the young magician!

Input

The first line contains two integers n and m (1 ≤ n,  m ≤ 100) — the number of rows and the number of columns.

Next n lines follow, each contains m integers: j-th integer in the i-th line is ai, j (|ai, j| ≤ 100), the number in the i-th row and j-th column of the table.

The rows of the table numbered from 1 to n. The columns of the table numbered from 1 to m.

Output

In the first line print the number a — the number of required applications of the first spell. Next print a space-separated integers — the row numbers, you want to apply a spell. These row numbers must be distinct!

In the second line print the number b — the number of required applications of the second spell. Next print b space-separated integers — the column numbers, you want to apply a spell. These column numbers must be distinct!

If there are several solutions are allowed to print any of them.

Examples

Input

4 1
-1
-1
-1
-1

Output

4 1 2 3 4 
0

Input

2 4
-1 -1 -1 2
1 1 1 1

Output

1 1 
1 4

题意:给出一个 n*m 的矩阵,其元素绝对值均小于 100,现在可以让某一行或一列的所有数取反,要求构造一个解,使得每一行每一列的和都是非负数

思路:

首先统计矩阵每一行每一列的和,然后去枚举行列的和,当某一行的值小于 0,那么将这一行直接翻转,再对行列和进行相应处理,直到没有负值

由于矩阵元素最多为 100 个,元素值范围为 -100~100,因此,整个矩阵和的范围为 [-10000,10000],故而当某一行列的和为负时,将其进行翻转后,和至少 +2,因此最多枚举 100^4 即可令整个矩阵的行列和为正

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 5000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;LL a[N][N];
LL sumRow[N],sumCol[N];
int row[N],col[N];
vector<int>resRow,resCol;
int main() {int n,m;scanf("%d%d",&n,&m);for(int i=1; i<=n; i++) {for(int j=1; j<=m; j++) {scanf("%lld",&a[i][j]);sumRow[i]+=a[i][j];sumCol[j]+=a[i][j];}}while(true) {for(int i=1; i<=n; i++) {if(sumRow[i]<0) {sumRow[i]=0;for(int j=1; j<=m; j++) {a[i][j]=-a[i][j];sumRow[i]+=a[i][j];sumCol[j]=sumCol[j]-(-a[i][j])+a[i][j];}row[i]+=1;}}for(int j=1; j<=m; j++) {if(sumCol[j]<0) {sumCol[j]=0;for(int i=1; i<=n; i++) {a[i][j]=-a[i][j];sumCol[j]+=a[i][j];sumRow[i]=sumRow[i]-(-a[i][j])+a[i][j];}col[j]+=1;}}bool flag=false;for(int i=1; i<=n; i++) {if(sumRow[i]<0) {flag=true;}}for(int i=1; i<=m; i++) {if(sumCol[i]<0) {flag=true;}}if(!flag)break;}int num1=0,num2=0;for(int i=1; i<=n; i++) {if(row[i]%2==1) {resRow.push_back(i);num1++;}}for(int i=1; i<=m; i++) {if(col[i]%2==1) {resCol.push_back(i);num2++;}}printf("%d ",num1);for(int i=0; i<num1; i++)printf("%d ",resRow[i]);printf("\n");printf("%d ",num2);for(int i=0; i<num2; i++)printf("%d ",resCol[i]);printf("\n");return 0;
}

The table(CF-226D)相关推荐

  1. MySQL建立外键出现Can't create table‘..’ (errno:150)问题(简单易懂版)

    今天创建表时出现了Can't create table'..' (errno:150),经过排查发现是关联的B表中有一条测试数据,其中的值不在A表所关联字段的范围 会造成error:150的原因大概有 ...

  2. 【解题报告】随便练练二(CF 2300)

    [解题报告]随便练练二(CF 2300) A:Antimatter | CF383D 题意 思路 :DP 代码 B:Physical Education Lessons | CF915E 题意 思路一 ...

  3. LeetCode hard 668. Kth Smallest Number in Multiplication Table(二分答案)

    题目:https://leetcode.com/problems/kth-smallest-number-in-multiplication-table/description/ Kth Smalle ...

  4. 【STL学习】自己动手C++编程实现hash table(散列表)

    SGI STL中散列表采用链接法解决冲突.结构中维护了一个vector,vector中每一个元素称为一个桶(bucket),它包含的是一个链表的第一个节点. 下面代码展示了自己编程实现的hash ta ...

  5. SAP HANA Temporal Table (历史表)

    引自<SAP HANA 实战> 刘刚 舒戈 著  2.4.2.3 除了行.列存储的数据库表外,HANA还提供了 Temporal Table(简称历史表或临时表).它和普通表的区别是所有历 ...

  6. Commentator problem(CF 2)

    题目链接 题目大意: 给定三个圆,询问是否存在点满足该点与三个圆夹角均相等,若存在多组解返回夹角最大值. 圆外一点到两圆夹角均相等: 即 sina = sinb = r1 / d1 = r2 / d2 ...

  7. PE教程6: Import Table(引入表)(看雪)

    首先,您得了解什么是引入函数.一个引入函数是被某模块调用的但又不在调用者模块中的函数,因而命名为"import(引入)".引入函数实际位于一个或者更多的DLL里.调用者模块里只保留 ...

  8. 数据库学习 - create table(创建表)

    创建table 简单语法形式: create table 表名(列名 数据类型[primary key|unique] [not null] [,列名 数据类型[not null],...]); &q ...

  9. Codeforces Round #323 (Div. 2): C. GCD Table(思维题)

    题意: 给你一个长度为n的序列a[1]~a[n], 之后用这个序列生成一个n*n的矩阵,其中矩阵第i行第i列的值为a[i],第i行第j列(j!=i)的值为Gcd(a[i], a[j]),现在给你一个矩 ...

  10. MySQL错误:Can't create table‘..’ (errno:150)解决方案

    场景 含有学生表s(sno,sname,sage).课程表c(cno,cname) 选课表(sc)创建时,设置(sno,cno)为主键.sno和cno为外键 drop table if exists ...

最新文章

  1. Java基础系列--Executor框架(一)
  2. python三:if...else
  3. 微信公众平台开发教程(八)Session处理
  4. SAP Spartacus里的defaultOccProductConfig
  5. (Kali)BackTrack-linux安全***测试系统盘
  6. ThreadLocal初识
  7. 解决tomcat控制台以及localhost Log和Catalina Log乱码问题
  8. docker daemon配置阿里云加速器
  9. 为什么打工人 996 会猝死,而企业家 007 却不会?
  10. 决策树之CART(分类回归树)详解
  11. unity怎么显示骨骼_Unity3d教程:骨骼动画介绍
  12. 用HTML和CSS做箭头
  13. javascript顺序点击文字验证
  14. android kl文件编辑,Android手机固件的简单修改教程
  15. 在虚拟机中开启VT功能
  16. 2021年度软件企业 100 强榜单(附全名单)看看有你家公司没
  17. 解决 手机使用10193 拨打国际长途时候 国际拨号助手 自动增加区号的问题
  18. 子域名收集 -- Esd
  19. 故事工厂在DuerOS技能开发中的应用——百度2019AI开发者大会DuerOS公开课摘要解读之四...
  20. 分享 | 会 Python 的人究竟怎么炒股?

热门文章

  1. 西方餐厅的顶级食材,被中国人干到了“白菜价”
  2. 谷歌、脸书、魔兽世界都在用!InnoDB是什么?有哪些关键特性?
  3. 七夕关爱单身狗程序猿:4本书给你一个完整的脱单秘籍
  4. 主管问我:你以为单元测试,只是测试吗?
  5. pick王菊?作为“菊外人”的程序员能做点什么?
  6. 用内卷搞垮团队!您可真行
  7. 火热报名 |【 6月26日上海站】VCEC沙龙第5期:智能化技术在质量场景落地和实践...
  8. Linux下几种文件传输命令 sz rz sftp scp
  9. 职场 | 工作五年之后,对技术和业务的思考
  10. GitHub的基础使用入门