Codeforces A. Orchestra
A. Orchestra
2 seconds
256 megabytes
standard input
standard output
Paul is at the orchestra. The string section is arranged in an r × c rectangular grid and is filled with violinists with the exception of nviolists. Paul really likes violas, so he would like to take a picture including at least k of them. Paul can take a picture of any axis-parallel rectangle in the orchestra. Count the number of possible pictures that Paul can take.
Two pictures are considered to be different if the coordinates of corresponding rectangles are different.
The first line of input contains four space-separated integers r, c, n, k (1 ≤ r, c, n ≤ 10, 1 ≤ k ≤ n) — the number of rows and columns of the string section, the total number of violas, and the minimum number of violas Paul would like in his photograph, respectively.
The next n lines each contain two integers xi and yi (1 ≤ xi ≤ r, 1 ≤ yi ≤ c): the position of the i-th viola. It is guaranteed that no location appears more than once in the input.
Print a single integer — the number of photographs Paul can take which include at least k violas.
2 2 1 1
1 2
4
3 2 3 3
1 1
3 1
2 2
1
3 2 3 2
1 1
3 1
2 2
4
We will use '*' to denote violinists and '#' to denote violists.
In the first sample, the orchestra looks as follows
*#
**
Paul can take a photograph of just the viola, the 1 × 2 column containing the viola, the 2 × 1 row containing the viola, or the entire string section, for 4 pictures total.
In the second sample, the orchestra looks as follows
#*
*#
#*
Paul must take a photograph of the entire section.
In the third sample, the orchestra looks the same as in the second sample.
思路:前缀数组和,然后暴力枚举两两点对,以上边的点为左上顶点下边的点为右下顶点,
as[x][y]-as[x][j-1]-(as[i-1][y]-as[i-1][j-1]);就为这个矩阵内的符合要求的点的个数,判断下是否这个矩阵成立即可复杂度n4;
1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<math.h>
6 #include<queue>
7 #include<map>
8 using namespace std;
9 typedef long long LL;
10 int ans[20][20]= {0};
11 int as[20][20];
12 int bs[20][20];
13 int main(void)
14 {
15 int i,j,k,p,q,n,m;
16 int x,y;
17 cin>>n>>m>>p>>q;
18 memset(ans,0,sizeof(ans));
19
20 for(i=0; i<p; i++)
21 {
22 cin>>x>>y;
23 ans[x][y]=1;
24 }
25 for(i=1; i<=n; i++)
26 {
27 for(j=1; j<=m; j++)
28 {
29 as[i][j]=ans[i][j]+as[i][j-1];
30 }
31 }
32 for(i=1; i<=m; i++)
33 {
34 for(j=1; j<=n; j++)
35 {
36 as[j][i]+=as[j-1][i];
37 }
38 }
39 int cnt=0;
40 for(i=1;i<=n;i++)
41 {
42 for(j=1;j<=m;j++)
43 {
44 for(x=i;x<=n;x++)
45 {
46 for(y=j;y<=m;y++)
47 {
48 int uu=as[x][y]-as[x][j-1]-(as[i-1][y]-as[i-1][j-1]);
49 if(uu>=q)
50 {
51 cnt++;
52 }
53 }
54 }
55 }
56 }
57 cout<<cnt<<endl;
58 return 0;
59 }
最新文章
- Javaweb——过滤器映射
- C#的yield关键字
- 查看oracle当前session
- Android开发之初识Camera图像采集
- SQL给字段加上统一的某个字符
- 利用no_merge优化
- Linux系统中如何添加自己的库文件路径
- redhat5安装phantomjs
- php 引用一点要小心使用
- ROS Indigo在ubuntu1404上的安装方法
- HashMap 深入分析
- SQL baseline_11g
- Ajax请求传递数组参数
- IP地址查询接口API
- placeholder的使用
- Spring点滴四:Spring Bean生命周期
- XAMPP启动mysql问题
- 启动secondarynamenode时报错
- 写shell脚本需要注意哪些地方----零基础必看
- 【原创】6. 在MYSQL++中实现SQL语法中的NULL