zoukankan      html  css  js  c++  java
  • TZOJ--5447: Irrational Division (博弈)

    5447: Irrational Division 

    时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte

    描述

    Your family has been blessed with chocolate! A huge piece of chocolate has been given to you and your sister to share. However, as you gobbled up the large majority last time, your parents have invented a game to keep things fair (and to keep you occupied while they hide all the other chocolate). To keep things interesting, they have given you a rectangular piece of chocolate, which consists of little squares of both dark chocolate and white chocolate in a chessboard pattern. While you and your sister both love dark chocolate, you hate white chocolate! So, both you and your sister want as much dark chocolate as possible, while simultaneously obtaining as little white chocolate as possible. Every dark piece of chocolate you obtain gives you 1 meaningless unit of happiness, while a white piece lowers your happiness by 1 meaningless unit (and the same holds for your sister). Now, while you love your sister very much, there is always heavy competition between siblings, so your goal is to maximize the difference of your obtained happiness and her obtained happiness (while she tries to do the opposite, obviously). 

    The game works as follows. Your parents place a p×q-rectangle of the aforementioned mixed chocolate on a table. You are situated on the west side of the table and your sister on the south side. The side of length p is parallel to the north-south line, while the side of length q is parallel to the east-west line. Furthermore, the north-west square is made of dark chocolate. Then, starting with yourself, you take turns breaking off blocks of chocolate (which you can keep). You can break off any positive number of entire columns from the west side, while your sister breaks off any positive number of entire rows from the south side. You repeat this process until no more chocolate is left. Your sister is very smart and will always play the game perfectly. 

    A game might proceed like this, for example: you and your sister start with a 3 ×4-rectangle. You decide to break off 2 columns, obtaining 3 dark and 3 white chocolate squares, netting a happiness of zero. Your sister then breaks off 1 row, obtaining 1 dark and 1 white squares as well, so no happiness for her either. You then take a single column, which nets you nothing again, after which your sister decides to break off one row, which nets her 1 happiness! You then take the last piece, which makes you lose a unit of happiness, so your total score is −1 − 1 = −2. See the figure. (Note: the strategies used here might not be optimal.)

    输入

    Multiple cases.

    Each case given are two positive integers p and q, both at most 100, the height and width of the chocolate rectangle.

    输出

    Each case output the largest possible difference (in your favour) between your net happiness and your sister’s net happiness.

    样例输入

     1 2

    样例输出

     2

    题目来源

    BAPC 2017

    题目链接:http://tzcoder.cn/acmhome/problemdetail.do?&method=showdetail&id=5447

    题目大意:有一块黑白交替的巧克力,黑色的巧克力幸福值+1,白色巧克力幸福值-1,一人可以选任意行,一人可以选任意列,求两人幸福值的差值。

    根据题目进行博弈模拟后发现结果只会存在0 1 2这3种情况

    m为偶数b为奇数并且m>n时两人一人为1分1人为-1分,差值为2

    m和n都是奇数是,一人为1分一人人为0分,差值为1

    其他情况两人分数一样,差值为0

    #include <bits/stdc++.h>
    using namespace std;
    int main(){
    	int n,m;
    	while(cin>>n>>m){
    		if(!(m&1)&&(n&1)&&m>n)puts("2");
    		else if((n&1)&&(m&1))puts("1");
    		else puts("0");
    	} 
    }
  • 相关阅读:
    Apache Jmeter 性能测试
    linux 达梦数据库 命令行 卸载
    vue控制台报错Duplicate keys detected: 'xxxx'. This may cause an update error.解决方案
    springboot报错说 Failed to parse multipart servlet request; nested exception is java.io.IOException
    简单理解Callable接口
    Windows下设置Mongodb用户名密码
    Win10 搭建FTP环境,并使用Java实现上传,下载,删除
    【小组展示】1
    【计网II】
    【密码学】AES
  • 原文地址:https://www.cnblogs.com/Anidlebrain/p/10029265.html
Copyright © 2011-2022 走看看