zoukankan      html  css  js  c++  java
  • 8VC Venture Cup 2016

    A. Orchestra

    题目连接:

    http://www.codeforces.com/contest/635/problem/A

    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 n violists. 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

    2 2 1 1
    1 2

    Sample Output

    4

    Hint

    题意

    有一个r*c的矩阵,然后有n个点是特殊的点

    然后问你里面有多少个子矩阵,其中至少有k个特殊的点

    题解:

    数据范围一看,才10

    想怎么做就怎么做,瞎JB做就好了。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 12;
    int a[maxn][maxn];
    int r,c,n,k;
    int cal(int x,int x1,int y,int y1)
    {
        int ans = 0;
        for(int i=x;i<=x1;i++)
            for(int j=y;j<=y1;j++)
                if(a[i][j])ans++;
        return ans;
    }
    int main()
    {
        scanf("%d%d%d%d",&r,&c,&n,&k);
        for(int i=1;i<=n;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            a[x][y]=1;
        }
        int ans = 0;
        for(int i=1;i<=r;i++)for(int j=i;j<=r;j++)
        for(int i1=1;i1<=c;i1++)for(int j1=i1;j1<=c;j1++)
        if(cal(i,j,i1,j1)>=k)ans++;
        cout<<ans<<endl;
    }
  • 相关阅读:
    Modbus软件开发实战指南 之 开发自己的Modbus Poll工具
    Divide Two Integers-不用'/' '*' '%'操作实现整数的除法
    用最少的砝码称出1到100克的物品
    Binary Tree Inorder Traversal-非递归实现中序遍历二叉树
    leetcode Word Break-单词划分
    位运算题目
    leetcode Single Number II
    leetcode 4Sum
    leetcode 3Sum Closest
    Unique Binary Search Trees-计算表示相同序列的不同BST个数
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5229457.html
Copyright © 2011-2022 走看看