http://codeforces.com/problemset/problem/675/B
题意:你已经知道四个位置的四个数字。在另外的五个方块里面可以放置,<n 的任意值,使四个2*2的正方形的和都相同,一共有多少种放法。
思路:
最后可以推出公式:
x2 = x1 + b + c | |||||
x4 = x1 + a - d | |||||
x5 = x2 + a - d |
此时需要对 x1 进行一次 1到n 的遍历,并且要保证x2 x4 x5 的数据结果符合条件。
代码Code:
#include<cstdio>
#include<cstring>
const int MYDD=1103;
typedef __int64 LL;
bool Judge(int x,int y) {
if(x>=1&&x<=y) return true;
return false;
}
int main() {
int n,a,b,c,d;
while(scanf("%d%d%d%d%d",&n,&a,&b,&c,&d)!=EOF) {
LL ans=0;
int x1,x2,x3,x4,x5;
for(x1=1; x1<=n; x1++) {
x2=x1+b-c;
x4=x1+a-d;
x5=x2+a-d;
if(Judge(x2,n)&&Judge(x4,n)&&Judge(x5,n))
ans++;
}
ans=ans*n;
printf("%I64d\n",ans);
}
return 0;
}
/*By: Shyazhut*/