Acwing第46场周赛-2022/4/9


1.题目链接 4396.取石子

#include 
#include 
#include 

using namespace std;

int n1, n2, k1, k2;

int main()
{
    cin >> n1 >> n2 >> k1 >> k2;
    
    if(n1 <= n2) puts("Second");
    else if(n1 > n2) puts("First");

    return 0;
}

2.题目链接 4397.卡牌

#include 
#include 
#include 
#include 

using namespace std;

const int N = 200010;

int n, m;
int a[N], b[N];
int ans;
priority_queue q;

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i ++ )
    {
        scanf("%d", &a[i]);
        ans += a[i];
    }
    for (int i = 1; i <= n; i ++ ) scanf("%d", &b[i]);
    for (int i = 1; i <= n; i ++ )
    {
        int c = a[i] - b[i];  //差值越大越好
        q.push(c);
    }
   // cout << ans << endl;
    while(q.size() > m)
    {
        auto t = q.top();
        //cout << t << endl;
        if(t < 0) break;
        q.pop();
        ans -= t;
    }
    printf("%d\n", ans);
    return 0;
}

3.题目链接 4398.查询字符串

#include 
#include 
#include 
#include 
#include 

using namespace std;

const int N = 10010;

char str[N][10];
map heap;
map mp;
map hs;

void mp_insert(string str, int k)
{
    set st;
    int len = str.size();
    for(int i = 0; i < len; i ++)
        for(int j = 1; j <= len - i; j ++)
            st.insert(str.substr(i, j));
    for(auto x : st) mp[x] ++, hs[x] = k;
}

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i ++ )
    {
        cin >> str[i];
        heap[i] = str[i];
        mp_insert(str[i], i);
    }
    //for(auto [a, b] : heap) cout << a << ' ' << b << endl;
    
    //cout << endl << endl << endl;
    
    //for(auto [a, b] : mp) cout << a << ' ' << b << endl;
    int m;
    cin >> m;
    while (m -- )
    {
        string s;
        cin >> s;
        if(mp.count(s))
        {
            int t = hs[s];
            cout << mp[s] << ' ' << heap[t] << endl;
        }
        else cout << "0 -" << endl;
    }
    
    return 0;
    
}