题目链接:

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+;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int N=1e4+;
int n,a,b,c,d,sum;
int main()
{
scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
LL ans=;
int temp=;
for(int i=;i<=n;i++)
{
sum=a+b+i;
if(sum-b-d<||sum-b-d>n)continue;
if(sum-a-c<||sum-a-c>n)continue;
if(sum-c-d<||sum-c-d>n)continue;
temp++; }
ans=(LL)n*(LL)temp; cout<<ans<<"\n";
return ;
}

codeforces 675B B. Restoring Painting(暴力枚举)的更多相关文章

  1. D. Diverse Garland Codeforces Round #535 (Div. 3) 暴力枚举+贪心

    D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. Codeforces 626D Jerry's Protest(暴力枚举+概率)

    D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  3. CodeForces - 593A -2Char(思维+暴力枚举)

    Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is th ...

  4. Codeforces Round #353 (Div. 2) B. Restoring Painting 水题

    B. Restoring Painting 题目连接: http://www.codeforces.com/contest/675/problem/B Description Vasya works ...

  5. Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举

    题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...

  6. Codeforces Round #298 (Div. 2) B. Covered Path 物理题/暴力枚举

    B. Covered Path Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/probl ...

  7. Codeforces 425A Sereja and Swaps(暴力枚举)

    题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...

  8. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  9. Codeforces Round #266 (Div. 2)B(暴力枚举)

    很简单的暴力枚举,却卡了我那么长时间,可见我的基本功不够扎实. 两个数相乘等于一个数6*n,那么我枚举其中一个乘数就行了,而且枚举到sqrt(6*n)就行了,这个是暴力法解题中很常用的性质. 这道题找 ...

随机推荐

  1. Linux环境下oracle创建和删除表空间及用户

    #su - oracle $ sqlplus /nolog SQL> connect / as sysdba --//创建临时表空间 create temporary tablespace te ...

  2. CI reids 缓存

    注意:在项目中的application/libraries 中自己定义的类最好不要以cache命名. 连接 Redis 服务器的配置信息必须保存到 application/config/redis.p ...

  3. Swift学习笔记十五

    自动引用计数(Automatic Reference Counting) 和OC一样,Swift用自动引用计数机制来跟踪和管理你应用程序的内存,大多数情况下,你不需要考虑自己管理内存,Swift会自动 ...

  4. BZOJ 1045: [HAOI2008] 糖果传递 数学

    1045: [HAOI2008] 糖果传递 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=1045 Description 有n个小朋友坐 ...

  5. Codeforces Round #244 (Div. 2) B. Prison Transfer 线段树rmq

    B. Prison Transfer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/pro ...

  6. 用python写makefile

    温馨提示:阅读本文的同学最好能了解makefile和python的编写规则. 不懂的同学能够先保存在收藏夹.以便日后查看. 事实上之前我一直非常懒,我不想了解makefile规则.由于在linux下开 ...

  7. 关于THIS_FILE

    VC++中本身就有内存泄漏检查的机制,可以在向导生成的支持MFC的工程中看到如下代码:  #ifdef _DEBUG  #define new DEBUG_NEW  #undef THIS_FILE  ...

  8. linux下的十六进制编辑器---wxHexEdit

    ....其实wxHexEdit是一个跨平台的十六进制编辑器,支持windows,linux,mac. 之所以标题用linux...是因为windows下多数都用winhex,UE之类的编辑器,而lin ...

  9. VC6.0常见编译错误提示

    原文:http://c.biancheng.net/cpp/html/746.html 1) error C2001: newline in constant 编号:C2001 直译:在常量中出现了换 ...

  10. 实现O(1)获取最大最小值的栈----java

    原文:http://blog.csdn.net/sheepmu/article/details/38459165 实现O(1)获取最大最小值的栈和队列----java 一.如何实现包含获取最小值函数的 ...