CodeForces 518B - Han Solo and Lazer Gun

原创 2016年08月28日 20:43:41
题意:给定两个串(长度范围为 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 Round #291 (Div. 2) B. Han Solo and Lazer Gun

B. Han Solo and Lazer Gun time limit per test 1 second memory limit per test 256 megabytes inp...

【codeforces 514B】Han Solo and Lazer Gun

【题目链接】:http://codeforces.com/contest/514/problem/B【题意】 每次攻击可以把经过自己的一条直线上的所有点都毁掉; 然后给你n个目标物的坐标 问...

Codeforces 514 B . Han Solo and Lazer Gun 精度 除0

传送门:http://codeforces.com/contest/514/problem/B B. Han Solo and Lazer Gun time limit per test 1 ...

Codeforces Round #291 (Div. 2) -- B. Han Solo and Lazer Gun (计算几何~暴力)

B. Han Solo and Lazer Gun time limit per test 1 second memory limit per test 256 megabyt...

CodeForces 518B Tanya and Postcard 计数

先来错误代码, Wrong answer test 8: #include #include #include #include #include using namespace std;...

Codeforces 518D Ilya and Escalator【概率dp】

D. Ilya and Escalator time limit per test 2 seconds memory limit per test 256 megabytes i...

Codeforces 518D Ilya and Escalator

D. Ilya and Escalator time limit per test 2 seconds memory limit per test 256 megabytes input ...

Codeforces 518C Anya and Smartphone【思维+模拟】

C. Anya and Smartphone time limit per test 1 second memory limit per test 256 megabytes i...

codeforces 518 C. Anya and Smartphone

C. Anya and Smartphone time limit per test 1 second memory limit per test 256 megabytes input ...

Codeforces 518D Ilya and Escalator (概率dp)

Codeforces 518D Ilya and Escalator (概率dp)
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:CodeForces 518B - Han Solo and Lazer Gun
举报原因:
原因补充:

(最多只允许输入30个字)