Codeforces1296B模拟 C二维坐标 pair map D 贪心取余

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值