您的位置:首页 > 其它

UVAlive 6426 Count【读入】

2015-08-29 20:18 351 查看
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]A[i,j] ≥ A[i−1,j] and A[i,j]≥A[i,j−1]A[i,j] ≥ A[i,j −1] for all i, j)

• One or several pairs of numbers (X,Y)(X,Y ) with the property that Y≥XY ≥ X. For each (X,Y)(X,Y ) pair, count how many numbers from the matrix are greater than or equal to XX but smaller than or equal to YY .

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×MN ×M integers, representing the values from the matrix, row by row

• An unspecified number of integers, representing the(X,Y) (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 XX but smaller than or equal to YY .

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

大水题

但是就是读入的时候有点迷,要求二进制读入。

语法问题吧?

[code]#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: