CF630E Solution

题目链接

题解

推式子呐,设\(x_2-x_1=x,y_2-y_1=y\)\(ans=\frac{y+2}{2}\cdot(x+1)-\frac{x+1}{2}\)。以题目样例为例,六边形个数\(=5\)(列数)\(\times 3\)(奇数列每列个数)\(-2\)(偶数列个数)。

AC代码

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
	int x1,y1,x2,y2;
	scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2);
	printf("%lld",(y2-y1+2)/2*(x2-x1+1)-(x2-x1+1)/2);
	return 0;
}
posted @ 2021-02-09 15:51  violet_holmes  阅读(44)  评论(0编辑  收藏  举报