化学

*化学很神奇,以下是烷烃基。
在这里插入图片描述
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MqYtU2aR-1583418155654)(https://espresso.codeforces.com/40fbd94c6282f47ed4c3040ecd1b29b610a0a032.png)]
假设如上图,这个烷烃基有6个原子和5个化学键,6个原子分别标号1~6,然后用一对数字 a,b 表示原子a和原子b间有一个化学键。这样通过5行a,b可以描述一个烷烃基

你的任务是甄别烷烃基的类别。

原子没有编号方法,比如
1 2
2 3
3 4
4 5
5 6

1 3
2 3
2 4
4 5
5 6
是同一种,本质上就是一条链,编号其实是没有关系的,可以在纸上画画就懂了
Input
输入第一行为数据的组数T(1≤T≤200000)。每组数据有5行,每行是两个整数a, b(1≤a,b≤6,a ≤b)

数据保证,输入的烷烃基是以上5种之一

Output
每组数据,输出一行,代表烷烃基的英文名

Example
Input
2
1 2
2 3
3 4
4 5
5 6
1 4
2 3
3 4
4 5
5 6
Output
n-hexane
3-methylpentane*

分析:判断可以依据度数,后来发现2-methylpentane和3-methylpentane都是一个三度、两个二度、三个一度,🐕急跳墙强行修改,代码十分丑陋。
附上失败代码:

#include <iostream>
#include <string.h>

using namespace std;

pair<int, int> lines[6];
int numberOfLine[7];//每个点的度数
int degrees[5];

void judge()
{
	if (degrees[1] == 2)
		cout << "n-hexane" << endl;
	else if (degrees[1] == 3)
	{
		int x;
		for (int i = 1; i <= 6; i++)
		{
			if (numberOfLine[i] == 3)
				x = i;
		}
		int a[3];
		int j = 0;
		for (int i = 1; i <= 5; i++)
		{
			if (lines[i].first == x)
				a[j++] = lines[i].second;
			else if (lines[i].second == x)
				a[j++] = lines[i].first;
		}
		int sumOfDegree = numberOfLine[a[0]] + numberOfLine[a[1]] + numberOfLine[a[2]];
		if (sumOfDegree == 4)
			cout << "2-methylpentane" << endl;
		else
			cout << "3-methylpentane" << endl;
	}
	else if (degrees[1] == 4)
	{
		if (degrees[4] == 1)
			cout << "2,2-dimethylbutane" << endl;
		else
			cout << "2,3-dimethylbutane" << endl;
	}
}

int main()
{
	int N;
	cin >> N;
	int a, b;
	while (N--)
	{
		memset(numberOfLine, 0, 28);
		memset(degrees, 0, 20);

		for (int i=1;i<=5;i++)
		{
			cin >> a >> b;
			lines[i] = pair<int, int>(a, b);
			numberOfLine[a]++;
			numberOfLine[b]++;
		}

		for (int i = 1; i <= 6; i++)
		{
			degrees[numberOfLine[i]]++;
		}
		
		judge();
	}
	
}

正确方法是依据点a的度数和a相邻点的度数,如3-methylpentane有一个三度点,并且其相邻点中有两个度数为2,而同样有一个三度点的2-methylpentane相邻殿中只有一个度数为2,用二维数组deg[][],维度一为点a度数,唯独二为a相邻点b的度数,如deg[3][2]意思是维度为3的点相邻点中度数为2的个数
正确代码如下:

#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

#define rep(i,s,t) for(int i=s;i<=t;i++)

vector<int> G[7];
int deg[7][7];

int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		memset(deg, 0, sizeof(deg));

		rep(i, 1, 5)
		{
			int u, v;
			cin >> u >> v;
			G[u].push_back(v);
			G[v].push_back(u);
		}
		rep(i, 1, 6)
			for (auto& x : G[i])
				deg[G[i].size()][G[x].size()]++;
		if (deg[4][1] == 3) cout << "2,2-dimethylbutane\n";
		else if (deg[3][3] == 2) cout << "2,3-dimethylbutane\n";
		else if (deg[3][2] == 2) cout << "3-methylpentane\n";
		else if (deg[3][2] == 1) cout << "2-methylpentane\n";
		else cout << "n-hexane\n";
	}

	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值