C - Game With Sticks
Problem description
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks.
An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.
In the grid shown below, n = 3 and m = 3. There are n + m = 6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are n·m = 9intersection points, numbered from 1 to 9.
The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move).
Assume that both players play optimally. Who will win the game?
Input
The first line of input contains two space-separated integers, n and m (1 ≤ n, m ≤ 100).
Output
Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game.
Examples
Input
2 2
2 3
3 3
Output
Malvika
Malvika
Akshat
Note
Explanation of the first sample:
The grid has four intersection points, numbered from 1 to 4.
If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this.
Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty.
In the empty grid, Akshat cannot make any move, hence he will lose.
Since all 4 intersection points of the grid are equivalent, Akshat will lose no matter which one he picks.
解题思路:这算是一道简单的博弈题吧。题目的意思就是只要有交叉点,轮到的人就可以移走两根棍子(一横一竖),如果轮到的人当前没有交叉点,那么这个人就输。我们找找规律:
n(m) m(n) 赢家
1 1 2 3 4...Akshat(先手)
2 2 3 4 5...Malvika(后手)
3 3 4 5 6...Akshat
4 4 5 6 7...Malvika
...
按照上面的方式继续推导下去,我们可以发现:如果输入的n、m中最小值是奇数,那么先手Akshat必赢,否则后手Malvika必赢。
AC代码:
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m,minval;
cin>>n>>m;
minval=min(n,m);
if(minval%)cout<<"Akshat"<<endl;
else cout<<"Malvika"<<endl;
return ;
}
C - Game With Sticks的更多相关文章
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- POJ 2653 Pick-up sticks (线段相交)
题意:给你n条线段依次放到二维平面上,问最后有哪些没与前面的线段相交,即它是顶上的线段 题解:数据弱,正向纯模拟可过 但是有一个陷阱:如果我们从后面向前枚举,找与前面哪些相交,再删除前面那些相交的线段 ...
- hduoj 1455 && uva 243 E - Sticks
http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...
- POJ 2653 Pick-up sticks【线段相交】
题意:n根木棍随意摆放在一个平面上,问放在最上面的木棍是哪些. 思路:线段相交,因为题目说最多有1000根在最上面.所以从后往前处理,直到木棍没了或者最上面的木棍的总数大于1000. #include ...
- POJ1065Wooden Sticks[DP LIS]
Wooden Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21902 Accepted: 9353 De ...
- 【POJ 2653】Pick-up sticks 判断线段相交
一定要注意位运算的优先级!!!我被这个卡了好久 判断线段相交模板题. 叉积,点积,规范相交,非规范相交的简单模板 用了“链表”优化之后还是$O(n^2)$的暴力,可是为什么能过$10^5$的数据? # ...
- CF451A Game With Sticks 水题
Codeforces Round #258 (Div. 2) Game With Sticks A. Game With Sticks time limit per test 1 second mem ...
- POJ 2452 Sticks Problem
RMQ+二分....枚举 i ,找比 i 小的第一个元素,再找之间的第一个最大元素..... Sticks Problem Time Limit: 6000MS ...
- The 2015 China Collegiate Programming Contest D.Pick The Sticks hdu 5543
Pick The Sticks Time Limit: 15000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others ...
- Pick-up sticks[HDU1147]
Pick-up sticksTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
随机推荐
- 图方法:寻找无向图联通子集的JAVA版本
图像处理中一般使用稠密方法,即对图像进行像素集合进行处理.在图像拓扑方面,更多地应用图计算方法. 寻找无向图联通子集的JAVA版本,代码: //查找无向图的所有连通子集//wishchin!!! pu ...
- ubuntu 16.04 安装QT问题
使用 sudo sh ./**.run 有错误: 增加 文件的可运行权限: sudo chmod +x Qt.run 直接运行: ./Qt.run 可完成安装
- HDU_1729_sg函数(dfs)
Stone Game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...
- EF test
LibraryEntities db = new LibraryEntities(); private void btnSelect_Click(object sender, EventArgs e) ...
- Jquery隐藏和显示Div的控制
html页面代码: <input type="checkbox" name="searchType" value="searchNews&quo ...
- count(*)实现原理+两阶段提交总结
count(*)实现原理 不同引擎的实现: MyISAM引擎把表的总行数存在了磁盘上,执行COUNT(*)就会直接返回,效率很高: InnoDB在count(*)时,需要把数据一行一行的从引擎里面取出 ...
- 本地远程访问服务器jupyter
一.前提: 安装Python3 安装Anaconda 配置jupyter notebook 并启动(重点) 二.配置jupyter文件 因为服务器已经安装好anaconda和jupyter,pytho ...
- 01-Linux命令基础-第01天(命令基础,软件安装与卸载、磁盘管理)
01- Linux初步 最早一直是单道程序设计模型的操作系统 69年贝尔实验室决定开发多道程序设计模型的操作系统 Multics计划 (失败了) x86 IA(Intel Architecture ...
- cookie和localstorage、sessionstorage区别
cookie数据始终在同源的http请求中携带(即使不需要),即cookie在浏览器和服务器间来回传递.sessionStorage和localStorage不会自动把数据发给服务器,仅在本地保存. ...
- java异常处理的面试题
package test; public class Test { public static int method(int i) throws Exception { try { return 10 ...