博弈论 —— The Game of Parity ( CodeForces 549C )

  • 题目链接:
    http://codeforces.com/problemset/problem/549/C

  • 分析:
    这道博弈论重在分清楚情况,偶数人数的城多一座少一座并不会改变最终剩余人数的奇偶性,只有奇数人数的城市的数量会对结果产生影响。

  • 题解:
    首先先算出奇数人数城市的数量Odd和偶数人数城市的数量Even,再算出可以操作的总次数T。

    如果T/2大于Odd,那么Daenerys就可以把所有奇数城市的城市拿走并获得胜利;

    如果T/2小于Odd,我们便进行下一步分析,判断最后一个操作的人是谁并且还需要考虑这时偶数人数城市的数量是否被取尽(如果被取尽,那么最后一步操作肯定会改变剩余人数奇偶性)。

    最后我们还要考虑一种情况,如果操作数为0的话,这个时候奇数人数城市的个数就能决定整个奇偶性。

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    int n, k;
    while(cin >> n >> k)
    {
        int o=0, e=0;
        for(int i=0;i<n;i++)
        {
            int x;
            cin >> x;
            if(x&1)
                o++;
            else
                e++;
        }
        //cout << o << ":" << e << endl;
        int res = n - k;
        int flag = 0;
        if(res>0)
        {
            if(res/2>=o)
            {
                flag = 0;
            }
            else
            {
                if(res&1)
                {
                    if(res/2>=e && !(k&1) )
                        flag = 0;
                    else
                        flag = 1;

                }
                else
                {
                    if(res/2>=e && (k&1))
                        flag = 1;
                    else
                        flag = 0;
                }
            }
        }
        else
        {
            if(o&1)
                flag = 1;
            else
                flag = 0;
        }

        if(flag)
            cout << "Stannis" << endl;
        else
            cout << "Daenerys" << endl;
    }
    return 0;
}
The initialization of UART4 can vary depending on the microcontroller or development board being used. However, here is an example of how to initialize UART4 on a STM32F4 Discovery board using CubeMX and HAL libraries: 1. Open CubeMX and create a new project for your microcontroller or development board. 2. In the "Pinout & Configuration" tab, select "UART4" from the peripherals list. 3. Enable the "Asynchronous" mode and set the baud rate to the desired value. 4. Set the word length, stop bits, and parity according to your application's requirements. 5. Configure the GPIO pins for the UART4 peripheral by selecting the appropriate pins in the "Pinout" tab. 6. Generate the code by clicking on the "Generate" button. 7. Open the generated code and locate the "MX_UART4_Init" function. 8. In this function, you will find the initialization code for UART4. It will look something like this: ``` huart4.Instance = UART4; huart4.Init.BaudRate = 115200; huart4.Init.WordLength = UART_WORDLENGTH_8B; huart4.Init.StopBits = UART_STOPBITS_1; huart4.Init.Parity = UART_PARITY_NONE; huart4.Init.Mode = UART_MODE_TX_RX; huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart4.Init.OverSampling = UART_OVERSAMPLING_16; if (HAL_UART_Init(&huart4) != HAL_OK) { Error_Handler(); } ``` 9. This code initializes UART4 with a baud rate of 115200, 8 data bits, 1 stop bit, no parity, and both transmit and receive modes enabled. 10. You can now use the HAL functions to send and receive data over UART4. For example, to transmit a string over UART4, you can use the following code: ``` char* str = "Hello, World!"; HAL_UART_Transmit(&huart4, (uint8_t*)str, strlen(str), HAL_MAX_DELAY); ``` This will send the string "Hello, World!" over UART4.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值