Codeforces1307B.Cow and Friend几何 C. Cow and Message dp

n 个喜欢的数字,每次只能跳他喜欢的数字,从 (0,0) 到 (x,0) 最少需要多少步?
一直选择最大的那个跳
如果距离是最大步数的倍数那就是沿着 x 轴跳,如果不是到最后距离小于最大步数了,那么我们就跳一个等腰三角形。
最大距离大于两个兔子的距离,直接跳一个等腰三角形。
n=2 x=4
3 5
maxx=5>x=4
(2, sqrt(21) )
在这里插入图片描述
在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int mod=1000;
const int INF=0x3f3f3f3f;
ll t,n,a[maxn],x,maxx,ans;
map<ll,bool> mp;
int main(){
	cin>>t;
	while(t--){
		maxx=0;ans=0;
	//	mp.clear();
		cin>>n>>x;
		for(int i=1;i<=n;i++){
			cin>>a[i];
		//	mp[a[i]]=true;
			if(a[i]==x)
				ans=1;
			maxx=max(maxx,a[i]);
		}
	//	if(mp[x]){
		if(ans){
			cout<<1<<endl;
			continue;
		}
		if(x%maxx==0)
			ans=x/maxx;
		else
			ans=x/maxx+1;
		
		cout<<max(2ll,ans)<<endl;
		//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int mod=1000;
const int INF=0x3f3f3f3f;
ll t,n,a[maxn],x,maxx,ans;
map<ll,bool> mp;
int main(){
	cin>>t;
	while(t--){
		maxx=0;ans=0;
	//	mp.clear();
		cin>>n>>x;
		for(int i=1;i<=n;i++){
			cin>>a[i];
		//	mp[a[i]]=true;
			if(a[i]==x)
				ans=1;
			maxx=max(maxx,a[i]);
		}
	//	if(mp[x]){
		if(ans){
			cout<<1<<endl;
			continue;
		}
		if(x%maxx==0)
			ans=x/maxx;
		else
			ans=x/maxx+1;
		cout<<max(2ll,ans)<<endl;
	//	cout<<max(2ll,(x+maxx-1)/maxx)<<endl;
	}
	return 0;
}


子序列等差数列分布
求所有等差子序列中出现次数最大的子序列的数量

长度大于2的序列发现最后与长度为2的序列的数量不冲突 可以由长度为2的序列替代
求所有长度为1和2的子序列即可
在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int mod=1000;
const int INF=0x3f3f3f3f;
ll t,n,a[26][26],maxx,ans,cnt[26];
string s; 
int main(){
	cin>>s;
	n=s.size();
	for(int i=0;i<n;i++){
		cnt[s[i]-'a']++;
	}
	for(int i=0;i<26;i++)
		ans=max(ans,cnt[i]);
//	cout<<s<<" "<<ans<<endl;
	memset(cnt,0,sizeof cnt);
	for(int i=0;i<n;i++){
		for(int j=0;j<26;j++){
			a[j][s[i]-'a']+=cnt[j];	//j 在s[i]之前的字母数量 

		}
		cnt[s[i]-'a']++;
	}
	for(int i=0;i<26;i++){
		for(int j=0;j<26;j++){
			ans=max(ans,a[i][j]);
		}
	}
	cout<<ans<<endl;
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值