B. Restoring Painting
来源:互联网 发布:昆仑虚麒麟臂升阶数据 编辑:程序博客网 时间:2024/06/08 16:53
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.
解题说明:此题是一道数学题,已知9宫格内四个数字,求其他数字,让其满足每个2x2的正方形内数字之和相等,通过公式进行计算并判断即可。
#include<cstdio>#include <cstring>#include<cmath>#include<iostream>#include<algorithm>#include<vector>#include <map>using namespace std;int main(){long long int n,a,b,c,d,s=0,i,dd,bb,cc;scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d); for(i=1;i<=n;i++) { dd=a+i-d; cc=b+i-c; bb=b+dd-c; if(bb>0 && cc>0 && dd>0 && bb<=n && cc<=n && dd<=n) {s++;} } printf("%lld\n",n*s);return 0;}
- B. Restoring Painting
- codeforces 675B Restoring Painting
- CodeForces 675B Restoring Painting
- 【Codeforces】675B - Restoring Painting
- 【CodeForces】[675B]Restoring Painting
- CodeForces 675B Restoring Painting
- Codefroces 675 B. Restoring Painting
- [CodeForces]-675B-Restoring Painting
- Codeforces #353(div2)B.Restoring Painting
- CodeForces 675B D - Restoring Painting
- 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
- Codeforces Round #353 (Div. 2) -- B. Restoring Painting (规律)
- CodeForces - 675B Restoring Painting (暴力&转换)水
- Codeforces Round #353 (Div. 2) B. Restoring Painting
- Codeforces Round #353 (Div. 2) B.Restoring Painting
- How does Linux detect your webcam?
- Java集合框架源码剖析:LinkedHashSet 和 LinkedHashMap
- 安装maven
- 支持优先队列操作的TreeSet
- 剑指offer-面试题29-数组中出现次数超过一半的数字
- B. Restoring Painting
- Python轻松入门-01Python的安装
- 复习C语言———《C Prime Plus(第六版)》 第13章~第17章
- 阿里云RDS数据本地恢复
- CSDN-markdown编辑器使用说明
- 数据结构-java实现(1)
- 针对NETFLIX的新型钓鱼攻击的精妙之处
- 听说最近你读过不少书
- 重温《JAVA编程思想》----2017.1.18 类型信息RTTI(未完待续)