题目链接:

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
  1. 2 1 1 1 2
output
  1. 2
input
  1. 3 3 1 2 3
output
  1. 6
  2.  
  3. 题意:
  4.  
  5. 给出a,b,c,d,其中所有2*2的格子的和与左上角的2*2的和相等,且满足每个格子的数字在[1,n];问有多少种不同的方案;
  6.  
  7. 思路:
  8.  
  9. 枚举左上角的那个数,然后看有多少数可以填在那,最后再乘上n,因为最中间的那个选什么数字没有影响;
  10.  
  11. AC代码:
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define Riep(n) for(int i=1;i<=n;i++)
  4. #define Riop(n) for(int i=0;i<n;i++)
  5. #define Rjep(n) for(int j=1;j<=n;j++)
  6. #define Rjop(n) for(int j=0;j<n;j++)
  7. #define mst(ss,b) memset(ss,b,sizeof(ss));
  8. typedef long long LL;
  9. const LL mod=1e9+;
  10. const double PI=acos(-1.0);
  11. const int inf=0x3f3f3f3f;
  12. const int N=1e4+;
  13. int n,a,b,c,d,sum;
  14. int main()
  15. {
  16. scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
  17. LL ans=;
  18. int temp=;
  19. for(int i=;i<=n;i++)
  20. {
  21. sum=a+b+i;
  22. if(sum-b-d<||sum-b-d>n)continue;
  23. if(sum-a-c<||sum-a-c>n)continue;
  24. if(sum-c-d<||sum-c-d>n)continue;
  25. temp++;
  26.  
  27. }
  28. ans=(LL)n*(LL)temp;
  29.  
  30. cout<<ans<<"\n";
  31. return ;
  32. }

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. gulp安装和使用简介

    一. gulp和grunt对比 grunt目前的工作流程:读文件.修改文件.写文件——读文件.修改文件.写文件——... gulp目前的工作流程:读取文件——修改文件——修改文件...——写文件 二. ...

  2. 转载:你可能没注意的CSS单位

    出自:http://www.cnblogs.com/dolphinX/p/4097693.html 扶今追昔 CSS中的单位我们经常用到px.pt.em.百分比,px和pt不用多说 em em是相对单 ...

  3. Simple Worker Thread Class

    http://www.codeproject.com/Articles/36184/Simple-Worker-Thread-Class Introduction Many times we need ...

  4. webView用法小结

    1.加入权限:AndroidManifest.xml中必须使用许可"android.permission.INTERNET",否则会出Web page not available错 ...

  5. 线性表 及Java实现 顺序表、链表、栈、队列

    数据结构与算法是程序设计的两大基础,大型的IT企业面试时也会出数据结构和算法的题目, 它可以说明你是否有良好的逻辑思维,如果你具备良好的逻辑思维,即使技术存在某些缺陷,面试公司也会认为你很有培养价值, ...

  6. vm.dirty_ratio & vm.dirty_background_ratio

    https://lonesysadmin.net/2013/12/22/better-linux-disk-caching-performance-vm-dirty_ratio/ Better Lin ...

  7. gradle的maven plugin使用

    在分布式系统开发中,基于gradle的项目,要共享jar一般是借助maven私服.那么gradle的maven插件如何做到上传binary jar,source jar, javadoc jar到私服 ...

  8. 学习笔记之高质量C++/C编程指南

    高质量C++/C编程指南 http://man.lupaworld.com/content/develop/c&c++/c/c.htm 高质量C++/C编程指南(附录 C :C++/C 试题的 ...

  9. [android]fmodex在某些android设备上声音延迟Latency

    // The default on windows in bufferlength = 1024 and numbuffers = 4 hr = g_pFmodSystem->setDSPBuf ...

  10. vsftpd虚拟用户创建实例(转载)

    vsftpd虚拟用户创建实例 发布:theboy   来源:net     [大 中 小] vsftpd虚拟用户创建实例,有需要的朋友可以参考下.  vsftpd虚拟用户创建实例,有需要的朋友可以参考 ...