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 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- 准确率,召回率,F值,ROC,AUC
度量表 1.准确率 (presion) p=TPTP+FP 理解为你预测对的正例数占你预测正例总量的比率,假设实际有90个正例,10个负例,你预测80(75+,5-)个正例,20(15+,5-)个负例 ...
- 学习 DDD - 通用语言的模式
大家好,我是霸戈,这周学习了一些关于领域驱动设计的知识 ,对比较深刻的地方做了不少笔记,分享给大家. 在日常需求讨论的时候,经常会碰到一个需求会议开了一个多小时还没有达成共识.作为业务方(领域专家)明 ...
- 取gridview中textbox的值【C#】
<asp:GridView ID="gridView" runat="server" OnRowCommand="gridView_RowCom ...
- C语言中的字符和整数之间的转换
首先对照ascal表,查找字符和整数之间的规律: ascall 控制字符 48 0 49 1 50 2 51 3 52 4 53 5 54 6 55 7 56 8 ...
- Applescript快速入门及OmniFocus每日md报告开发
本篇主要记录 Applescript 基础语法,以及利用 applescript 生成 omnifocus 每日报告 从 windows 转换到 macos,最近一直在不断折腾,这两天浏览 githu ...
- 疯了吧!这帮人居然用 Go 写“前端”?(二)
作者 | 郑嘉涛(羣青) 来源|尔达 Erda 公众号 前言 上篇我们讲了故事发生的背景,也简单阐述了组件及协议的设想: 一.丰富的通用组件库. 二.组件渲染能力,将业务组件渲染成通用组件 ...
- 用usb线配置直流电机驱动器不能配置成功
原因可能是因为usb线的问题 换了三条usb线. 这三条都是通的,用万用表测试都是通的,但是进行电机配置的时候不行. 猜测原因可能是三条usb线的芯材质不同导致压降不同,使得通信故障.
- c学习 - 第五章:选择结构程序设计
5.2 关系运算符与逻辑运算符 !(非) ^ 高 算术运算符 | 关系运算符 | &&和 || | 赋值运算符 | 低
- 转 Android应用开发必备的20条技能
https://blog.csdn.net/u012269126/article/details/52433237 有些andorid开发人员感觉很迷茫,接下来该去看系统源码还是继续做应用,但是感觉每 ...
- 石墨文档Websocket百万长连接技术实践
引言 在石墨文档的部分业务中,例如文档分享.评论.幻灯片演示和文档表格跟随等场景,涉及到多客户端数据同步和服务端批量数据推送的需求,一般的 HTTP 协议无法满足服务端主动 Push 数据的场景,因此 ...