ACM ICPC Vietnam National Second Round D X = X + X % 100

本文探讨了一个ACM竞赛中的循环节问题,通过分析题目要求多次操作后数值的变化规律,提出了针对不同数值特点的解题策略,并实现了具体的算法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//	ACM ICPC Vietnam National Second Round D
//
//	题目大意:
//		
//		X = X + X % 100.给你一个N和K.求K次操作后N的值
//
//	解题思路:
//
//		看到N和K都是1e9这种数.想到肯定会有循环节.然后
//	打表找规律.一开始发现是20一循环.即4的倍数才可以开
//	始循环,然而太年轻,交了无数发,wrong了无数发.后来发现
//	10这类的也是有循环4一循环.欣喜的敲了一发,然后还是wrong
//	这时候,我又想到了00这种特殊的情况,好,又交,又wrong
//	当然50也要特判啊.25啊,75啊都特判.写完之后,我发现自己太
//	年轻了,这样就可以过了.还是自己考虑问题不够周全吧.
//	情况多多,做练习赛的时候并没有做出来.不得不说自己太弱了.
//	继续加油,FIGHTING!!!
	

#include <cstring>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#define For(x,a,b,c) for (int x = a; x <= b; x += c)
#define Ffor(x,a,b,c) for (int x = a; x >= b; x -= c)
#define cls(x,a) memset(x,a,sizeof(x))
using namespace std;
typedef long long ll;

const int MAX_N = 108;

const int INF = 0x3f3f3f3f;
const ll MOD = 1e6;
ll N,K;

int a[108];
int cnt[108];
bool vis[108];

int main(){
  //  cls(a,0); //打表所用
  //  cls(cnt,0);
  //  for (int i = 1 ;i < 100;i ++){
  //      cls(vis,0);
  //      int k = 0;
  //      vis[i] = 1;
  //      int x = i;
  //      x = x + x % 100;
  //      int t = x % 100;
  //      int c = 1;
  //      while(!vis[t]){
  //          vis[t] = 1;
  //          x = x + x % 100;
  //          t = x % 100;
  //          c++;
  //      }
  //      a[i] = x;
  //      cnt[i] = c;


  //  //  if (i % 10 == 5)
  //  //      printf("%d %d %d\n",i,x,c);


  //  }
    //freopen("1.in","r",stdin);  
    int kase;
    scanf("%d",&kase);

    for (int i = 1;i <= kase ;i ++){
        scanf("%I64d%I64d",&N,&K);
        
        ll ans = N / 100 * 100;
        ll res = N % 100;

        if (res == 0){
            printf("%I64d\n",N);
            continue;
        }
        if ( res == 50){
            printf("%I64d\n", N + 50);
            continue;
        }

        if ( res == 25){
            if (K >= 1000000){
                printf("%I64d\n",ans + 100);
            }
            continue;
        }

        if (res == 75){
            if (K >= 1000000){
                printf("%I64d\n",ans + 200);
            }
            continue;
        }
    
        if (K < 1000000){
            for (int j = 1;j <= K;j ++){
                res = res + res % 100;
            }
            printf("%I64d\n",ans + res);
            continue;
        }

        int c = 0;

        if ( res % 10 != 0 || res % 10 != 5){
            while((res % 100) % 4){
                res += res % 100;
                c++;
            }

            K -= c;
            res = res + K / 20 * 1000;
            K %= 20;
        }
        else {

            while(((res % 100) / 10) % 2){
                res += res % 100;
                c++;
            }

            K -= c;
            res = res + K / 4 * 200;
            K %= 4;
        }
        for (int j = 0 ; j < K; j++){
            res += res % 100;
        }
        printf("%I64d\n",ans + res);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值