CodeForces 635A Orchestra

Description

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.

Input

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.

Output

Print a single integer — the number of photographs Paul can take which
include at least k violas. Sample Input

Input
2 2 1 1
1 2
Output
4
Input
3 2 3 3
1 1
3 1
2 2
Output
1
Input
3 2 3 2
1 1
3 1
2 2
Output
4
先选定起点,再在起点右下选定终点,计算中间有多少个提琴手,若符合条件就加一种情况。
数据不大直接暴力搜索。

#include<iostream>
#include<cstdio>
using namespace std;
int r,c,n,k;
int map[12][12];


int main()
{
    int x,y;
    while(cin>>r>>c>>n>>k)
    {
        memset(map,0,sizeof(map));
        for(int i=0;i<n;i++)
        {
            cin>>x>>y;
            map[x][y]=1;
        }
        int k1,g=0,x1,y1,x2,y2;
        for(x1=1;x1<=r;x1++)
        {
            for(y1=1;y1<=c;y1++)
            {
                for(x2=x1;x2<=r;x2++)
                {
                    for(y2=y1;y2<=c;y2++)
                    {
                        k1=0;
                        for(int b=x1;b<=x2;b++)
                            for(int e=y1;e<=y2;e++)
                                k1+=map[b][e];
                        if(k1>=k)
                            g++;
                    }
                }
            }
        }
        cout<<g<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值