Yet Another Median Task Gym
来源:互联网 发布:瑞尔森大学怎么样知乎 编辑:程序博客网 时间:2024/06/05 03:27
数据挺水
直接排序复杂度有点高,可以二分中位数
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <set>#include <map>#include <stack>#include <queue>#include <ctype.h>#include <vector>#include <algorithm>#include <time.h>// cout << " === " << endl;using namespace std;typedef long long ll;const int maxn = 800 + 7;const ll INF = 0x3f3f3f3f3f3f3f3f, mod = 1e9+7;int n, m, t;int a[maxn][maxn];void init() { scanf("%d %d", &n, &m); for(int i = 1; i <= n; ++i) { for(int j = 1; j <= n; ++j) scanf("%d", &a[i][j]); }}void solve() { int x1, x2, y1, y2; for(int i = 0; i < m; ++i) { scanf("%d %d %d %d", &x1, &y1, &x2, &y2); int cnt = (x2-x1+1)*(y2-y1+1); t = (cnt+1)/2 - 1; ll l_ = INF, r_ = -INF; int mid, ans; for(int i = x1; i <= x2; ++i) { for(int j = y1; j <= y2; ++j) l_ = min(l_, (ll)a[i][j]), r_ = max(r_, (ll)a[i][j]); } l_ = (int)l_, r_ = (int)r_; while(l_ <= r_) { int num = 0; mid = (l_ + r_) / 2; for(int i = x1; i <= x2; ++i) { for(int j = y1; j <= y2; ++j) if(a[i][j] < mid) num++; } if(num <= t) { l_ = mid+1; ans = mid; } else if(num > t) r_ = mid-1; } printf("%d\n", ans); }}int main() { init(); solve(); return 0;}
阅读全文
1 0
- Yet Another Median Task Gym
- Yet Another Median Task Gym
- Gym 100741G Yet Another Median Task
- Yet Another Median Task
- Codeforces Gym 100741G Yet Another Median Task 二分乱搞
- Gym 100735 - I. Yet another A + B
- Gym 100735I Yet another A + B (java大数)
- GYM 100488 Yet Another Goat in the Garden
- GYM 100488 A. Yet Another Goat in the Garden(计算几何)
- 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(模拟)
- Yet Another Multiple Problem
- Yet Another PhotoMosaic Generator
- Yet Another Analog Clock
- Yet Another Lambda Tutorial
- Codeforces868F Yet Another MinimizationProblem
- Yet Another Web Framework 1
- Yacc: Yet Another Compiler-Compiler
- hdu 6153 A Secret【KMP/想法题】
- 影梭客户端原理剖析
- Java进阶之路【代码篇】——《CleanCode》编程规则精编(10) 并发
- HTTP协议详解
- centos7初使用
- Yet Another Median Task Gym
- SEO
- Clean Code 代码整洁之道
- 数据库例子
- Silver Cow Party (SPFA+最短路径)
- 因结婚彩礼起积怨 山西一男子行凶致1死5伤
- 并发之秒杀
- CS231 笔记 卷积神经网络
- 算法提高 ADV-73 数组输出