首页 > 其他分享 >UVa 696 How Many Knights (想法题)

UVa 696 How Many Knights (想法题)

时间:2023-04-12 11:37:46浏览次数:58  
标签:696 How column Many placed int board knights row


696 - How Many Knights


Time limit: 3.000 seconds


http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=637

The knight is a piece used in chess, a game played on a board with squares arranged in rows and columns. A knight attacks pieces that are either (a) two rows and one column away from its position, or (b) one row and two columns away from its position. The following diagram illustrates this. The square marked N represents the position of the knight, and the squares marked X indicate the squares that are under attack.


 

X

 

X

 

X

 

 

 

X

 

 

N

 

 

X

 

 

 

X

 

X

 

X

 


In this problem you are to determine the largest number of knights that can be placed on a board with M rows and N columns so that no knight is attacking any other. M and N will each be no larger than 500.

Input


The input consists of pairs of integers giving values for  M  and  N , followed by a pair of zeroes.

Output


For each input pair, display the number of rows and columns in the board, and the number of knights that can be appropriately placed.

Sample Input


2 3
5 5
4 7
0 0


Sample Output


4 knights may be placed on a 2 row 3 column board.
13 knights may be placed on a 5 row 5 column board.
14 knights may be placed on a 4 row 7 column board.



思路:

如图所示,分以下三种情况(详见代码)

UVa 696 How Many Knights (想法题)_UVa

完整代码:

/*0.029s*/

#include<cstdio>

inline int cal(int m, int n)
{
	if (m > n) return cal(n, m);
	if (m == 1) return n;
	if (m == 2) return ((n >> 2 << 1) + (n % 4 == 3 ? 2 : n % 4)) << 1;
	return (m * n + 1) >> 1;
}

int main(void)
{
	int m, n;
	while (scanf("%d%d", &m, &n), m)
		printf("%d knights may be placed on a %d row %d column board.\n", cal(m, n), m, n);
	return 0;
}




标签:696,How,column,Many,placed,int,board,knights,row
From: https://blog.51cto.com/u_5535544/6185328

相关文章

  • archery entered FATAL state, too many start retries too quickly
    #################################一、配置文件:supervisord.conf(venv)[root@wy3-db245archery]#catsupervisord.conf[unix_http_server]file=supervisor.sock[supervisord]logfile=logs/supervisord.lognodaemon=false[supervisorctl]serverurl=unix://supervis......
  • ctfshow web入门 sql注入 171-175
    171-175同属无过滤绕过(并未对sql语句过滤,仅对查询结果过滤)重点:1、了解万能密码2、了解sql语句中字符串函数3、了解备份功能(导入/导出数据)4、蚁剑如何连接数据库web171$sql="selectusername,passwordfromuserwhereusername!='flag'andid=......
  • 3500/34 125696-01 捕获每个公交车站的GPS位置
    3500/34125696-01捕获每个公交车站的GPS位置因此,要设计特定的路线,必须为每个路线方向创建两条路线及其相应的公交车站。路线被设计成有向图,其中节点被用来表示汽车站,边被用来表示一个汽车站和另一个汽车站之间的距离。该模块使用Googlemaps的API,并对其进行扩展,以定义城市中特......
  • window.showModalDialog与window.open
    //window.showModalDialog全屏显示functionwinModalFullScreen(strURL){varsheight=screen.height-70;varswidth=screen.width-10;varwinoption="dialogHeight:"+sheight+"px;dialogWidth:"+swidth+"px;status:yes;scroll:yes;resiz......
  • How to use Xbox Series X as a DVD player All In One
    HowtouseXboxSeriesXasaDVDplayerAllInOne如何把XboxSeriesX做为一个DVD播放器使用Blu-rayPlayer蓝光播放器SetupandinstalltheBlu-rayandDVDplayerapponXbox在Xbox上设置和安装蓝光和DVD播放器应用程序TowatchBlu-rayorDVDmovi......
  • ctfshow-web4(Nginx日志写shell)
    这是一道有关Nginx日志文件写入shell的题目。  一、基础知识/etc/nginx/nginx.conf:该文件是Ngnix的配置的文件,该文件保存着能够影响服务器运行的配置信息。有时会泄露敏感信息。该文件支持php解析。/var/log/nginx/access.log:该文件是Ngnix的访问日志文件,Ngnix会把每个......
  • POJ - 2029 Get Many Persimmon Trees(暴力水题)
    题目大意:给你一个矩阵,矩阵上面有N个柿子树,现在要求你画一个s*t的矩阵,使得这个矩阵内的柿子树达到最多解题思路:100*100,直接暴力#include<cstdio>#include<cstring>#include<algorithm>usingnamespacestd;constintN=110;intn,w,h,s,t;intmap[N][N];voidin......
  • Linux chown 命令
    Linuxchown命令这个也是必须需要掌握的命令,是安全常用命令Linuxchown(英文全拼:changeowner)命令用于设置文件所有者和文件关联组的命令。Linux/Unix是多人多工操作系统,所有的文件皆有拥有者。利用chown将指定文件的拥有者改为指定的用户或组,用户可以是用户名或者用户ID,......
  • bootstrap5 .jqurey报错Cannot read properties of null (reading 'show')
    //toenabletooltipswiththedefaultconfiguration$('[data-bs-toggle="tooltip"]').tooltip()//toinitializetooltipswithgivenconfiguration$('[data-bs-toggle="tooltip"]').tooltip({boundary:'clipping......
  • A tutorial that will show you how to build an instant messaging app with Sinch.
     http://stackoverflow.com/questions/26247986/unsatisfiedlinkerror-couldnt-load-sinch-android-rtc-from-loader-dalvik-systemhttps://www.sinch.com/tutorials/android-messaging-tutorial-using-sinch-and-parse/https://github.com/sinch/android-messaging-tutorial......