【CodeForces】675B - Restoring Painting(数学推导)
来源:互联网 发布:单桂敏淘宝哪个真的 编辑:程序博客网 时间:2024/06/10 01:49
题目链接:点击打开题目
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 a, b, c 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.
The first line of the input contains five integers n, a, b, c 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.
Print one integer — the number of distinct valid squares.
2 1 1 1 2
2
3 3 1 2 3
6
Below are all the possible paintings for the first sample.
In the second sample, only paintings displayed below satisfy all the rules.
题解:
然后:
还是读题的问题。
代码如下:
#include <cstdio>int main(){__int64 ans = 0;int n;int a,b,c,d;int e,f,i,h;scanf ("%d %d %d %d %d",&n,&a,&b,&c,&d);for (e = 1 ; e <= n ; e++){f = e + b - c;h = e + a - d;i = f + a - d;if (f >= 1 && f <= n && h >= 1 && h <= n && i >= 1 && i <= n)ans++;}ans *= n;printf ("%I64d\n",ans);return 0;}
- 【CodeForces】675B - Restoring Painting(数学推导)
- codeforces 675B Restoring Painting
- CodeForces 675B Restoring Painting
- 【Codeforces】675B - Restoring Painting
- 【CodeForces】[675B]Restoring Painting
- CodeForces 675B Restoring Painting
- [CodeForces]-675B-Restoring Painting
- Codeforces Round #353 (Div. 2)-B. Restoring Painting(数学)
- CodeForces - 675B Restoring Painting (暴力&转换)水
- CodeForces 675B D - Restoring Painting
- Codeforces #353(div2)B.Restoring Painting
- Codefroces 675 B. Restoring Painting(数学推公式)
- Codefroces 675 B. Restoring Painting(数学推公式)
- Codefroces 675 B. Restoring Painting
- B. Restoring Painting
- Codeforces Round #353 (Div. 2) B. Restoring Painting
- Codeforces Round #353 (Div. 2) B Restoring Painting
- Codeforces Round #353 (Div. 2) -- B. Restoring Painting (规律)
- R语言:常用函数(9.29 更新版)
- CocoaPods 错误 target overrides the `OTHER_LDFLAGS`
- 蓝桥杯--基础练习--BASIC-3字母图形
- 通过HttpServletRequest判断客户端浏览器类型是否为IE11
- eclipse代码自动提示,eclipse设置代码自动提示
- 【CodeForces】675B - Restoring Painting(数学推导)
- 2016SDAU课程练习三1002
- C Tricks(四)—— 从数组中随机选择一个元素
- Android自助餐之EventBus框架
- 集合Collection
- 文件读取写入
- EAS KDTable 判断点击的是表头
- halcon图片格式和opencv的IPLimage格式的转换
- HDU 1520 Anniversary party 树形dp 入门