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 .
• 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.
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
大水题
但是就是读入的时候有点迷,要求二进制读入。
语法问题吧?
• 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; }
相关文章推荐
- android异常Unable to instantiate activity ComponentInfo解决方法
- Android应用程序资源的编译和打包过程分析
- http协议中content-length 以及chunked编码分析
- ICSharpCode.SharpZipLib.dll 使用方法
- Win7、Ubuntu双系统正确卸载Ubuntu系统
- Notification
- QT中QWidget、QDialog及QMainWindow的区别
- [leetcode] 20.Valid Parentheses
- Qt QWaitCondition的应用
- 使用定时器去抖
- Http编程(二)使用Apache 的API实现
- python中get、post数据
- synchronized初步
- ZOJ3818--Pretty Poem(暴力)
- DllImport调用系统DLL的方法
- Android_布局优化
- poj 1091 跳蚤(最大公约数原理+容斥原理)
- IP地址转整数
- PHP中的常量
- uvalive4835(模拟)