题解 | Stammering Chemists-2019牛客暑期多校训练营第十场H题

题目来源于牛客竞赛:https://ac.nowcoder.com/acm/contest/discuss
题目描述:
在这里插入图片描述
输入描述:
在这里插入图片描述
输出描述:
在这里插入图片描述
示例1:
在这里插入图片描述
题解:
在这里插入图片描述
代码:

#include <bits/stdc++.h>
using namespace std;

typedef array<pair<int, int>, 5> molecule;
molecule isomer[] = {
    { { {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6} } }, // n-hexane
    { { {1, 3}, {2, 3}, {3, 4}, {4, 5}, {5, 6} } }, // 2-methylpentane
    { { {1, 4}, {2, 3}, {3, 4}, {4, 5}, {5, 6} } }, // 3-methylpentane
    { { {1, 4}, {2, 5}, {3, 4}, {4, 5}, {5, 6} } }, // 2,3-dimethylbutane
    { { {1, 4}, {2, 4}, {3, 4}, {4, 5}, {5, 6} } }, // 2,2-dimethylbutane
};

const char *name[] = {
    "n-hexane", "2-methylpentane", "3-methylpentane",
    "2,3-dimethylbutane", "2,2-dimethylbutane"
};

molecule canonicalize(molecule mol) {
    for (auto& p : mol) if (p.first > p.second) swap(p.first, p.second);
    sort(mol.begin(), mol.end());
    return mol;
}

map<molecule, int> moltype;

void init() {
    for (int i = 0; i < 5; i++) {
        molecule mol = isomer[i];
        int perm[7]; iota(perm + 1, perm + 7, 1);
        do {
            molecule cm = mol;
            for (auto& p : cm) {
                p.first = perm[p.first];
                p.second = perm[p.second];
            }
            moltype[canonicalize(cm)] = i;
        } while (next_permutation(perm + 1, perm + 7));
    }
}

int main() {
    init();
    int T; scanf("%d", &T);
    while (T--) {
        molecule mol;
        for (int i = 0; i < 5; i++)
            scanf("%d%d", &mol[i].first, &mol[i].second);
        puts(name[moltype.at(canonicalize(mol))]);
    }
    return 0;
}

更多问题,更详细题解可关注牛客竞赛区,一个刷题、比赛、分享的社区。
传送门:https://ac.nowcoder.com/acm/contest/discuss

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值