Codeforces Round #353 (Div. 2) B. Restoring Painting 水题
B. Restoring Painting
题目连接:
http://www.codeforces.com/contest/675/problem/B
Description
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.
Sample Input
2 1 1 1 2
Sample Output
2
Hint
题意
给你一个33的矩阵,然后给你四个位置的数是多少
然后让你填五个位置的数,使得四个22正方形的值大小相同。
问你一共有多少种填数的方法
题解:
直接暴力枚举左上角,然后O(1)去check合不合法就好了
中间那个数无所谓的,肯定有n种方法
代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n,a,b,c,d;
long long ans=0;
cin>>n>>a>>b>>c>>d;
for(int i=1;i<=n;i++)
{
long long b2=b-c+i;
long long c2=a-d+i;
long long d2=b-c+c2;
if(1<=b2&&b2<=n&&1<=c2&&c2<=n&&1<=d2&&d2<=n)
ans++;
}
ans*=n;
cout<<ans<<endl;
}
Codeforces Round #353 (Div. 2) B. Restoring Painting 水题的更多相关文章
- Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Round #353 (Div. 2) C. Money Transfers (思维题)
题目链接:http://codeforces.com/contest/675/problem/C 给你n个bank,1~n形成一个环,每个bank有一个值,但是保证所有值的和为0.有一个操作是每个相邻 ...
- Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题
A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...
- Codeforces Round #146 (Div. 1) A. LCM Challenge 水题
A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...
- Codeforces Round #335 (Div. 2) B. Testing Robots 水题
B. Testing Robots Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606 ...
- Codeforces Round #335 (Div. 2) A. Magic Spheres 水题
A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...
- Codeforces Round #306 (Div. 2) A. Two Substrings 水题
A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...
随机推荐
- C++学习之路(十一):C++的初始化列表
结论: 1.在C++中,成员变量的初始化顺序与变量在类型中的声明顺序相同,而与他们在构造函数的初始化列表中的顺序无关. 2.构造函数分为两个阶段执行:1)初始化阶段:2)普通的计算阶段,表现为赋值操作 ...
- 使用netcat的正向 / 反向shell
reverse shell bind shell reverse shell描述图: 在此示例中,目标使用端口4444反向连接攻击主机.-e选项将Bash shell发回攻击主机.请注意,我们也可以在 ...
- Redis相关链接
Redis 教程 http://www.runoob.com/redis/redis-data-types.html Python操作redis学习系列之(集合)set,redis set详解 (六) ...
- vue+vuex+axios+echarts画一个动态更新的中国地图
一. 生成项目及安装插件 # 安装vue-cli npm install vue-cli -g # 初始化项目 vue init webpack china-map # 切到目录下 cd china- ...
- 1.SpringBoot之Helloword 快速搭建一个web项目
背景: Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配 ...
- No.7 selenium学习之路之Alert弹窗
Alert弹窗 弹窗是用工具选不到的~ 切换到alert driver.switch_to_alert() 新的语法:driver.switch_to.alert 注:新的语法不需要后面加括号 打印a ...
- Python基础 - MySQLdb模块
安装 pip install MySQLdb 使用 去除一个数据库中所有的表 import MySQLdb def db_test(): conn = MySQLdb.connect(user='&l ...
- OpenCV持久化(一)
在OpenCV中,采用FileStorage类进行数据持久化,可以采用XML或YAML格式存储数据. 将数据写入XML或YAML文件,可采用以下步骤: 1.创建FileStorage对象.可以调用构造 ...
- day5模块学习--shutil模块
shutil模块 高级的 文件.文件夹.压缩包 处理模块 os模块提供了对目录或者文件的新建/删除/查看文件属性,还提供了对文件以及目录的路径操作.比如说:绝对路径,父目录…… 但是,os文件的操作 ...
- linux下更换pip源
pip不更换源的话,速度可能非常慢.这里将pip源更换为阿里云源. 1.修改文件~/.pip/pip.conf(没有该文件则创建一个) $ sudo vim ~/.pip/pip.conf 2.写入以 ...