2014 Pacific Northwest Region Programming Contest—Division 2 Problem U — limit 10 seconds Top 25

In college football, many different sources create a list of the Top 25 teams in the country. Since
it’s subjective, these lists often differ, but they’re usually very similar. Your job is to compare two
of these lists, and determine where they are similar. In particular, you are to partition them into
sets, where each set represents the same consecutive range of positions in both lists, and has the
same teams, and is as small as possible. If the lists agree completely, you’ll have 25 lists (or n,
where n is an input). For these lists:
K&R Poll Lovelace Ranking
A A
B C
C D
D B
E E
You’ll have 3 sets:
A
B C D
E
Input
The input will start with a single integer on one line giving the number of test cases. There will
be at least one but not more than 100 test cases. Each test case will begin with an integer N,
1 ≤ N ≤ 1,000,000, indicating the number of teams ranked. The next N lines will hold the first
list, in order. The team names will appear one per line, consist of at most 8 capital letters only.
After this will be N lines, in the same format, indicating the second list. Both lists will contain
the same team names, and all N team names will be unique.
Output
For each test case, simply output the size of each set, in order, on one line, with the numbers
separated by a single space. Do not output any extra spaces, and do not output blank lines
between numbers.
2014 Pacific Northwest Region Programming Contest—Division 2 21
Sample Input Sample Output
3
5
A
B
C
D
E
A
C
D
B
E
3
RED
BLUE
ORANGE
RED
BLUE
ORANGE
3
MOE
LARRY
CURLY
CURLY
MOE
LARRY
1 3 1
1 1 1
3

集合的基本操作而已;
比较水的,当时还以为比较难。。。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<string>
#include<bitset>
#include<ctime>
#include<deque>
typedef long long ll;
using namespace std;
typedef unsigned long long int ull;
#define maxn 300005
#define ms(x) memset(x,0,sizeof(x))
#define Inf 0x7fffffff
#define inf 0x3f3f3f3f
const long long int mod = 1e9 + 7;
#define pi acos(-1.0)
#define pii pair<int,int>
#define eps 1e-7
#define pll pair<ll,ll>



ll quickpow(ll a, ll b) {
    ll ans = 1;
    a = a % mod;
    while (b > 0) {
        if (b % 2)ans = ans * a;
        b = b / 2;
        a = a * a;
    }
    return ans;
}

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a%b);
}


int n;
set<string>a, b;
string  pre[maxn], nxt[maxn];
int stor1[maxn], stor2[maxn];
int main()
{
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while (T--) {
        cin >> n;
        int i, j;
        a.clear();
        b.clear();
        memset(stor1, 0, sizeof(stor1));
        for (i = 0; i < n; i++) {
            cin >> pre[i];
        }
        for (i = 0; i < n; i++) {
            cin >> nxt[i];
        }
        int tot = 0;
        for (i = 0; i < n; i++) {
            a.insert(pre[i]);
            b.insert(nxt[i]);
            if (a == b) {
                stor1[tot]++;
                tot++;
                a.clear();
                b.clear();
                continue;
            }
            else {
                stor1[tot]++;
                continue;
            }
        }
        for (i = 0; i < tot-1; i++) {
            cout << stor1[i] << ' ';
        }
        cout << stor1[tot - 1] << endl;
    }
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值