LightOJ-1010-Knights in Chessboard(数学)
链接:
https://vjudge.net/problem/LightOJ-1010
题意:
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.
思路:
存在一行时,直接乘,存在两行时,每8个用四个,多的最多用4个。
其他的m*2/2.
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
typedef long long LL;
const int INF = 1e9;
const int MAXN = 1e6+10;
const int MOD = 1e9+7;
int main()
{
int t, cnt = 0;
int n, m;
scanf("%d", &t);
while(t--)
{
printf("Case %d: ", ++cnt);
scanf("%d%d", &n, &m);
if (n == 1 || m == 1)
printf("%d\n", n*m);
else if (n == 2 || m == 2)
printf("%d\n", ((n*m)/8)*4+min(4, (n*m)%8));
else
printf("%d\n", (n*m+1)/2);
}
return 0;
}
LightOJ-1010-Knights in Chessboard(数学)的更多相关文章
- Lightoj 1010 - Knights in Chessboard
1010 - Knights in Chessboard PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: ...
- Lightoj 1010 - Knights in Chessboard (胡搞)
题目连接: http://www.lightoj.com/volume_showproblem.php?problem=1010 题目描述: 有一个n*m的棋盘,根据象棋中马走日字的规则,问此棋盘最多 ...
- LightOJ - 1010 Knights in Chessboard(规律)
题目链接:https://vjudge.net/contest/28079#problem/B 题目大意:给你一个nxm的棋盘,问你最多可以放几个骑士让他们互相攻击不到.骑士攻击方式如下图: 解题思路 ...
- lightoj 1010 (水题,找规律)
lightoj 1010 Knights in Chessboard 链接:http://lightoj.com/volume_showproblem.php?problem=1010 题意:国际象棋 ...
- LightOJ1171 Knights in Chessboard (II)(二分图最大点独立集)
题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1171 Description Given an m x n ches ...
- lightoj 1148 Mad Counting(数学水题)
lightoj 1148 Mad Counting 链接:http://lightoj.com/volume_showproblem.php?problem=1148 题意:民意调查,每一名公民都有盟 ...
- LightOJ 1027 A Dangerous Maze (数学期望)
题意:你面前有 n 个门,每次你可以选择任意一个进去,如果xi是正数,你将在xi后出去,如果xi是负数,那么xi后你将回来并且丢失所有记忆,问你出去的期望. 析:两种情况,第一种是直接出去,期望就是 ...
- LightOJ 1282 Leading and Trailing (数学)
题意:求 n^k 的前三位和后三位. 析:后三位,很简单就是快速幂,然后取模1000,注意要补0不全的话,对于前三位,先取10的对数,然后整数部分就是10000....,不用要,只要小数部分就好,然后 ...
- lightoj 1010
题意,在一个n*n的棋盘上放置一些马,使这些马不能互相攻击,问最多能放多少. 思路:从第一行每隔一个放置一个马即可,注意n=1和n=2的情况要特判. #include<cstdio> in ...
- Sum of Consecutive Integers LightOJ - 1278(推公式 数学思维)
原文地址:https://blog.csdn.net/qq_37632935/article/details/79465213 给你一个数n(n<=10^14),然后问n能用几个连续的数表示; ...
随机推荐
- 011 Android AutoCompleteTextView(自动完成文本框)的基本使用
1.XML布局 android:completionThreshold="1":这里我们设置了输入一个字就显示提示 (1)主界面布局 <?xml version=" ...
- Centos7部署node
近期在配置jenkins自动化部署前端项目时,需要使用到npm对前端项目进行构建打包,故这里单独介绍下node的部署. 项目地址:https://nodejs.org/en/download/ 1.下 ...
- SpringBoot中service注入失败(A component required a bean of type 'XXService' that could not found)
先写了JUnit,发现启动不了,注释掉有问题的service也不可以.可能是因为spring开始时会加载所有service吧. 按照网友们的说法,一般需要检查: 1.入口类有没有写MapperScan ...
- leetcode 2019.10.29 首次破百
刷题首次破百,记录一下自己成长的历程. 仍在路上,会慢慢变强的~
- Python中的动态属性与描述符
动态属性与属性描述符 属性描述符是什么? 在解释属性查找顺序之前我们需要了解Python中的属性描述符,属性描述符作为其他类对象的属性而存在,实现了特殊方法中的get.set.delete中的一种 ...
- SAS学习笔记56 ODS ESCAPECHAR
这种内嵌格式独立于style型和table型,它既可以结合二者使用,也可以独立使用.它主要通过下列语句的格式形式来进行调用: ODS ESCAPECHAR ‘^’; 上述符号’^’表示触发条件,如果碰 ...
- Informix从一个表更新多选数据到另一个表
功能如题, Informix从一个表更新多选数据到另一个表 例如, 要更新tab01的几个字段数据, 这些数据来自tab02, tab01和tab02之间通过id关联 参考语句: update tab ...
- 了解Scrum敏捷开发过程的优点
Scrum 1. 我们的团队 1.1 团队名称 开发小分队&7号 1.2 团队成员 徐棒 彭康明 刘鹏芝 罗樟 王小莉 胡广健 沈兴艳 1.3 我在团队中位置 需求实现团队(负责将需求模块实现 ...
- vue打包后.woff字体文件路径问题处理
在执行 npm run build 命令打包后,如果出现 .woff 等字体文件找不到的情况 通过设置 vue-style-loader 打包前缀路径解决
- flutter入门之常见的flutter问题汇总(转)
1. 使用AppBar后如何去掉左边的返回箭头.左边的图标对应的是leading,源代码如下(吐槽一下,CSDN暂不支持dart语言): Widget leading = widget.leading ...