zoukankan      html  css  js  c++  java
  • codeforces 675B B. Restoring Painting(暴力枚举)

    题目链接:

    B. Restoring Painting

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it.

    • The painting is a square 3 × 3, each cell contains a single integer from 1 to n, and different cells may contain either different or equal integers.
    • The sum of integers in each of four squares 2 × 2 is equal to the sum of integers in the top left square 2 × 2.
    • Four elements abc and d are known and are located as shown on the picture below.

    Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong.

    Two squares are considered to be different, if there exists a cell that contains two different integers in different squares.

    Input
     

    The first line of the input contains five integers nabc and d (1 ≤ n ≤ 100 000, 1 ≤ a, b, c, d ≤ n) — maximum possible value of an integer in the cell and four integers that Vasya remembers.

    Output
     

    Print one integer — the number of distinct valid squares.

    Examples
     
    input
    2 1 1 1 2
    output
    2
    input
    3 3 1 2 3
    output
    6


    题意:

    给出a,b,c,d,其中所有2*2的格子的和与左上角的2*2的和相等,且满足每个格子的数字在[1,n];问有多少种不同的方案;

    思路:

    枚举左上角的那个数,然后看有多少数可以填在那,最后再乘上n,因为最中间的那个选什么数字没有影响;

    AC代码:

    #include <bits/stdc++.h>
    using namespace std;
    #define Riep(n) for(int i=1;i<=n;i++)
    #define Riop(n) for(int i=0;i<n;i++)
    #define Rjep(n) for(int j=1;j<=n;j++)
    #define Rjop(n) for(int j=0;j<n;j++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
    typedef long long LL;
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const int inf=0x3f3f3f3f;
    const int N=1e4+25;
    int n,a,b,c,d,sum;
    int main()
    {
        scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
        LL ans=0;
        int temp=0;
        for(int i=1;i<=n;i++)
        {
            sum=a+b+i;
            if(sum-b-d<1||sum-b-d>n)continue;
                if(sum-a-c<1||sum-a-c>n)continue;
                if(sum-c-d<1||sum-c-d>n)continue;
                temp++;
    
        }
        ans=(LL)n*(LL)temp;
    
        cout<<ans<<"
    ";
        return 0;
    }
  • 相关阅读:
    php基础
    MYSQL 常用函数
    MYSQL 练习题
    MYSQL 查询
    MYSQL:增删改
    隐藏导航
    分层导航
    图片轮播!
    你帅不帅?
    PHP 流程
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5502169.html
Copyright © 2011-2022 走看看