Sicily 8842. Mirko's Exam

8842. Mirko's Exam

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

Mirko-wan has just received the results of his history exam. One of the problems was putting famous historical battles into chronological order. The correct order was:
1. Blockade of Naboo 2. Battle of Geonosis 3. Battle of Yavin 4. Battle of Hoth 5. Battle of Endor
Mirko-wan has studied (relatively) hard for the exam, so he remembered the exact years of all battles, except for the Blockade of Naboo. He couldn't remember anything about it, so he randomly placed it last instead of first, obtaining the order:
1. Battle of Geonosis 2. Battle of Yavin 3. Battle of Hoth 4. Battle of Endor 5. Blockade of Naboo
Since Mirko-wan's order doesn't match the correct solution at any index, Mirko-wan's score on that problem was – to his disappointment – 0 out of 5 points, even though he knew the correct order of four out of five battles!
This opens the question of fair scoring of an ordering problem. The example given above suggests that scoring by counting the number of items in the correct absolute position isn't fair. Is there a better way?
One possibility is finding the longest subsequence (not necessarily contiguous) of correctly ordered items. This isn't the best solution either: if an item is displaced by just one position from the correct order, the score that it awards drops to zero, even though it was almost correctly ordered.
Mirko-wan has thus suggested (using the MAWT – Might As Well Try a Mind Trick approach) the following scoring method to his history teacher. For every two items, the student will receive 1 point if the two items are in mutually correct order. In other words, the number of points is the number of item pairs that the student has correctly ordered. The maximum number of points is then, of course, the total number of pairs, which equals N * (N - 1) / 2, where N is the total number of entries.

Input

The first line of input contains the positive integer N (2 ≤ N ≤ 2500), the number of items. The items are distinct words consisting of 3 to 15 lowercase English letters.
The second line of input contains the N items, space-separated, listed in the correct order.
The third line of input contains the N items, space-separated, listed in Mirko-wan's order.

Output

The first and only line of output must contain, with no spaces, the following: the number of points that Mirko-wan would earn using his scoring method, a / (forward slash) character, and the maximum possible number of points for that problem (again assuming Mirko-wan's scoring method). (This is the usual notation found on a typical graded exam.)

Sample Input

样例1:
3
alpha beta gamma
alpha gamma beta
样例2:
5
naboo geonosis yavin hoth endor
geonosis yavin hoth endor naboo

Sample Output

样例1:
2/3
样例2:
6/10

Problem Source

2013年每周一赛第七场/COCI 2012.12

// Problem#: 8842
// Submission#: 3544131
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main() {

    std::ios::sync_with_stdio(false);

    int N;
    cin >> N;
    map<string, int> m;
    string temp;
    for (int i = 0; i < N; i++) {
        cin >> temp;
        m[temp] = i;
    }
    int pos[2505];
    for (int i = 0; i < N; i++) {
        cin >> temp;
        pos[i] = m[temp];
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            if (pos[i] < pos[j]) ans++;
        }
    }
    cout << ans << '/' << N * (N - 1) / 2 << endl;

    return 0;
}                                 


1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值