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. 请问:hive中avg聚合函数会使用到combiner功能吗?
  2. apache加载php配置
  3. printf 格式控制符的完整格式
  4. 使用NPOI库导入导出EXCEL
  5. SpringBoot 计划任务
  6. 在Chrome78浏览器上如何实现自动播放音视频
  7. python读取文件名包含某字符的文件_python 读写文件时判断文件名是否包含某字符串...
  8. 3-8-循环队列-栈和队列-第3章-《数据结构》课本源码-严蔚敏吴伟民版
  9. SpringMVC使用json格式之间的转换的工具类
  10. php冒泡排序图解,PHP冒泡排序(Bubble Sort)代码实现图解
  11. jdk11的class反射机制,将newInstance()方法设置为了不建议使用了,怎么通过反射创建新的对象
  12. [教程]配置青鸟云Web服务器
  13. 使用插件对温度植被干旱指数进行计算
  14. android字体带下划线
  15. java ee中如何编译,【Javaweb】于Eclipse for JavaEE中编译一个项目Tomcat下的webap
  16. 区块链技术+二维码,打造爱码物联产品质量溯源软件
  17. 生命不息,折腾不止——新的起点
  18. python 利用win32 打印文件
  19. 关于django模型语法里面的一些坑。系统报错:Unknown command: 'validate' Type 'manage.py help' for usage.
  20. matlab中h无穷状态反馈控制,求教 :用LMI方法求倒立摆H无穷状态反馈控制器程序...

热门文章

  1. 手把手教你用Python读取Excel
  2. STM32之SPI从机例程
  3. 新入职了一个卷王 , 天天加班12点!张口闭口就手写spring , 太让人崩溃了......
  4. 不要等到离职,才明白这些道理
  5. 面试官:面对业务量增长10倍、100倍怎么处理? 当场哭出声。。
  6. 有位哥们坚持不用微服务架构,被老板踢出了群聊···
  7. 儒枭:我看技术人的成长路径
  8. Docker 架构原理及简单使用
  9. 程序员的三门课之项目管理篇
  10. MAVEN自定义项目骨架