思路:求f(c, d) + f(a, b) - f(a, d) - f(c, b);
代码:
int f(int x, int y){ if(y % 2 == 0){ y = y / 2; int ans = y * (x / 4) * 8; x %= 4; if(x == 1){ ans += y * 3; }else if(x == 2){ ans += y * 6; }else if(x == 3){ ans += y * 7; } return ans; }else{ y /= 2; int ans = y * (x / 4) * 8 + 2 * (x / 4) * 2; x %= 4; if(x == 1){ ans += y * 3 + 2; }else if(x == 2){ ans += y * 6 + 3; }else if(x == 3){ ans += y * 7 + 3; } return ans; } } void solve(){ int a, b, c, d; cin >> a >> b >> c >> d; if(a < 0){ int cnt = (-a + 3) / 4; a += cnt * 4; c += cnt * 4; } if(b < 0){ int cnt = (-b + 3) / 4; b += cnt * 4; d += cnt * 4; } cout << f(c, d) + f(a, b) - f(a, d) - f(c, b); }
标签:AtCoder,cnt,return,int,Wallpaper,else,ans,图形 From: https://www.cnblogs.com/litianyu1969/p/18206627