codeforces 675B B. Restoring Painting(暴力枚举)
题目链接:
1 second
256 megabytes
standard input
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.
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 题意: 给出a,b,c,d,其中所有2*2的格子的和与左上角的2*2的和相等,且满足每个格子的数字在[1,n];问有多少种不同的方案; 思路: 枚举左上角的那个数,然后看有多少数可以填在那,最后再乘上n,因为最中间的那个选什么数字没有影响; AC代码:
#include <bits/stdc++.h>
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
const LL mod=1e9+;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int N=1e4+;
int n,a,b,c,d,sum;
int main()
{
scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
LL ans=;
int temp=;
for(int i=;i<=n;i++)
{
sum=a+b+i;
if(sum-b-d<||sum-b-d>n)continue;
if(sum-a-c<||sum-a-c>n)continue;
if(sum-c-d<||sum-c-d>n)continue;
temp++; }
ans=(LL)n*(LL)temp; cout<<ans<<"\n";
return ;
}
codeforces 675B B. Restoring Painting(暴力枚举)的更多相关文章
- D. Diverse Garland Codeforces Round #535 (Div. 3) 暴力枚举+贪心
D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces 626D Jerry's Protest(暴力枚举+概率)
D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- CodeForces - 593A -2Char(思维+暴力枚举)
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is th ...
- Codeforces Round #353 (Div. 2) B. Restoring Painting 水题
B. Restoring Painting 题目连接: http://www.codeforces.com/contest/675/problem/B Description Vasya works ...
- Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举
题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...
- Codeforces Round #298 (Div. 2) B. Covered Path 物理题/暴力枚举
B. Covered Path Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/probl ...
- Codeforces 425A Sereja and Swaps(暴力枚举)
题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...
- CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)
题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...
- Codeforces Round #266 (Div. 2)B(暴力枚举)
很简单的暴力枚举,却卡了我那么长时间,可见我的基本功不够扎实. 两个数相乘等于一个数6*n,那么我枚举其中一个乘数就行了,而且枚举到sqrt(6*n)就行了,这个是暴力法解题中很常用的性质. 这道题找 ...
随机推荐
- 那些年困扰我们的委托(C#)
委托这个东西不是很好理解,可是工作中又经常用到,你随处可以看到它的身影,真让人有一种又爱又恨的感觉,我相信许多人被它所困扰过. 一提到委托,如果你学过C语言,你一定会马上联想到函数指针. 什么是委托? ...
- Unity3d:使用uWebKit插件嵌入网页,网页中的flv视频无法播放
问题描述:unity3d程序,使用uWebKit插件嵌入网页,用来播放FLV视频,有的电脑可以正常播放,有的电脑在网页中播放不了ps:网页中的播放器用的是player.swf解决方案:是由于网页中的播 ...
- 【转】Android -- Looper.prepare()和Looper.loop()
Looper.prepare()和Looper.loop() 原文地址:http://blog.csdn.net/heng615975867/article/details/9194219 Andro ...
- 实现带查询功能的Combox控件
前言 ComBox 还可以实现查询功能,通过设置 ComBox 控件的 AutoCompleteSource 属性和 AutoCompleteMode 属性,可以实现从 Combox 控件中查询已存在 ...
- word2013中取消句首字母自动大写
经常使用word的朋友都知道word中一行的首字母会自动大写,这给用户带来方便的同时,也产生了问题,因为有时候我们并不希望每行开头的首字母大写.要取消首字母自动大写可以取消勾选"首句字母大写 ...
- 在linux下修改oracle的sys和system的密码和用户解锁
修改oracle的sys和system的密码和用户解锁 1.再linux系统上sqlplus '/as sysdba' 进入sqlplus后就可以修改sys和system的密码了 2.alter us ...
- git有merge时如何删除分支
不小心增加了一个分支,并且有了merge,如何删除掉? 具有merge时不能切换分支 可以利用git stash命令 git rm controllers/InterfaceController.ph ...
- 小票打印机指令集封装(支持EPSON指令)
最近写了一些关于小票打印机的程序,不难,但是记录下来,作为足迹吧. 现在市场上的小票机基本都支持EPSON指令.指令集文档 对指令集进行了自己的封装,方便以后调用: package aheiziUti ...
- 【JavaScript】深入理解JavaScript之强大的原型和原型链
由于JavaScript是唯一一个被广泛使用的基于原型继承的语言,所以理解两种继承模式的差异是需要一定时间的,今天我们就来了解一下原型和原型链. AD: hasOwnProperty函数: hasOw ...
- memached+asp.net 4.0 分布式缓存
由于准备做一个商品站点,希望做一个memached缓存.折腾了一个多星期.本机是存进去取出来为空. 各种办法都试过了,还是不行.最后用同事电脑測试是能够的,然后将DEMO公布到阿里云也是能够的.支持. ...