Codeforces Gym 100741G Yet Another Median Task 二分乱搞
来源:互联网 发布:vscode下载插件 编辑:程序博客网 时间:2024/06/05 08:20
给你一个矩阵,q次询问,每次问你子矩阵拉成一维数组排序后的中位数是多少。
二分答案,每次二分把子矩阵扫一遍,看比当前二分数字小的数有多少个。
这样乱搞也能过,真心佩服自己啊~ (小小自恋一把
#include <cstdio>#include <iostream>#include <string.h>#include <string> #include <map>#include <queue>#include <vector>#include <set>#include <algorithm>#include <math.h>#include <cmath>#include <stack>#define mem0(a) memset(a,0,sizeof(a))#define meminf(a) memset(a,0x3f,sizeof(a))using namespace std;typedef long long ll;typedef long double ld;const int maxn=805,inf=0x3f3f3f3f; const ll llinf=0x3f3f3f3f3f3f3f3f; const ld pi=acos(-1.0L); int a[maxn][maxn];int p[maxn*maxn];int main() {int n,i,j,k,l,r,u,d,q;ll m=-llinf,w=llinf;scanf("%d%d",&n,&q);for (i=1;i<=n;i++) {for (j=1;j<=n;j++) {scanf("%d",&a[i][j]);m=max(m,(ll)a[i][j]);w=min(w,(ll)a[i][j]);}}for (i=1;i<=q;i++) {scanf("%d%d%d%d",&u,&l,&d,&r);int lc=w,rc=m,mid,tot=(r-l+1)*(d-u+1),ans;if (tot%2) tot/=2; else tot=tot/2-1;while (lc<=rc) {int cnt=0;mid=(lc+rc)/2;for (j=u;j<=d;j++) {for (k=l;k<=r;k++) {if (a[j][k]<mid) cnt++;}}if (cnt<=tot) lc=mid+1,ans=mid; else {rc=mid-1;} } printf("%d\n",ans);}return 0;}
阅读全文
0 0
- Codeforces Gym 100741G Yet Another Median Task 二分乱搞
- Gym 100741G Yet Another Median Task
- Yet Another Median Task Gym
- Yet Another Median Task Gym
- Yet Another Median Task
- Gym 100735 - I. Yet another A + B
- Yet Another Number Sequence CodeForces
- Codeforces Beta Round #95 (Div. 2) -- E. Yet Another Task with Queens(STL)
- Codeforces Beta Round #95 (Div. 2) E. Yet Another Task with Queens(模拟)
- Codeforces 903G Yet Another Maxflow Problem 线段树+网络流
- Codeforces Round #438:F. Yet Another Minimization Problem(DP决策单调性+二分+莫队)
- CF 903G. Yet Another Maxflow Problem
- Codeforces 392C Yet Another Number Sequence
- Codeforces 392C Yet Another Number Sequence
- codeforces gym 100548G
- CodeForces Gym 100735G
- CodeForces Gym 100735G
- Codeforces-GYM-100923G
- 洛谷P2212 [USACO14MAR]浇地Watering the Fields
- vue2.0 中#$emit,$on的使用详解
- Create
- SQL注入漏洞产生的原因?如何防止?
- 根据字符查找索引
- Codeforces Gym 100741G Yet Another Median Task 二分乱搞
- 使用My97DatePicker插件(现在基本使用前端框架自带的时间控件)
- Oracle中的SQL基础查询语句--下
- IOS TableViewStylePlain header 悬停的解决方案
- 无界队列导致内存耗尽问题一例
- NYOJ18andNYOJ613
- 两种车往两个车站运人的java问题
- UI之UITableView和UITableViewCell
- OSI七层网络模型和Linux四层概念模型