Downgrade (CFGym 101775K )

Description

The God of Sheep plays an RPG game recently. The game has a level system that records a player's level with a pair of positive integers A and B where A is the major level and B is the minor level. For each major level k, you have to reach minor level Lk in order to upgrade to the next level k + 1. Different major levels may have different number of minor levels. For example, the God of Sheep is currently on level 3-4, and level 3 contains 4 minor levels: 3-1, 3-2, 3-3, and 3-4. Once the God of Sheep upgrades, he will be on level 4-1.

The God of Sheep has work to do now. Countless sheep are suffering in slaughter houses, woolsheds, and dairy farms. The God of Sheep has to rescue his fellow sheep citizens. He will be busy with the rescue plan for a couple of days and meanwhile the level of the game will be downgraded each day as a penalty. The downgrade penalty works like this: with each day the God of Sheep not playing the game, his level A-B will firstly be transformed to A minor levels (with minor level B discarded), and then be cast to an equivalent - pair as his new level. For example, suppose both level 1 and level 2 have 2 minor levels, and the God of Sheep is currently on level 3-3. For the first day of his absence, the level will become 2-1, the second day the level will become 1-2, the third day the level will become 1-1, and from the third day on the level will keep the same level as 1-1.

The God of Sheep wonders which level will he be when he comes back from the rescue?

Input

The first line of the input gives the number of test cases, T. T test cases follow.

Each test case contains two lines. The first line contains three integers: A, B and N, indicating the current major level, minor level, and the number of days the God of Sheep will be away from the game. The next line contains A integers: L1, L2, ..., LA indicating the number of minor levels in each major level.

  • 1 ≤ T ≤ 20.
  • 1 ≤ A ≤ 105.
  • 1 ≤ B ≤ LA.
  • 1 ≤ Li, N ≤ 109.

Output

For each test case, output one line containing "Case #x: y-z", where x is the test case number (starting from 1), y and z are the major level and the minor level when the God of Sheep is back to the game.

Sample Input
Input 
2
3 2 2
2 2 2
3 1 2
1 1 1
Output 
Case #1: 1-2
Case #2: 3-1

题意:这是一道翻译题,大体意思就是给一个等级A-B,每天都要降级,每个等级给出一个等级个数(每组样例第二行就是等级i有的等级数,例如第一个样例有1-1,1-2,2-1,2-1,3-1,3-2),题目的降级规则就是舍弃B,A就是经验值,看经验值能到什么等级,这就是一天的操作,问n天之后等级是多少。

这个很难理解,举个样例吧,看题目第一组样例,刚开始的等级是3-2,经验值就是3,3个经验值可以让它的等级变为2-1(1-1,1-2,2-1),就是第一天后的等级变为了2-1。现在的经验值是2,可以让它的等级变为1-2(1-1,1-2)。

思路:用一个前缀和记录一下通过经验值可以支撑它的等级到哪里,关键就是需要找到一个暂停条件,就是当经验值不变的时候就是等级不变的时候就可以直接输出了。

/***
 * ┌───┐   ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┐
 * │Esc│   │ F1│ F2│ F3│ F4│ │ F5│ F6│ F7│ F8│ │ F9│F10│F11│F12│ │P/S│S L│P/B│  ┌┐    ┌┐    ┌┐
 * └───┘   └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┘  └┘    └┘    └┘
 * ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐ ┌───┬───┬───┐ ┌───┬───┬───┬───┐
 * │~ `│! 1│@ 2│# 3│$ 4│% 5│^ 6│& 7│* 8│( 9│) 0│_ -│+ =│ BacSp │ │Ins│Hom│PUp│ │N L│ / │ * │ - │
 * ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤ ├───┼───┼───┤ ├───┼───┼───┼───┤
 * │ Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │{ [│} ]│ | \ │ │Del│End│PDn│ │ 7 │ 8 │ 9 │   │
 * ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤ └───┴───┴───┘ ├───┼───┼───┤ + │
 * │ Caps │ A │ S │ D │ F │ G │ H │ J │ K │ L │: ;│" '│ Enter  │               │ 4 │ 5 │ 6 │   │
 * ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────────┤     ┌───┐     ├───┼───┼───┼───┤
 * │ Shift  │ Z │ X │ C │ V │ B │ N │ M │< ,│> .│? /│  Shift   │     │ ↑ │     │ 1 │ 2 │ 3 │   │
 * ├─────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬────┬────┤ ┌───┼───┼───┐ ├───┴───┼───┤ E││
 * │ Ctrl│    │Alt │         Space         │ Alt│    │    │Ctrl│ │ ← │ ↓ │ → │ │   0   │ . │←─┘│
 * └─────┴────┴────┴───────────────────────┴────┴────┴────┴────┘ └───┴───┴───┘ └───────┴───┴───┘
 */

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
#define inf 0x3f3f3f3f
#define PI acos(-1)
const int mod=1e9+7;
const int M=1e5 + 10;
typedef long long ll;
int A[M];
ll sum[M];
int main()
{
    int T,n,m,i,j,kk,a,b;
    scanf("%d",&T);
    for(kk=1; kk<=T; kk++)
    {
        int flag=0;
        memset(sum,0,sizeof(sum));
        memset(A,0,sizeof(A));
        scanf("%d%d%d",&a,&b,&n);
        ll p=a,q=b;
        for(int i=1; i<=a; i++)
        {
            scanf("%d",&A[i]);
            sum[i] = sum[i-1] + A[i];
        }
        int t;//记录上一个经验值是什么
            while(1)
            {
                if(t == p)
                    break;
                if(n<=0)
                    break;
                n--;
                for(int i=1; i<=a; i++)
                {
                    if(sum[i] == p)
                    {
                        t = p;
                        p = i;
                        q = A[i];
                        break;
                    }
                    else if(sum[i] > p)
                    {
                        t = p;
                        q = p-sum[i-1];
                        p = i;
                        break;
                    }
                }
            }


        printf("Case #%d: %lld-%lld\n",kk,p,q);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值