codeforces1000a csdn-博客

Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners.

The valid sizes of T-shirts are either “M” or from 00 to 33 “X” followed by “S” or “L”. For example, sizes “M”, “XXS”, “L”, “XXXL” are valid and “XM”, “Z”, “XXXXL” are not.

There are nn winners to the cup for both the previous year and the current year. Ksenia has a list with the T-shirt sizes printed for the last year cup and is yet to send the new list to the printing office.

Organizers want to distribute the prizes as soon as possible, so now Ksenia is required not to write the whole list from the scratch but just make some changes to the list of the previous year. In one second she can choose arbitrary position in any word and replace its character with some uppercase Latin letter. Ksenia can’t remove or add letters in any of the words.

What is the minimal number of seconds Ksenia is required to spend to change the last year list to the current one?

The lists are unordered. That means, two lists are considered equal if and only if the number of occurrences of any string is the same in both lists.

Input
The first line contains one integer nn (1≤n≤1001≤n≤100) — the number of T-shirts.

The ii-th of the next nn lines contains aiai — the size of the ii-th T-shirt of the list for the previous year.

The ii-th of the next nn lines contains bibi — the size of the ii-th T-shirt of the list for the current year.

It is guaranteed that all the sizes in the input are valid. It is also guaranteed that Ksenia can produce list bb from the list aa.

Output
Print the minimal number of seconds Ksenia is required to spend to change the last year list to the current one. If the lists are already equal, print 0.

Examples
Input
3
XS
XS
M
XL
S
XS
Output
2
Input
2
XXXL
XXL
XXL
XXXS
Output
1
Input
2
M
XS
XS
M
Output
0
Note
In the first example Ksenia can replace “M” with “S” and “S” in one of the occurrences of “XS” with “L”.

In the second example Ksenia should replace “L” in “XXXL” with “S”.

In the third example lists are equal.

  • 题意:给你两组字符串,求把第一组字符串装换成第二组时要变化多少次。其中字符串形式是固定的几种,且变化时不能增多也不能减少。

  • 解题思路:根据题意,当字符串长度为一时,有不同的情况。因此,可以把字符串为一的字符单独记录有多少个,然后比较即可。对于长度不是一的,可以每个不同的只需变化一次,排序后一次比较即可,也可以单独记录比较。

#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
using namespace std;
int n;
vector<string>g[4],h[4];
int a1=0,a2=0,a3=0,b1=0,b2=0,b3=0;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string s;cin>>s;
        if(s.size()==1){
            if(s=="M")a1++;
            if(s=="S")a2++;
            if(s=="L")a3++;
            continue;
        }
        g[s.size()-1].push_back(s);

    }
    for(int i=0;i<n;i++)
    {
        string s;cin>>s;
        if(s.size()==1){
            if(s=="M")b1++;
            if(s=="S")b2++;
            if(s=="L")b3++;
            continue;
        }
        h[s.size()-1].push_back(s);
    }
    sort(g[1].begin(),g[1].end());
    sort(g[2].begin(),g[2].end());
    sort(g[3].begin(),g[3].end());
    sort(h[1].begin(),h[1].end());
    sort(h[2].begin(),h[2].end());
    sort(h[3].begin(),h[3].end());
    int ans=0;
    ans=a1+a2+a3-min(a1,b1)-min(a2,b2)-min(a3,b3);
    for(int i=0;i<g[1].size();i++)
    {
        if(g[1][i]!=h[1][i]){
            ans++;
        }
    }
    for(int i=0;i<g[2].size();i++)
    {
        if(g[2][i]!=h[2][i]){
            ans++;
        }
    }
    for(int i=0;i<g[3].size();i++)
    {
        if(g[3][i]!=h[3][i]){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CodeForces - 616D是一个关于找到一个序列中最长的第k好子段的起始位置和结束位置的问题。给定一个长度为n的序列和一个整数k,需要找到一个子段,该子段中不超过k个不同的数字。题目要求输出这个序列最长的第k好子段的起始位置和终止位置。 解决这个问题的方法有两种。第一种方法是使用尺取算法,通过维护一个滑动窗口来记录\[l,r\]中不同数的个数。每次如果这个数小于k,就将r向右移动一位;如果已经大于k,则将l向右移动一位,直到个数不大于k。每次更新完r之后,判断r-l+1是否比已有答案更优来更新答案。这种方法的时间复杂度为O(n)。 第二种方法是使用枚举r和双指针的方法。通过维护一个最小的l,满足\[l,r\]最多只有k种数。使用一个map来判断数的种类。遍历序列,如果当前数字在map中不存在,则将种类数sum加一;如果sum大于k,则将l向右移动一位,直到sum不大于k。每次更新完r之后,判断i-l+1是否大于等于y-x+1来更新答案。这种方法的时间复杂度为O(n)。 以上是两种解决CodeForces - 616D问题的方法。具体的代码实现可以参考引用\[1\]和引用\[2\]中的代码。 #### 引用[.reference_title] - *1* [CodeForces 616 D. Longest k-Good Segment(尺取)](https://blog.csdn.net/V5ZSQ/article/details/50750827)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Codeforces616 D. Longest k-Good Segment(双指针+map)](https://blog.csdn.net/weixin_44178736/article/details/114328999)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值