1010 - Knights in Chessboard(找规律)
2016-03-29 19:14
363 查看
http://www.lightoj.com/volume_showproblem.php?problem=1010
1010 - Knights in Chessboard
Given an m x n chessboard where you want to place chess knights. You have to find the number of maximum knights that can be placed in the chessboard such that no two knights attack each other.
Those who are not familiar with chess knights, note that a chess knight can attack 8 positions in the board as shown in the picture below.
Each case contains two integers m, n (1 ≤ m, n ≤ 200). Here m and n corresponds to the number of rows and the number of columns of the board respectively.
1010 - Knights in Chessboard
PDF (English) | Statistics | Forum |
Time Limit: 1 second(s) | Memory Limit: 32 MB |
Those who are not familiar with chess knights, note that a chess knight can attack 8 positions in the board as shown in the picture below.
Input
Input starts with an integer T (≤ 41000), denoting the number of test cases.Each case contains two integers m, n (1 ≤ m, n ≤ 200). Here m and n corresponds to the number of rows and the number of columns of the board respectively.
Output
For each case, print the case number and maximum number of knights that can be placed in the board considering the above restrictions.Sample Input | Output for Sample Input |
3 8 8 3 7 4 10 | Case 1: 32 Case 2: 11 Case 3: 20 |
//几种可行的方法然后取最大值 #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <map> #include <set> #include <stack> #include <string> #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long using namespace std; const int SIZE=1e5+10; const int maxn=500000; int main() { int T; scanf("%d",&T); for(int cas=1;cas<=T;cas++){ int n,m; scanf("%d%d",&n,&m); printf("Case %d: ",cas); int ans=n*m/2; ans=max(ans,n*m-ans); if(n==1||m==1)ans=max(ans,n*m); else if(n==2||m==2)ans=max(ans,2*(2*(max(n,m)/4)+min(2,max(n,m)%4))); printf("%d\n",ans); } return 0; }
相关文章推荐
- 【Android】通用系列 —— 对话框
- 加载更多
- Tomcat配置Https环境
- 比较好用的办公软件
- 计算机程序的思维逻辑 (1)
- 在linux上配置unixODBC和FreeTDS访问MS SQL Server.
- mac ssh常见问题
- iOS quartzCore第一章——CADisplayLink详解 及与NSTimer的区别(类型为翻译,主要是自己好找)
- xcode常见报错调试
- 递归求阶乘
- 递归求阶乘
- 递归求阶乘
- 递归求阶乘
- 递归求阶乘
- 【小白学数据库】SQL批量模糊查询
- Go语言学习一 :基础语句
- 太乐了
- 事务四大特性(简称ACID)_me
- 解密回声消除技术
- NOIP2012提高组Day2 第3题 疫情控制