【CodeForces】[675B]Restoring Painting
2016-05-30 03:22
357 查看
起初没看懂为何左下角与右上角的块被限制
直到发现
指的是所有的2×2都要等于左上角的2×2
在九宫格
x a x
b x c
x d x
中间的一个是四个2×2共有部分不需要考虑
所以可以枚举左上角块的数字
分别计算另外三个块有几种可能
无法直接计算是因为
有可能有些数字会导致无法满足
(其它格加1也比左上角和大)
(其它格加n也没有左上角和大)
另外需要注意数据范围
需用__int64
#include<stdio.h> int main() { int n,a,b,c,d; while(scanf("%d %d %d %d %d",&n,&a,&b,&c,&d)!=EOF) { int cnt=0,t1=a+b,t2=b+d,t3=d+c,t4=a+c; for(int i=1; i<=n; i++) { int t=i+t1; if(t>t2&&t>t3&&t>t4&&t<=t2+n&&t<=t3+n&&t<=t4+n) { cnt++; } } printf("%I64d\n",(__int64)cnt*n); } return 0; }
题目地址:【CodeForces】[675B]Restoring Painting
相关文章推荐
- Codeforces Round #197 (Div. 2)
- Codeforces Round #198 (Div. 1)
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces 407C Codeforces Round #239 (Div. 1)C
- CodeForces 449A - Jzzhu and Chocolate
- CodeForces 449 B. Jzzhu and Cities
- codeforces 618C. Constellation
- Codeforces Round #349 (Div. 2) - C
- Codeforces Round #265 (Div. 2)
- Codeforces #310 div2 C. Case of Matryoshkas
- 状态压缩DP codeforces 244 Problem C. The Brand New Function 和 codeforces 165 E. Compatible Numbers
- codeforces 16 Problem E fish
- Codeforces Round332 部分题解
- CodeForces 603A_Alternative Thinking (DP)
- CodeForces 602B_Approximating a Constant Range_DP
- Codeforces round #247 for Div. 2
- Codeforces Round #246 (Div. 2)
- Codeforces #264(div 2)D.Gargari and Permutations
- Codeforces Round #236 (Div. 2)------A,B
- codeforces 257 div2 B