跳到正文

题解

题解:P10252 线性变换

I_like_florr_io约 2 分钟
原文
文章信息与版本

文章信息

收录
2026年7月14日
更新
2026年7月14日
篇幅
约 2 分钟
题目
P10252

版本

  1. v1当前

题目大意

有T行,每行有三个整数 xx,aa,bb,每次 xx 可变为 a×x−ba\times x-b 当 x<0x<0 时停止操作,求过程中 xx 的最小值。

优化

当 a=1a=1 时,每次xx可变为 x−bx-b ,所以加一个特判。

当 a>1a>1 时,不会发生这种问题。

特别的,不加特判会被这个数据卡爆,只能拿部分分,会TLE三个点。

代码
if(a==1){
    if(b!=0){
        x%=b;
        x-=b;
    }
}

AC code

C++
#include <bits/stdc++.h>
using namespace std;
#define int __int128
#define QAQ ch=getchar();
#define qaq printf("\n")
namespace quickread{
	inline int read(){
		int x=0,f=1;char ch=getchar();
		while (ch<'0'||ch>'9'){if(ch=='-')f=-1;QAQ}
		while (ch>='0'&&ch<='9'){x=x*10+ch-'0';QAQ}
		return x*f;
	}
	inline void write(int x){
	    if(x<0){putchar('-');x=-x;}
	    if(x>9)write(x/10);
	    putchar(x%10+'0');
	}
}
using namespace quickread;
int n,a,x,b;
signed main(){
	n=read();
	while(n--){
		x=read(),a=read(),b=read();
        if(a==1){
		    if(b!=0){
			    x%=b;
			    x-=b;
            }
		}
		else while(a*x-b<x&&x>=0) x=x*a-b;
		write(x),qaq;
	}
	return 0;
}
原文