Saddle Point ZOJ - 3955 题意题
Chiaki has an n × m matrix A. Rows are numbered from 1 to n from top to bottom and columns are numbered from 1 to m from left to right. The element in the i-th row and the j-th column is Ai, j.
Let M({i1, i2, ..., is}, {j1, j2, ..., jt}) be the matrix that results from deleting row i1, i2, ..., is and column j1, j2, ..., jt of A and f({i1, i2, ..., is}, {j1, j2, ..., jt}) be the number of saddle points in matrix M({i1, i2, ..., is}, {j1, j2, ..., jt}).
Chiaki would like to find all the value of f({i1, i2, ..., is}, {j1, j2, ..., jt}). As the output may be very large ((2n - 1)(2m - 1) matrix in total), she is only interested in the value
Note that a saddle point of a matrix is an element which is both the only largest element in its column and the only smallest element in its row.
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains four integers n and m (1 ≤ n, m ≤ 1000) -- the number of rows and the number of columns.
Each of the next n lines contains m integer Ai, 1, Ai, 2, ..., Ai, m (1 ≤ Ai, j ≤ 106), where Ai, j is the integer in the i-th row and the j-th column.
It is guaranteed that neither the sum of all n nor the sum of all m exceeds 5000.
<h4< dd="">Output
For each test case, output an integer denoting the answer.
<h4< dd="">Sample Input
2
2 2
1 1
1 1
4 5
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
<h4< dd="">Sample Output
4
465 这题就是难在读题
我和我队友看了半天这题 觉得这题不能写
后来看题解 知道题意后 这题真的傻逼
题意
一个n*m的矩阵,问n*m个点能否在去掉某些行、列的情况下,成为马鞍点。
马鞍点是行中最小 列中最大的元素(严格大于和小于),问所有 点能够成为马鞍点的方式总数。
然后按每个点算一次贡献就好了
行中最小 就把每一行中比这个值大的数目 每一次有两种状态 选和不选
列中最大 就把每一行中比这个值小的数目 每一次有两种状态 选和不选
每个点的贡献就是 expmod(2, cnt1) * expmod(2, cnt2)
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define fuck(x) cout<<"["<<x<<"]"<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("DATA.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#pragma comment (linker,"/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x7fffffff;
const int mod = 1e9 + ;
const int maxn = 1e3 + ;
int mp[maxn][maxn], L[maxn][maxn], H[maxn][maxn];
int t, n, m;
LL expmod(LL a, LL b) {
LL ret = ;
while(b) {
if (b & ) ret = ret * a % mod;
a = a * a % mod;
b = b >> ;
}
return ret;
}
int main() {
sf(t);
while(t--) {
sff(n, m);
for (int i = ; i < n ; i++) {
for (int j = ; j < m ; j++) {
sf(mp[i][j]);
L[i][j] = mp[i][j];
H[j][i] = mp[i][j];
}
}
for (int i = ; i < n ; i++) sort(L[i], L[i] + m);
for (int i = ; i < m ; i++) sort(H[i], H[i] + n);
LL ans = ;
for (int i = ; i < n ; i++) {
for (int j = ; j < m ; j++) {
int cnt1 = m - (upper_bound(L[i], L[i] + m, mp[i][j]) - L[i]);
int cnt2 = lower_bound(H[j], H[j] + n, mp[i][j]) - H[j];
ans = (ans + expmod(, cnt1) * expmod(, cnt2) % mod) % mod;
}
}
printf("%lld\n", ans);
}
return ;
}
Saddle Point ZOJ - 3955 题意题的更多相关文章
- Saddle Point ZOJ - 3955(求每个值得贡献)
题意: 给出一个矩阵,删掉一些行和列之后 求剩下矩阵的鞍点的总个数 解析: 对于每个点 我们可以求出来 它所在的行和列 有多少比它大的 设为a 有多少比它小的 设为b 然后对于那些行和列 都有两种操 ...
- Day7 - C - Saddle Point ZOJ - 3955
Chiaki has an n × m matrix A. Rows are numbered from 1 to n from top to bottom and columns are numbe ...
- ZOJ 3955:Saddle Point(思维)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3955 题意:给出一个n*m的矩阵,定义矩阵中的特殊点Aij当且仅当Aij是 ...
- ZOJ 3955 Saddle Point 校赛 一道计数题
ZOJ3955 题意是这样的 给定一个n*m的整数矩阵 n和m均小于1000 对这个矩阵删去任意行和列后剩余一个矩阵为M{x1,x2,,,,xm;y1,y2,,,,,yn}表示删除任意的M行N列 对于 ...
- ZOJ 3955 Saddle Point
排序. 枚举每一个格子,计算这个格子在多少矩阵中是鞍点,只要计算这一行有多少数字比他大,这一列有多少数字比他小,方案数乘一下就是这个格子对答案做出的贡献. #include<bits/stdc+ ...
- zoj 3657 策略题 easy
http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=4880 由于是要去牡丹江.是浙大出题,所以找了份浙大的题,第一道水题做的就不顺 ...
- zoj 3647 智商题
此题就是求格点中三角形的个数. 就是找出三点不共线的个数. n*m的矩形中有(n+1)*(m+1)个格点. 选出三个点的总个数为:C((n+1)*(m+1),3). 减掉共线的情况就是答案了. 首先是 ...
- D - Matrix Multiplication ZOJ - 2316 规律题
Let us consider undirected graph G = which has N vertices and M edges. Incidence matrix of this grap ...
- 九度OJ 1032:ZOJ (基础题)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4569 解决:2561 题目描述: 读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当某个字符用完时,剩下的 ...
随机推荐
- 技本功丨知否知否,Redux源码竟如此意味深长(下集)
上集回顾 Redux是如何使用的?首先再来回顾一下这个使用demo(谁让这段代码完整地展示了redux的使用) 如果有小伙伴对这段代码不是很理解的话,建议先去学习Redux的使用再来看这篇源码,这样更 ...
- 机器学习-线性回归LinearRegression
概述 今天要说一下机器学习中大多数书籍第一个讲的(有的可能是KNN)模型-线性回归.说起线性回归,首先要介绍一下机器学习中的两个常见的问题:回归任务和分类任务.那什么是回归任务和分类任务呢?简单的来说 ...
- python SyntaxError: Non-ASCII character '\xe8' in file C:\Users\nwpujun\PycharmProjects\projects\hrl1\hrlAgent\src\li_nn.py on line 52
解决方法:在文件头部加上这样的一句话 # -*- coding: utf-8 -*- 注意:加在其他的位置可能没用,我就是这样的
- java poi技术读取到数据库
https://www.cnblogs.com/hongten/p/java_poi_excel.html java的poi技术读取Excel数据到MySQL 这篇blog是介绍java中的poi技术 ...
- Jquery复选框
Jquery复选框 1.checkbox list选择 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E ...
- 软件工程-东北师大站-第二次作业psp
1.本周PSP 2.本周进度条 3.本周累计进度图 代码累计折线图 博文字数累计折线图 本周PSP饼状图
- Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset Trie
题目链接: http://codeforces.com/contest/706/problem/D D. Vasiliy's Multiset time limit per test:4 second ...
- Linux内核策略介绍学习笔记
主要内容 硬件 策略 CPU 进程调度.系统调用.中断 内存 内存管理 外存 文件IO 网络 协议栈 其他 时间管理 进程调度 内核的运行时间 系统启动.中断发生.系统调用以及内核线程. 进程和线程的 ...
- 最近面试js部分试题总结
二,JavaScript面试题总结 1,首先是数组去重算法:给一个数组,去掉重复值 (function() { var arr = [1, 2, 3, 3, 4, ]; function unique ...
- 使用LoadRunner脚本采集Linux性能数据
前面介绍过在LoadRunner的Java协议实现“使用SSH连接Linux”.下面的脚本,是在LoadRunner里连接Linux/Unix远程服务器,收集其磁盘IO的负载到测试结果. 涉及到三个知 ...