首页 > 代码库 > CodeForces 518B - Han Solo and Lazer Gun(模拟)

CodeForces 518B - Han Solo and Lazer Gun(模拟)

题意:给定两个串(长度范围为 1 ~ 2*10^5,两串长度不一定相同,由大、小写字母构成),需要让两串中完全相同字母匹配的尽量多,在此前提下,再让同一字母但大小写不同的对数尽量多。

先尽量多的完全相同匹配,然后再尽量多的匹配大小写不同的字母即可

 

#include<cstdio>  
#include<cstring>  
#include<cctype>  
#include<cstdlib>  
#include<cmath>  
#include<iostream>  
#include<sstream>  
#include<iterator>  
#include<algorithm>  
#include<string>  
#include<vector>  
#include<set>  
#include<map>  
#include<deque>  
#include<queue>  
#include<stack>  
#include<list>  
typedef long long ll;  
typedef unsigned long long llu;  
const int MAXN = 100 + 10;  
const int MAXT = 1000000 + 10;  
const int INF = 0x7f7f7f7f;  
const double pi = acos(-1.0);  
const double EPS = 1e-6;  
using namespace std;  
  
char s1[MAXT], s2[MAXT], s[MAXT], vis[MAXT];  
map<int, int> u;  
  
int main(){  
    memset(vis, 0, sizeof vis);  
    scanf("%s%s", s1, s2);  
    for(int i = 0; s1[i] != \0; ++i){  
        if(isupper(s1[i]))  ++u[s1[i] - A + 26];  
        else  ++u[s1[i] - a];  
    }  
    int ans1 = 0, ans2 = 0;  
    for(int i = 0; s2[i] != \0; ++i)  
        if(isupper(s2[i])){  
            if(u[s2[i] - A + 26] >= 1){  
                --u[s2[i] - A + 26];  
                ++ans1;  
                vis[i] = 1;  
            }  
        }  
        else{  
            if(u[s2[i] - a] >= 1){  
                --u[s2[i] - a];  
                ++ans1;  
                vis[i] = 1;  
            }  
        }  
    for(int i = 0; s2[i] != \0; ++i){  
        if(vis[i] == 1)  continue;  
        if(isupper(s2[i])){  
            if(u[s2[i] - A]){  
                --u[s2[i] - A];  
                ++ans2;  
            }  
        }  
        else{  
            if(u[s2[i] - a + 26]){  
                --u[s2[i] - a + 26];  
                ++ans2;  
            }  
        }  
    }  
    printf("%d %d\n", ans1, ans2);  
    return 0;  
}  

 

CodeForces 518B - Han Solo and Lazer Gun(模拟)