zoukankan      html  css  js  c++  java
  • D

    http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1550

    很久都没补这题,最近想学网络流,就看看,队友以前用网络流过的,Orz,

    但是这题只需要简单的判断,可能想起来有点麻烦。

    考虑一定要从A串取出n个,B串也一定要取出n个,那么A和C的交集一定要大于等于n,同理B。

    同时为了得到C串,还需要A + B和C的交集一定要大于等于n * 2

    怎么说呢。可以画个图表示下,反正找不到反例。就先码一波。

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <assert.h>
    #define IOS ios::sync_with_stdio(false)
    using namespace std;
    #define inf (0x3f3f3f3f)
    typedef long long int LL;
    
    
    #include <iostream>
    #include <sstream>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <string>
    #include <bitset>
    const int maxn = 123456;
    char str[maxn], sub1[maxn], sub2[maxn];
    int hasStr[222], hasSub1[222], hasSub2[222];
    void work() {
        int lenstr = strlen(str + 1);
        memset(hasStr, 0, sizeof hasStr);
        memset(hasSub1, 0, sizeof hasSub1);
        memset(hasSub2, 0, sizeof hasSub2);
        for (int i = 1; i <= lenstr; ++i) hasStr[str[i]]++;
        for (int i = 1; i <= lenstr; ++i) hasSub1[sub1[i]]++;
        for (int i = 1; i <= lenstr; ++i) hasSub2[sub2[i]]++;
        int ans1 = 0, ans2 = 0, ans3 = 0;
        for (int i = 'A'; i <= 'Z'; ++i) {
            ans1 += min(hasStr[i], hasSub1[i]);
            ans2 += min(hasStr[i], hasSub2[i]);
            ans3 += min(hasStr[i], hasSub1[i] + hasSub2[i]);
        }
        if (ans1 < lenstr / 2 || ans2 < lenstr / 2 || ans3 < lenstr) {
            printf("NO
    ");
        } else printf("YES
    ");
    }
    
    int main() {
    #ifdef local
        freopen("data.txt", "r", stdin);
    //    freopen("data.txt", "w", stdout);
    #endif
        while (scanf("%s%s%s", sub1 + 1, sub2 + 1, str + 1) > 0) work();
        return 0;
    }
    View Code
  • 相关阅读:
    前端全链路优化总结
    到底使用字符数组还是字符串常量
    指针的误区
    指针
    函数使用初体验
    C语言函数使用小试牛
    十年研发经验工程师的嵌入式学习书籍大推荐与学习进阶路线
    TCP/IP协议前期的一知半解
    Ubuntu 16.04 LTS安装sogou输入法详解
    1/0信封——数据链路层,ARP及RARP
  • 原文地址:https://www.cnblogs.com/liuweimingcprogram/p/6934767.html
Copyright © 2011-2022 走看看