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;
}