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;
    }
  • 相关阅读:
    LeetCode 350. Intersection of Two Arrays II (两个数组的相交之二)
    LeetCode 349. Intersection of Two Arrays (两个数组的相交)
    LeetCode 290. Word Pattern (词语模式)
    LeetCode 266. Palindrome Permutation (回文排列)$
    34.Search for a Range
    spark连接mongodb
    NLPIR中文分词器的使用
    scala和maven整合实践
    Spark中的键值对操作-scala
    301.Remove Invalid Parentheses
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5229457.html
Copyright © 2011-2022 走看看