#include<bits/stdc++.h> using namespace std;
#define inf 0x3f3f3f3f3f3f
#define int long long
int vis[];
signed main(){
int n,k;
cin>>n>>k;
string str;
cin>>str;
map<int,int> mp;
int sum=;
for(int i=;i<str.size();i++){
if(!mp[str[i]-'A']){
mp[str[i]-'A']=;
sum++;
}
vis[str[i]-'A']++;
}
if(sum==k){
int ans=inf;
for(int i=;i<k;i++){
ans=min(ans,vis[i]);
}
//cout<<ans<<'\n';
cout<<ans*k;
}else{
cout<<"";
}
return ;
}
思路:猜了一个想法,就过了。
#include<bits/stdc++.h> using namespace std;
#define int long long signed main(){
int n;
cin>>n;
if(n==||n==){
cout<<"No";return ;
}
printf("Yes\n");
int m=n/;
if(n%){
int s1=,s2=;
printf("%lld ",+m);
for(int i=;i<=n;i+=){
printf("%lld ",i);
s1+=i;
}
printf("\n");
printf("%lld ",m);
for(int i=;i<=n;i+=){
printf("%lld ",i);
s2+=i;
}
printf("\n");
// cout<<__gcd(s1,s2)<<'\n';
}else{
int s1=,s2=;
printf("%lld ",m);
for(int i=;i<=n;i+=){
printf("%lld ",i);
s1+=i;
}
printf("\n");
printf("%lld ",m);
for(int i=;i<=n;i+=){
printf("%lld ",i);
s2+=i;
}
printf("\n");
// cout<<__gcd(s1,s2)<<'\n';
}
return ;
}
/* */
思路:贪心+模拟【判断应该加自己和移除对手的值哪一个大。优先队列维护最大值】
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 10050005
priority_queue <int,vector<int>,less<int> >q1;
priority_queue <int,vector<int>,less<int> >q2;
int a[N];
int b[N];
signed main(){
int n;cin>>n;
for(int i=;i<=n;i++){
cin>>a[i];
q1.push(a[i]);
}
for(int i=;i<=n;i++){
cin>>b[i];
q2.push(b[i]);
}
int suma=,sumb=;
int now=;
while(){
now++;
if(q1.empty()&&q2.empty()){
break;
}
int t1=,t2=;
if(now%){//A
if(!q1.empty()&&!q2.empty()){
t1=q1.top();
t2=q2.top();
if(t1>t2){
q1.pop();
suma+=t1;
}else{
q2.pop();
}
}else if(q1.empty()&&!q2.empty()){
q2.pop();
}else if(!q1.empty()&&q2.empty()){
suma+=q1.top();
q1.pop(); } }else{
if(!q1.empty()&&!q2.empty()){
t1=q1.top();
t2=q2.top();
if(t2>t1){
q2.pop();
sumb+=t2;
}else{
q1.pop();
}
}else if(q1.empty()&&!q2.empty()){
sumb+=q2.top();
q2.pop();
}else if(!q1.empty()&&q2.empty()){
q1.pop();
} }
}
//cout<<suma<<" "<<sumb<<'\n';
cout<<suma-sumb;
return ;
}
#include<bits/stdc++.h> using namespace std;
#define int long long
#define inf 1<<30
#define N 10005000
int arr[N];
signed main(){
int n;cin>>n;
if(n==)
{
int qwq;
cin>>qwq;
cout<<qwq<<endl;return ;
}
int flag1=;int flag2=;
int sum1=;int minx=inf;
for(int i=;i<=n;i++) {
cin>>arr[i];
sum1+=abs(arr[i]);
if(arr[i]<){
flag1=;
}else if(arr[i]>){
flag2=;
}
minx=min(minx,abs(arr[i]));
}
if(flag1&&flag2){
cout<<sum1;
}else{
cout<<sum1-abs(minx)*;
}
return ;
}