Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:增加水题ac人数。。。In Reply To:Re:这题用什么算法好啊?我用递归Memory: 1636K Time: 390MS,太差劲了 Posted by:D00050 at 2008-07-24 16:02:52 > 算右下角是白色格子的8*8棋盘个数 > ans=((m-7)*(n-7)+c)/2 //Black and white painting #include <stdio.h> int n, m, c; void deal() { int white_sum; if (m % 2 == 0) white_sum = n * (m / 2); else { white_sum = (n / 2) * (m / 2 + 1 + m / 2); white_sum += (n % 2) * (m / 2 + 1); } if (c == 0) white_sum = n * m - white_sum; if (m % 2 == 0) //处理第8列 right { if (c == 1) { if (n % 2 == 1) white_sum -= 4; else white_sum -= 3; } else { if (n % 2 == 1) white_sum -= 3; else white_sum -= 4; } } else { if (c == 0) { if (n % 2 == 1) white_sum -= 4; else white_sum -= 3; } else { if (n % 2 == 1) white_sum -= 3; else white_sum -= 4; } } white_sum -= 7 * (n / 2); //处理前7列 if (c == 1) { if (m % 2 == 1) white_sum -= 4 * (n % 2); else white_sum -= 3 * (n % 2); } else { if (m % 2 == 1) white_sum -= 3 * (n % 2); else white_sum -= 4 * (n % 2); } white_sum -= 7 * ((m - 8) / 2); //处理前7行,去掉重复 if (c == 1) { if (n % 2 == 0) white_sum -= 3 * ((m - 8) % 2); else white_sum -= 4 * ((m - 8) % 2); } else { if (n % 2 == 0) white_sum -= 4 * ((m - 8) % 2); else white_sum -= 3 * ((m - 8) % 2); } printf("%d\n", white_sum); } void input() { while (scanf("%d%d%d", &n, &m, &c) && (n || m || c)) deal(); } int main() { input(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator