zoukankan      html  css  js  c++  java
  • Codeforces Round #308 (Div. 2) A. Vanya and Table 暴力

    A. Vanya and Table

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/552/problem/A

    Description

    Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.

    In this table, Vanya chose n rectangles with sides that go along borders of squares (some rectangles probably occur multiple times). After that for each cell of the table he counted the number of rectangles it belongs to and wrote this number into it. Now he wants to find the sum of values in all cells of the table and as the table is too large, he asks you to help him find the result.

    Input

    The first line contains integer n (1 ≤ n ≤ 100) — the number of rectangles.

    Each of the following n lines contains four integers x1, y1, x2, y2 (1 ≤ x1 ≤ x2 ≤ 100, 1 ≤ y1 ≤ y2 ≤ 100), where x1 and y1 are the number of the column and row of the lower left cell and x2 and y2 are the number of the column and row of the upper right cell of a rectangle.

    Output

    In a single line print the sum of all values in the cells of the table.

    Sample Input

    2
    1 1 2 3
    2 2 3 3

    Sample Output

    10

    HINT

    题意

    有n个操作,每次操作会将使得一个矩形区域都加上1

    然后问你这个100×100的区域的和是多少

    题解:

    数据范围很小,暴力做就好了

    代码:

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)  
    #define maxn 1000010
    #define mod 1000000007
    #define eps 1e-6
    const int inf=0x3f3f3f3f;
    const ll infll = 0x3f3f3f3f3f3f3f3fLL;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //**************************************************************************************
    
    ll g[200][200];
    
    int main()
    {
        int n=read();
        for(int ii=0;ii<n;ii++)
        {
            int x1=read(),y1=read(),x2=read(),y2=read();
            for(int i=x1;i<=x2;i++)
            {
                for(int j=y1;j<=y2;j++)
                    g[i][j]++;
            }
        }
        ll ans=0;
        for(int i=1;i<=100;i++)
        {
            for(int j=1;j<=100;j++)
                ans+=g[i][j];
        }
        cout<<ans<<endl;
    }
  • 相关阅读:
    鼠标拖放div 实现
    layerX offsetX pageX
    960 grid 使用
    960 grid 分析
    WebMatrix安装和使用
    Sass使用教程
    CSS预处理器实践之Sass、Less比较
    node.js 入门教程(beginnder guide
    node.js NPM 使用
    《Head First 设计模式》学习笔记——状态模式
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4588064.html
Copyright © 2011-2022 走看看