https://codeforces.com/contest/1296/standings
对数s 每次spend x obtain x/10下取整
最终spend最大值
10
ans=11
9876
ans=10973
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const int mod=1e9+7;
#define mp make_pair
#define fi first
#define se second
ll t,n,m,k,ans;
ll a[maxn];
ll x;
ll work(ll x){
ll len=0;
while(x){
x/=10;
len++;
}
return len;
}
ll ksm(ll a,ll b){
ll res=1;
while(b){
if(b&1)
res=res*a;
a=a*a;
b>>=1;
}
return res;
}
int main(){
cin>>t;
while(t--){
ans=0;
cin>>x;
ll shu=x;
while(shu){
ll len=work(shu);
ll z=shu/ksm(10,len-1);
ans+=z*ksm(10,len-1);
shu-=z*ksm(10,len-1);
if(len==1) //shu==0 不能结束 shu=900 z=9 ans+=900 shu-=900 shu+=9*10
break;
shu+=z*ksm(10,len-2);
}
cout<<ans<<endl;
}
return 0;
}
C
记录二维位置是否重复出现 最短 UD y++ y-- LR x-- x++ 不存在-1
4
4
LRUD
4
LURD
5
RRUDU
5
LLDDR
1 2
1 4
3 4
-1
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int mod=1e9+7;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pii;
string s,ans;
char c[maxn];
int cnt,n,t;
int main(){
cin>>t;
while(t--){
map<pii,int> m;
cin>>n;
scanf("%s",c+1);
int v=0,l=0,r=0,ans=n+1,x=0,y=0;
m[mp(0,0)]=1;//位置0 坐标出现多次
for(int i=1;i<=n;i++){
if(c[i]=='L')x--;
if(c[i]=='R')x++;
if(c[i]=='U')y++;
if(c[i]=='D')y--;
v=m[mp(x,y)];//v为0说明不存在 起码从1开始 不为0
if(v){
if(i-v+1<ans){
ans=i-v+1;
l=v;r=i;
}
}
m[mp(x,y)]=i+1;
}
if(ans==n+1) cout<<"-1"<<endl;
else cout<<l<<" "<<r<<endl;
}
return 0;
}
n<=2e5 a,b,k,hi<=1e9
n=6 a=2 b=3 k=3
7 10 50 12 1 8
6
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int mod=1e9+7;
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> pii;
string s;
char c[maxn];
ll n,a,b,k,ww[maxn],p,cnt[maxn],ans;
int main(){
cin>>n>>a>>b>>k;
for(int i=1;i<=n;i++){
cin>>ww[i];
p=ww[i]%(a+b);//有影响的部分
if(p==0)
p=a+b;
cnt[i]=(p-1)/a;//除去a先的一次 需要连续几次a结束
}
sort(cnt+1,cnt+n+1);
for(int i=1;i<=n && cnt[i]<=k;i++){
ans++;
k-=cnt[i];
}
cout<<ans<<endl;
return 0;
}