本文主要是介绍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[i−1,j] and A[i,j]≥A[i,j−1] for all i, j)
• One or several pairs of numbers (X,Y) with the property that Y≥X . 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
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
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【读入】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!