首先考虑x=0的情况,即ans=n*m/2
否则考虑颜色为x-1的个数。
n-=2*x m-=2*x
当n或m等于一时 ans=(n*m+1)/2;
否则ans=n+m-2
1 #include<cstdio> 2 3 int n,m,x; 4 5 int main() 6 { 7 freopen("testC.in","r",stdin); 8 freopen("testC.out","w",stdout); 9 int ans=0; 10 scanf("%d%d%d",&n,&m,&x); 11 if (x==0) 12 { 13 ans=n*m/2; 14 printf("%d",ans); 15 return 0; 16 } 17 else 18 { 19 x--; 20 m-=2*x; 21 n-=2*x; 22 if (m<=0||n<=0) 23 ans=0; 24 else { 25 if (m==1||n==1) ans=(n*m+1)/2; 26 else ans=m+n-2; 27 } 28 } 29 if (ans<0) ans=0; 30 printf("%d",ans); 31 }