这套题是我上周日, 就是前天打得一场组队赛, 题目不太好找

题目链接:http://codeforces.com/gym/100861 在virtual judge 上也可以提交哦!

A ACM ICPC Rules:

  题目大意: 有很多所高校参加预选赛, 并在预选赛取得了排名, 但是对于每所学校, 除了MSU有4个名额之外其他大学只有两个名额( 也就是说, 只有每个大学的前2名进决赛(MSU前四名)&& 最多有10个队伍进入决赛), 高中队伍不能进入决赛。 给出预选赛的排名, 输出可以进入决赛的名单,( 最多十个 )

  题目分析: 这道题还是看题解出来的, 感觉自己做的题太少了, 很多题能做出来就是做的方法添麻烦, 所以以后要多做题夯实, 首先如果遇到"SCH"就continue,  创建一个MAP<string, int>记录每种字符串出现的次数, 再创建一个vector<pair<string, string>> V 储存进入MSU 的排名。

 

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

vector<pair<string, string>> V;
map<string, int> MAP;

int main() {
    int n;
    while( cin >> n ) {
        int lim = 0;
        for( int i = 1; i <= n; i++ ) {
            string a, b;
            cin >> a >> b;
            if( a == "SCH" ) continue;
            else {
                if( a == "MSU" ) lim = 4;
                else lim = 2;
            }
            if( MAP[a] < lim ) {
                MAP[a]++;
                V.push_back( make_pair( a, b ) );
            }
        }
        int ans1 = min( 10, (int)V.size() );
        cout << ans1 << endl;
        for( int i = 0; i < ans1; i++ ) {
            cout << V[i].first << " ";
            cout << V[i].second << endl;
        }
    }
    return 0;
}
View Code

相关文章:

  • 2021-06-05
  • 2022-01-23
  • 2022-01-09
  • 2021-10-10
  • 2022-01-04
  • 2021-11-02
  • 2022-01-01
猜你喜欢
  • 2021-10-10
  • 2021-09-16
  • 2022-12-23
  • 2021-09-19
  • 2021-05-19
  • 2021-07-13
  • 2022-12-23
相关资源
相似解决方案