Gym 100741G Yet Another Median Task
来源:互联网 发布:鲱鱼罐头 淘宝 编辑:程序博客网 时间:2024/06/05 10:38
题意:
给出一个n*n的矩阵。然后有很多操作,每次给你两个点(x1,y1)和(x2,y2),求出这两个点作为新矩阵的左上角和有下角,求出新矩阵所有值的中点。
直接暴力,用scanf输入,然后就爆过了,用cin cout会超时。
用nth_element函数。
使用方法:nth_element(start, start+n, end)
使第n大元素处于第n位置(从0开始,其位置是下标为n的元素),并且比这个元素小的元素都排在这个元素之前,比这个元素大的元素都排在这个元素之后,但不能保证他们是有序的。
#include <iostream>#include <string>#include <cmath>#include <algorithm>#include <cstring>#include <cstdio>using namespace std;int a[1000005];int g[1005][1005];int main(){ int n, q; scanf("%d%d", &n, &q); for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { scanf("%d", &g[i][j]); } } int x1, y1, x2, y2; while(q--) { scanf("%d%d%d%d",&x1, &y1, &x2, &y2); int cnt = 0; for(int i = x1; i <= x2; i++) { for(int j = y1; j <= y2; j++) { a[cnt++] = g[i][j]; } } nth_element(a, a+(cnt-1)/2, a+cnt); printf("%d\n", a[(cnt-1)/2]); //cout << a[(cnt-1)/2] << endl; } return 0;}
阅读全文
0 0
- Gym 100741G Yet Another Median Task
- Codeforces 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
- CF 903G. Yet Another Maxflow Problem
- Gym 100735I Yet another A + B (java大数)
- GYM 100488 Yet Another Goat in the Garden
- 【矩阵快速幂】UVA 10698 G - Yet another Number Sequence
- 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
- Windows未能启动amd_xata.sys数字签名无法验证怎么解决
- Java匿名内部类可以访问外部类的成员;若访问所在方法的成员,那个成员必须具有final属性
- java邮件发送
- Mongodb 3.4配置搭建高可用集群(1)
- ubuntu下查看CPU,GPU内存使用率
- Gym 100741G Yet Another Median Task
- 在一定时间内连续双击返回键退出应用
- JSP——请求重定向与请求转发
- 阿里云linux系统安装mysql
- ssh和ssm的对比
- Thinkphp 5.0 命名空间
- c/c++程序编译连接过程
- Spring IoC(控制反转)和DI(依赖注入)的理解
- 【POJ】2976 Dropping tests(二分)