B - 326-like Numbers
题意:找到一个不小于n的数是326数,定义是![image](https://img2023.cnblogs.com/blog/3316142/202312/3316142-20231203155816298-1711317697.png)
思路:简单的模拟循环即可
#include<bits/stdc++.h>
using namespace std;
bool check(int x){vector<int>a;while(x){a.push_back(x%10);x/=10;}if(a[1]*a[2]==a[0])return true;else return false;
}
void solve(){int n;cin>>n;for(int i=n;i<=919;i++){if(check(i)){cout<<i;return;}}
}
int main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int t=1;//cin>>t;for(int i=1;i<=t;i++)solve();return 0;
}
C - Peak
题意:有n个礼物在A[i]上,找到一个区间[A[i],A[i]+m]使得包含的礼物最多,求包含最多的个数
思路:用尺取法模拟,满足条件j指针就++,不满足i指针++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e5+10;
int a[N];
void solve(){int n,m;cin>>n>>m;for(int i=1;i<=n;i++)cin>>a[i];sort(a+1,a+1+n);int ans=0;for(int i=1,j=1;j<=n;){if(a[j]-a[i]>=m){ans=max(ans,j-1-i+1);i++;continue;}else{j++;}ans=max(ans,j-i);}cout<<ans;
}
signed main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int t=1;//cin>>t;for(int i=1;i<=t;i++)solve();return 0;
}