【CodeForces】675B - Restoring Painting(数学推导)
2016-05-26 20:38
706 查看
题目链接:点击打开题目
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 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.
Input
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.
Output
Print one integer — the number of distinct valid squares.
Examples
input
output
input
output
Note
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;
}
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 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.
Input
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.
Output
Print one integer — the number of distinct valid squares.
Examples
input
2 1 1 1 2
output
2
input
3 3 1 2 3
output
6
Note
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;
}
相关文章推荐
- 论文笔记之:Fully Convolutional Attention Localization Networks: Efficient Attention Localization for Fine-Grained Recognition
- Windows Server 2012 磁盘管理之 简单卷、跨区卷、带区卷、镜像卷和RAID-5卷
- 【CodeForces】667A - Pouring Rain(数学)
- Installation error: INSTALL_FAILED_DUPLICATE_PERMISSION
- chromium WinMain
- haartraining训练生成xml过程
- Contains Duplicate
- CodeForces 667A Pouring Rain
- 解决<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized></not-authorized></failure>
- Linux进程学习---wait()和waitpid()函数
- Codeforces Round #354 (Div. 2) E. The Last Fight Between Human and AI 数学
- Mybaits之逆向工程
- .net active up mail 邮件发送
- HDU_1023_Train Problem II_卡特兰数
- 菜鸟对使用AIDL的一点理解
- 临时解决系统中大量的TIME_WAIT连接
- ASE :Space available in segment 'logsegment' has fallen critically low in database
- HDU3779Railroad DP 记忆化搜索
- HDU 1532 Drainage Ditches 最大流模板题
- 关于rangeOfString:和containsString: