Codeforces Round #645 (Div. 2) 参与排名人数14819
[codeforces 1358C] Celex Update 找规律+猜公式
总目录详见https://blog.csdn.net/mrcrack/article/details/103564004
在线测评地址https://codeforces.com/contest/1358/problem/C
Problem | Lang | Verdict | Time | Memory |
---|---|---|---|---|
C - Celex Update | GNU C++17 | Accepted | 77 ms | 200 KB |
该题思维量极大,过程如下
如上图所示找规律
(1,1)->(1,2)
1+2=3
共1种情况
(1,1)->(1,3)
1+2+4=7
共1种情况
(1,1)->(1,4)
1+2+4+7=14
共1种情况
(1,1)->(2,1)
1+3=4
共1种情况
(1,1)->(3,1)
1+3+6=10
共1种情况
(1,1)->(4,1)
1+3+6+10=20
共1种情况
(1,1)->(2,2)
1+2+5=8
1+3+5=9
共2种情况
(1,1)->(2,3)
1+2+4+8=15
1+2+5+8=16
1+3+5+8=17
共3种情况
(1,1)->(2,4)
1+2+4+7+12=26
1+2+4+8+12=27
1+2+5+8+12=28
1+3+5+8+12=29
共4种情况
(1,1)->(3,2)
1+2+5+9=17
1+3+5+9=18
1+3+6+9=19
共3种情况
(1,1)->(3,3)
1+2+4+8+13=28
1+2+5+8+13=29
1+3+5+8+13=30
1+2+5+9+13=29
1+3+5+9+13=31
1+3+6+9+13=32
6种情况,其中雷同情况1种,扣除后
共5种情况
大致找到规律,以
(1,1)->(3,4)为例
和值最小路径1+2+4+7+12+18=44
和值最大路径1+3+6+9+13+18=50
共有50-44+1=7种情况
进一步找规律
(1,1)->(6,7)
和值最小路径 a=1+2+4+7+11+16+22+30+39+49+60+72
和值最大路径 b=1+3+6+10+15+21+27+34+42+51+61+72
最大最小路径差值之和b-a=0+1+2+3+4+5+5+4+3+2+1+0=30
共有b-a+1=30+1=31种情况
最大最小路径差值之和
(1+5)*5/2*2=6*5=(7-1)*(6-1)=30
进一步验证
(1,1)->(3,4)为例
和值最小路径 1+2+4+7+12+18=44
和值最大路径 1+3+6+9+13+18=50
最大最小路径差值之和0+1+2+2+1+0
共有50-44+1=7种情况
最大最小路径差值之和
(1+2)*2/2*2=3*2=(4-1)*(3-1)=6
基本找到公式,答案是(y2-y1)*(x2-x1)+1
AC代码如下
#include <stdio.h>
#define LL long long
int main(){
int t,x1,y1,x2,y2;
LL ans;
scanf("%d",&t);
while(t--){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
ans=(LL)(y2-y1)*(x2-x1)+1;
printf("%lld\n",ans);
}
return 0;
}
类似题目