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 }
Codeforces A. Orchestra的更多相关文章
- codeforces A. Orchestra B. Island Puzzle
A. Orchestra time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces 627E - Orchestra(双向链表,思维题)
Codeforces 题目传送门 & 洛谷题目传送门 下设 \(n,m\) 同阶. 首先有一个傻子都会的暴力做法,枚举矩形的上.下边界 \(l,r\),考虑集合多重集 \(S=\{y|x\in ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A. Orchestra 水题
A. Orchestra 题目连接: http://www.codeforces.com/contest/635/problem/A Description Paul is at the orches ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- UE4之Slate:App默认窗口的创建流程
UE4版本:4.24.3源码编译 Windows10 + VS2019开发环境 在先前分享的基础上,现在来梳理下App启动时默认窗口的创建流程,以及相关的类.对象之间的抽象层级: 纯C++工程配置 S ...
- Windows cmd 命令行基本操作
Windows cmd 命令行基本操作 1. 进入到指定根目录 注意:不区分大小写 例如进入到 D 盘 2. 进入到指定的目录 例如 (如果目录文件名太长,可以使用 tab 键来自动补全.重复按可以进 ...
- 商业爬虫学习笔记day4
一.获取登录后页面信息的两种方法 1.第一种方法: 人为把有效cookies加到请求头中,代码如下 import urllib.request # 确定url url = "https:// ...
- Swift alert 倒计时
let title: String = "您的开奖时间为" let time: String = "2017-10-23 12:23:18" let count ...
- Output of C++ Program | Set 8
Predict the output of following C++ programs. Question 1 1 #include<iostream> 2 using namespac ...
- Default Assignment Operator and References
We have discussed assignment operator overloading for dynamically allocated resources here . This is ...
- ACE_Message_Block实现浅析
ACE_Message_Block实现浅析1. 概述ACE_Message_Block是ACE中很重要的一个类,和ACE框架中的重要模式的实现 如ACE_Reactor, ACE_Proactor, ...
- 基于spring sringmvc mybatis 做的导入导出
导入 pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://ww ...
- 【力扣】649. Dota2 参议院
Dota2 的世界里有两个阵营:Radiant(天辉)和 Dire(夜魇) Dota2 参议院由来自两派的参议员组成.现在参议院希望对一个 Dota2 游戏里的改变作出决定.他们以一个基于轮为过程的投 ...
- 制作一个有趣的涂鸦物联网小项目(涂鸦模组SDK开发 CBU BK7231N WiFi+蓝牙模组 HSV彩色控制)
实现的功能: l APP控制月球灯 l 本地月球灯控制 l APP控制"大白"颜色,实现各种颜色变身 l 门状态传感器状态APP显示 l 网络状态指示灯,连接服务器长亮, ...