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的顺序输出,当某个字符用完时,剩下的 ...
随机推荐
- lintcode174 删除链表中倒数第n个节点
删除链表中倒数第n个节点 给定一个链表,删除链表中倒数第n个节点,返回链表的头节点. 注意事项 链表中的节点个数大于等于n 您在真实的面试中是否遇到过这个题? Yes 样例 给出链表1->2 ...
- markdown语法介绍
1. 标题类 每级标题用"# title"表示,共支持6级标题: 2. 段落类 1.建议用换行符控制: 2.用"<p></p>"控制: ...
- 您的下个中文网站可以使用的5个高质量中文Webfont
你有没有考虑为什么中文网站的版式风格不像大多数现代英文网站那样丰富?您想了解如何让您的下一个中文网站项目更吸引用户的眼球么?继续往下读吧…… 根据Smashing Magazine进行的一项调查显示 ...
- 2.hadoop基本配置,本地模式,伪分布式搭建
2. Hadoop三种集群方式 1. 三种集群方式 本地模式 hdfs dfs -ls / 不需要启动任何进程 伪分布式 所有进程跑在一个机器上 完全分布式 每个机器运行不同的进程 2. 服务器基本配 ...
- 软件工程 part4 评价3作品
作品1 抢答器 地址: https://modao.cc/app/ylGTXobcMU7ePNi6tY53gG4iraLl0md评价: 挺好玩,但是字体大小是个缺陷,简单大方. 作品2:连连看 软件工 ...
- 20162328蔡文琛week02
学号 20162328 <程序设计与数据结构>第2周学习总结 教材学习内容总结 这周学习了课本中的第二章内容,比起第一章,本章难度有略微底稿,从刚开始的显示字符转变为简单的加减乘除运算,经 ...
- 语音信号处理之动态时间规整(DTW)(转)
这学期有<语音信号处理>这门课,快考试了,所以也要了解了解相关的知识点.呵呵,平时没怎么听课,现在只能抱佛脚了.顺便也总结总结,好让自己的知识架构清晰点,也和大家分享下.下面总结的是第一个 ...
- 字符串数组去重 ["a","b","c","a","b","c"] --> ["a","b","c"]
非正则实现: let str_arr=["a","b","c","a","b","c&qu ...
- spring ioc经典总结
component-scan标签默认情况下自动扫描指定路径下的包(含所有子包),将带有 @Component @Repository @Service @Controller标签的类自动注册到spri ...
- 第二章 持续集成jenkins工具使用之系统基本设置
Jenkin系统初始化成功后,会进入用户设置页面,设置用户信息后即可进入系统,如果没有设置用户,jenkins系统默认的用户是admin,密码administrator 1.1 Con ...