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 }                                 
  • 相关阅读:
    定义serialVersionUID的作用与意义整理
    HttpClient学习整理
    Eclipse+TestNG搭建接口自动化测试框架
    Jmeter之Bean shell使用(一)
    吴军博士的《数学之美》(摘录)
    SqlServer—大话函数依赖与范式
    MySQL—FOREIGN KEY
    MYSQL-用户操作
    WAMPServer 默认安装启动后,图标显示橙黄色
    Linux time命令
  • 原文地址:https://www.cnblogs.com/crazyapple/p/3051086.html
Copyright © 2011-2022 走看看