20140708 testC 模拟

最水的一道题>_<

首先 x=0 时输出白格子个数就好 ans=n*m/2

x>0 时 即为输出颜色为 x-1 的格子

对于颜色为x的格子

他一定存在于边长为 n-2x 和 m-2x 的矩形边上 且个数为 周长/2

画图即可发现

也即 ans=n+m-4x-2

若 n-2x 或 m-2x 特殊判断 ans=(n*m+1)/2

详见代码 >_<

 1 #include <cstdio>
 2 using namespace std;
 3 typedef long long LL;
 4 
 5 int main() {
 6     freopen("testC.in","r",stdin);
 7     freopen("testC.out","w",stdout);
 8     LL n,m,x;
 9     scanf("%I64d%I64d%I64d",&n,&m,&x);
10     LL ans;
11     if (x==0) {
12         ans=n*m/2;
13     }
14     else {
15         x--;
16         n-=2*x;
17         m-=2*x;
18         if (n<=0 || m<=0) ans=0;
19         else {
20             if (n==1 || m==1) ans=(n*m+1)/2;
21             else ans=m+n-2;
22         }
23     }
24     if (ans<0) ans=0;
25     printf("%I64d",ans);
26 }
View Code
原文地址:https://www.cnblogs.com/fjmmm/p/3832066.html