UVAlive 6426 Count【读入】

2024-08-24 11:38
文章标签 uvalive 6426 count 读入

本文主要是介绍UVAlive 6426 Count【读入】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

You have:
• A matrix of natural numbers, with the property that all rows and all columns are sorted in ascending order (i.e. A[i,j]A[i1,j] and A[i,j]A[i,j1] for all i, j)
• One or several pairs of numbers (X,Y) with the property that YX . For each (X,Y) pair, count how many numbers from the matrix are greater than or equal to X but smaller than or equal to Y .

Input

The input file is a binary file containing 32-bit integer numbers. The input file consists of:
• One integer N representing the number of rows (no more than 10000)
• One integer M representing the number of columns (no more than 10000)
N×M integers, representing the values from the matrix, row by row
• An unspecified number of integers, representing the (X,Y) pairs, one pair at a time. There will be at least one pair and at most 100 pairs in the file — and there will not be an incomplete pair at the end of the file.

Output

For each pair you should write to standard output a value representing how many numbers in the matrix are greater than or equal to X but smaller than or equal to Y .
Note: The sample input is here in text form, not binary, for obvious reasons
Sample Input

2 4
1 5 10 10
2 10 20 99
10 99
2 9
100 1000
10 10
Sample Output
5
2
0
3


大水题
但是就是读入的时候有点迷,要求二进制读入。
语法问题吧?

#include<bits/stdc++.h>
#define MAXN 5010
#define MAXE 500000
typedef long long LL;
using namespace std;
int A[10005][10005];
bool read(int *a, int n){return fread(a,4,n,stdin);
}
int main(){int n, m;read(&n,1); read(&m,1);for(int i=0;i<n;i++){read(A[i],m);}int l,r;while(read(&l,1)&&read(&r,1)){int ans=0;for(int i=0;i<n;i++){int lpos=lower_bound(A[i],A[i]+m,l)-A[i];int rpos=upper_bound(A[i],A[i]+m,r)-A[i];if(rpos>lpos) ans+=rpos-lpos;}printf("%d\n",ans);}return 0;
}

这篇关于UVAlive 6426 Count【读入】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1102372

相关文章

leetcode#38. Count and Say

The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 12. 113. 214. 12115. 111221 1 is read off as “one 1” or 11. 11 is read off

004: VTK读入数据---vtkImageData详细说明

VTK医学图像处理---vtkImageData类 目录 VTK医学图像处理---vtkImageData类 简介: 1 Mricro软件的安装和使用 (1) Mricro安装 (2) Mricro转换DICOM为裸数据  2 从硬盘读取数据到vtkImageData 3 vtkImageData转RGB或RGBA格式 4 练习 总结 简介:         对于医

将DIB/bitmap读入内存并转为 halcon hobject

问题由来:在mfc halcon混合编程中,发现halcon::readimage() 函数读取图片(8位8M/bmp)至少200ms,当然24位 32位bmp 倍数所消耗的时间倍数上涨。那么有没有什么方法加快读取速度?目前发现一个亲测可行的方式:  1、通过 DIBAPI 读取图片,下载可转到点击打开链接,赚点积分 2、获取所读读片的图像数据的首地址,注意非结构头地址 3、通过halcon

《Learning To Count Everything》CVPR2021

摘要 论文提出了一种新的方法来解决视觉计数问题,即在给定类别中仅有少量标注实例的情况下,对任何类别的对象进行计数。将计数问题视为一个少样本回归任务,并提出了一种新颖的方法,该方法通过查询图像和查询图像中的少量示例对象来预测图像中所有感兴趣对象的存在密度图。此外,还提出了一种新颖的适应策略,使网络能够在测试时仅使用新类别中的少量示例对象来适应任何新的视觉类别。为了支持这一任务,作者还引入了一个包含

class _ContiguousArrayStorage deallocated with non-zero retain count

Xcode报错 : Object 0x11c614000 of class _ContiguousArrayStorage deallocated with non-zero retain count 2. This object's deinit, or something called from it, may have created a strong reference to self w

LeetCode - 38. Count and Say

38. Count and Say  Problem's Link  ---------------------------------------------------------------------------- Mean:  题目意思太晦涩。 1 读出来 就是“1个1” 所以记为“11” 11 读出来 就是“2个1” 所以记为“21” 21 读出来 就是“1个

【UVALive】6709 Mosaic 二维线段树

传送门:【UVALive】6709 Mosaic 题目大意: 每次选择矩阵中的一个点,求以他为中心,边长为D(D一定是奇数)的矩阵中的最小值min和最大值max,输出ans =(min+max)/ 2(向下取整)。然后将该点的值修改为ans。 题目分析: 赤果果的二维线段树单点修改、区间查询。 又一次学习了线段树,发现原来所有的更新操作全部放在二维中即可。 很不错,一定要经常看看,温

【UVALive】3887 Slim Span 枚举+最小生成树

传送门:【UVALive】3887 Slim Span 题目大意:给出一个n(2 <= n <= 100)个结点的无向图,找一棵苗条度(最大边减最小边的值)最小的生成树。图中不含自环或重边。 题目分析:枚举最小边求生成树即可。模板用用萌萌哒~ 代码如下: #include <cstdio>#include <cstring>#include <algorit

【UVALive】5713 Qin Shi Huang's National Road System 最小生成树

传送门:【UVALive】5713 Qin Shi Huang's National Road System 题目大意:秦朝有n个城市,需要修建一些道路使得任意两个城市之间都可以连通。道士徐福声称他可以用法术修路,不花钱,也不用劳动力,但只能修一条路,因此需要慎重选择用法术修哪一条路。秦始皇不仅希望其他道路的总长度B尽量短(这样可以节省劳动力),还希望法术连接的两个城市的人口之和A尽量大,因此下

【UVALive】3661 Animal Run 平面图最小割 最短路

传送门:【UVALive】3661 Animal Run 题目大意:给你一个n*m个点的网格图,其中动物园在左上角,动物们的目的地在右下角,现在你需要派出一些工作人员拦截某些边使得没有一只动物能到达右下角,已知每个单元网格中存在左上角到右下角的对角线,网格中的边以及对角线都是双向的,每条道路有个权值,表示拦截这条边所需要的工作人员数。你的任务是派尽量少的工作人员使得达到目的。 题目分析