2017暑期集训一Restoring Painting(思维)
来源:互联网 发布:java和php哪个前景好 编辑:程序博客网 时间:2024/06/14 13:40
K - *Restoring Painting(思维)
CodeForces - 675BVasya 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.
思路:根据题目信息四个2x2的区域之和相等,正中间小方块存在于四个区域,故其值没有影响不用考虑,
然后设左上角为x1,右上角为x2,左下角为x3,右下角为x4,因为x1+a+b=x2+a+c=x3+b+d=x4+c+d,所以x2=x1+b-c,x3=x1+a-d,x4=x1+a+b-c-d;题目要求,x1,x2,x3,x4都要在1和n之间,所以根据四者之间的关系,令x1从1到n循环,并判断其余三者是不是同时都在1到n的范围内,在就计数,而且最中间数字可以使1到n的任意一个。
#include<cstdio>int main(){int a,b,c,d;long long n;while(scanf("%lld%d%d%d%d",&n,&a,&b,&c,&d)!=EOF){long long num=0;for(int x1=1;x1<=n;x1++){int x2=x1+b-c;int x3=x1+a-d;int x4=x1+a+b-c-d;if((x2>=1&&x2<=n)&&(x4>=1&&x4<=n)&&(x3>=1&&x3<=n))num++;}long long k=num*n;printf("%lld\n",k);}return 0; }
- 2017暑期集训一Restoring Painting(思维)
- Restoring Painting
- 暑期集训搜索专题(一)
- 暑期集训搜索专题(一)
- HPU16级暑期集训练习(一)
- Codeforces #353(div2)B.Restoring Painting
- 2017暑期集训——Wet Shark and Bishops(思维)
- B. Restoring Painting
- 暑期集训(首篇博文)
- 7.19 暑期集训——动态规划篇(一)
- Codeforces Round #353 (Div. 2)-B. Restoring Painting(数学)
- CodeForces - 675B Restoring Painting (暴力&转换)水
- 【CodeForces】675B - Restoring Painting(数学推导)
- Codeforces Round #353 (Div. 2) B. Restoring Painting __ map or set 、思维题
- codeforces 675B Restoring Painting
- CodeForces 675B Restoring Painting
- 【Codeforces】675B - Restoring Painting
- 【CodeForces】[675B]Restoring Painting
- Linux Shell Scripting Cookbook, Second Edition [eBook] pdf,epub,mobi,code
- cs231n-2017-assignments2-TensorFlow.ipynb 自动调参
- Java中单例模式实现
- node.js
- 使用输入输出流迭代器读取和写入文件
- 2017暑期集训一Restoring Painting(思维)
- js校验页面输入是否为空
- 内存映射
- LSTM
- 2016web前端面试题
- Html5(移动端)开发,安卓机上的软键盘顶起影响页面布局
- Linux SPI总线和设备驱动架构之四:SPI数据传输的队列化
- jenkins 构建maven工程--Unknown lifecycle phase "clean"
- HDU1019