LightOJ 1010
2016-05-30 21:53
357 查看
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.
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int t, ncase=1;
cin>>t;
while(t--)
{
int m, n;
scanf("%d %d", &m, &n);
printf("Case %d: ",ncase++);
if(m==1||n==1)
{
printf("%d\n",n*m);
}
else if(n==2||m==2)
{
int x=(m*n)%8, y=((m*n)/8)*4;
if(x>4)
{
x=4;
}
printf("%d\n",x+y);
}
else
{
if((m*n)&1)
{
printf("%d\n",(m*n)/2+1);
}
else
{
printf("%d\n",(m*n)/2);
}
}
}
return 0;
}
每隔一个棋子放一个马,可达到最优解,1,2特判;
然而比赛时并没有多想完全交给队友去做也不问他的思维一心只钻研自己的题,因为一开始没和队友说自己是怎么想的后来在队友的提醒下才知道想错了然而却已经浪费了大量的时间结果不仅没做出来还浪费了大量的时间,如果和队友一起想的话可能就帮队友做出来了,下次一定要记住要团体解题靠个人能力实在是时间浪费太严重
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 <iostream>
#include <cstdio>
using namespace std;
int main()
{
int t, ncase=1;
cin>>t;
while(t--)
{
int m, n;
scanf("%d %d", &m, &n);
printf("Case %d: ",ncase++);
if(m==1||n==1)
{
printf("%d\n",n*m);
}
else if(n==2||m==2)
{
int x=(m*n)%8, y=((m*n)/8)*4;
if(x>4)
{
x=4;
}
printf("%d\n",x+y);
}
else
{
if((m*n)&1)
{
printf("%d\n",(m*n)/2+1);
}
else
{
printf("%d\n",(m*n)/2);
}
}
}
return 0;
}
每隔一个棋子放一个马,可达到最优解,1,2特判;
然而比赛时并没有多想完全交给队友去做也不问他的思维一心只钻研自己的题,因为一开始没和队友说自己是怎么想的后来在队友的提醒下才知道想错了然而却已经浪费了大量的时间结果不仅没做出来还浪费了大量的时间,如果和队友一起想的话可能就帮队友做出来了,下次一定要记住要团体解题靠个人能力实在是时间浪费太严重
相关文章推荐
- 第12周项目2-时间类
- 熟悉 CMake (三)—— 配置 opencv3
- 学习笔记之自适应布局
- JSP--jstl标签
- 202. Happy Number
- 使用rdpproxy和rdpy对RDP进行中间人攻击的总结
- Intent类
- 整数划分问题
- JVM参数
- ORA-12154: TNS:could not resolve the connect identifier specified
- application共享变量
- 键盘回车事件导致页面刷新
- C#中Math类的计算整数的三种方法
- 高可用软件Keepalived
- filter拦截器的简单使用
- [BZOJ2161]布娃娃(扫描线+线段树)
- C++函数中的引用
- 基于Openwrt iptables 限速
- Java多线程笔记
- java- 分布式- 一致性哈希算法(1)