zoukankan      html  css  js  c++  java
  • The Fifth Season Gym

    Cersei and Jaime has stolen n gold coins from the Casterly Rock reserves. They decided to play a game while the disappearence is not detected.

    The game consists of q rounds. At the beginning of each round all n coins lie in a heap. The players move in rotation, taking from the heap no less than ki and no more than li coins (ki ≤ lii is the number of round). The player who can't do the move loses.

    Cersei and Jaime have determined the pairs of numbers (ki, li) for each round of the game. They don't see any point in finding out who wins in what round as they choose who moves the first by flipping a coin. They are interested in the maximal length of each round, provided that they play optimally (intend to win). The length of the round is the total number of moves made by both Cersei and Jaime.

    Your task is to find the maximal possible length of each round of the game.

    Input

    The first line contains two integers n and q — the number of coins and the number of rounds (1 ≤ n ≤ 106, 1 ≤ q ≤ 105).

    Each of the next q lines contains two integers ki and li   — the minimal and maximal number of coins that could be taken at one turn in the i-th round.

    Output

    Write q space-separated integers. The i-th number should be equal to the maximal possible length of the i-th round.

    Examples

    Input
    10 2
    1 1
    5 6
    Output
    10 1 


     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 int main()
     5 {
     6     int n, q, a, b;
     7     scanf("%d %d", &n, &q);
     8     while(q--)
     9     {
    10         scanf("%d %d", &a, &b);
    11 
    12         if(n%(a+b)<a) printf("%d", n/(a+b)*2);
    13         else printf("%d", n/(a+b)*2+1);
    14 
    15         if(q>0) printf(" ");
    16         else printf("
    ");
    17     }
    18     return 0;
    19 }
  • 相关阅读:
    [NLP] 语义网络与知识图谱入门(二)
    [NLP] 语义网络与知识图谱入门(一)
    [论文理解] LFFD: A Light and Fast Face Detector for Edge Devices
    [学习笔记] 匈牙利匹配
    [NLP] nlp-lstm-cos -> sin
    [ros] ros入门记录
    [推荐系统] 两种协同过滤
    [NN] Guided Backpropgation 可视化
    [torch] pytorch hook学习
    python高级编程和算法
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/11671452.html
Copyright © 2011-2022 走看看