小红的字符串
代码
#include<iostream>
#include<map>
using namespace std;
string a;
map<char,int>S;
int main(){
cin>>a;
for(int i=0;i<a.size();i++){
S[a[i]]++;
}
int maxv=0;
for(auto [v,w]:S){
maxv=max(maxv,w);
}
cout<<a.size()-maxv;
return 0;
}
小红的序列乘积
思路
就是直接看个位数就可以了,别的不管。
#include<iostream>
#define int long long
using namespace std;
const int N = 2e5+10;
int w[N];
int n;
int res;
signed main(){
cin>>n;
int sum=1;
for(int i=1;i<=n;i++){
int x;
cin>>x;
int k=x%10;
sum*=k;
sum%=10;
// cout<<k<<endl;
if(sum%10==6){
res++;
}
}
cout<<res;
return 0;
}
小红的数组重排
思路
我们就直接排个序即可。
#include<iostream>
#include<algorithm>
#define int unsigned long long
using namespace std;
const int N = 5e5+10;
int w[N];
int a[N],b[N];
int n;
int m1,m2;
signed main(){
cin>>n;
for(int i=1;i<=n;i++)cin>>w[i];
sort(w+1,w+1+n);
bool f=false;
for(int i=1;i<n-1;i++){
if(w[i]*w[i+1]>=w[i+1]*w[i+2]){
f=true;
break;
}
}
if(f)puts("NO");
else{
puts("YES");
for(int i=1;i<=n;i++){
cout<<w[i]<<' ';
}
}
return 0;
}
虫洞操纵者
思路
本质上就是bfs,但只不过我们这道题建图有点麻烦,我们得考虑每行的最近点对和每列的,我们要搞虫洞,我们可以