题目链接:

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 ;
}

最新文章

  1. js字符串格式化扩展方法
  2. WPF textblock加入超链接
  3. VS2010无法调试问题解决
  4. BestCoder Round #87 1002 Square Distance[DP 打印方案]
  5. 线下线上对接的一种思路(本地erp与线上电子商务平台对接)
  6. Oracle EBS在编码方式为AL32UTF8时的注意事项
  7. paper 62:高斯混合模型(GMM)参数优化及实现
  8. Android自定义下拉刷新
  9. mysql语句添加索引
  10. JQuery easyui (1) Draggable(拖动)组件
  11. python mysql 2014 Commands out of sync; you can&#39;t run this command now
  12. Git命令行和Xcode结合使用
  13. 布隆过滤器(BloomFilter)持久化
  14. vue从入门到进阶:Vuex状态管理(十)
  15. 第四十一天 socker server和 event
  16. java session创建与获取
  17. Perl中命令行参数以及打开管道文件
  18. Git报错:error: cannot open .git/FETCH_HEAD: Read-only file system
  19. Top N的MapReduce程序MapReduce for Top N items
  20. bzoj 4372 烁烁的游戏——动态点分治+树状数组

热门文章

  1. 使用JAVA对字符串进行DES加密解密(修正问题)
  2. [转] 一个程序猿眼中的国内主流地图api
  3. 函数WideCharToMultiByte() 详解
  4. (剑指Offer)面试题24:二叉搜索树的后序遍历序列
  5. Android LIstView初次创建getview方法执行多次问题
  6. vc6.0 通过ADO(udl)连接sql 2008
  7. java String和Date转换
  8. ASP.NET中DesignMode属性
  9. Objective-C语法之代码块(block)的使用
  10. Looksery Cup 2015 B. Looksery Party 暴力