Restoring Painting
来源:互联网 发布:ubuntu命令行运行软件 编辑:程序博客网 时间:2024/05/29 03:02
Restoring Painting
CodeForces - 675B
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 from1 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 square2 × 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 to0, 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<stdio.h>int main(){int a,b,c,d,x,y,z,i;long long ans,n;while(~scanf("%lld%d%d%d%d",&n,&a,&b,&c,&d)){ans=0;for(i=1;i<=n;i++){x=b+i-c;y=i+a-d;z=b+i+a-c-d;if(x>=1&&x<=n&&y>=1&&y<=n&&z>=1&&z<=n)ans++;}printf("%lld\n",ans*n);}return 0;}
- Restoring Painting
- 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
- 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
- MYSQL的索引类型:PRIMARY, INDEX,UNIQUE,FULLTEXT,SPAIAL 有什么区别?各适用于什么场合?
- 分布式id生成方案概述
- 离线下载demo
- 学习笔记---引入外部样式表时link与@import的区别
- POJ1077 Eight —— IDA*算法
- Restoring Painting
- [Leetcode] 393. UTF-8 Validation 解题报告
- Linux上JavaWeb环境搭建: JDK8 Tomcat Mysql Redis
- 抽奖
- 邝斌的ACM模板(RMQ )
- 面试
- WOJ1192-Image Conversion
- 组合数学基本工具-- 排列与组合以及简单公式
- Sdk界面UI开发自动适配屏幕技巧