zoukankan      html  css  js  c++  java
  • 1001. Black Magic (soj)

    Description

    Believe it or not, there is a powerful black magic, invented by Mage Philia, which will make one person fall in love with an OTAKU. Needless to say, this is the ultimate goal for all of you. However, in order to learn this spell, you need to solve a problem first.

    First, Mage Philia wrote a row of numbers from 1…N on the blackboard. Then, she copied the last row of numbers to the next line, and erased the first M number in the new row. She repeated the same action again and again until all the number in the new row had been erased. For example, let N = 5 and M = 2, all the numbers on the blackboard are as follows.

    1

    2

    3

    4

    5

       

    3

    4

    5

           

    5

    At last, Mage Philia generates a sequence by concatenating all the rows from top to bottom. In the above example, the sequence is [1, 2, 3, 4, 5, 3, 4, 5, 5]

    Here comes your problem, find out the Kth number in the sequence.

    Input

    There are multiple test cases.

    The first line contains an integer T (1 ≤ T ≤ 20000), indicating the number of test cases.

    T lines follows. Each line contains three integers, N, M, K (1 ≤ N, M, K ≤ 10000), whose meanings are described above.

    Output

    Output one line for each test case. In each line, there is a number indicating the Kth number in the sequence. If K is greater than the length of the sequence, output a single 0 instead.

    Sample Input
    Copy sample input to clipboard
    3
    5 2 1
    5 2 7
    5 2 9
    
    Sample Output
    1
    4
    5
    
    分析:模拟暴力即可
     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<math.h>
     4 #include<algorithm>
     5 #include<string.h>
     6 #include<string>
     7 #include<ctime>
     8 #include<queue>
     9 #include<list>
    10 #include<map>
    11 #include<set>
    12 #include<vector>
    13 #include<stack>
    14 using namespace std;
    15 int main()
    16 {
    17     int t;
    18     while(~scanf("%d",&t))
    19     {
    20         while(t--)
    21         {
    22             int n,m,k;
    23             scanf("%d%d%d",&n,&m,&k);
    24             int s=k,left=n,temp=0;
    25             while(1)
    26             {
    27                 if(s>left)
    28                     s-=left;
    29                 else
    30                     break;
    31                 temp+=m;
    32                 left-=m;
    33                 if(left<=0)
    34                     break;
    35             }
    36             if(s+temp>n)
    37                 printf("0\n");
    38             else
    39                 printf("%d\n",s+temp);
    40 
    41         }
    42     }
    43     return 0;
    44 }                                 
  • 相关阅读:
    启动dr-elephant失败问题
    hive2.3 任务因一个map导致进程oom挂掉的排查
    hive客户端远程debug
    jdk命令行工具
    hadoop联邦集群 Hive 服务不重启udf函数生效
    livy server高并发下报错java.lang.RuntimeException: java.io.IOException: Unable to connect to provided ports 10000~10010
    使用apache livy导致的结果集不一致问题记录
    spark与hive引擎差异致结果集不一致
    mysql终止当前正在执行的sql语句
    Linux 修改文件目录权限
  • 原文地址:https://www.cnblogs.com/crazyapple/p/3051086.html
Copyright © 2011-2022 走看看