化学-模拟题(原题Codeforces Gym-270437A)

Isabel ·
更新时间:2024-09-21
· 952 次阅读

问题描述

\hspace{17pt}化学很神奇,以下是烷烃基。
在这里插入图片描述
\hspace{17pt}假设如上图,这个烷烃基有6个原子和5个化学键,6个原子分别标号1~6,然后用一对数字 a,b 表示原子a和原子b间有一个化学键。这样通过5行a,b可以描述一个烷烃基。
\hspace{17pt}你的任务是甄别烷烃基的类别。
\hspace{17pt}原子没有编号方法,比如:
\hspace{17pt} 1 2
\hspace{17pt} 2 3
\hspace{17pt} 3 4
\hspace{17pt} 4 5
\hspace{17pt} 5 6
\hspace{17pt} 和
\hspace{17pt} 1 3
\hspace{17pt} 2 3
\hspace{17pt} 2 4
\hspace{17pt} 4 5
\hspace{17pt} 5 6
\hspace{17pt}是同一种,本质上就是一条链,编号其实是没有关系的,可以在纸上画画就懂了。

Input

\hspace{17pt}输入第一行为数据的组数T(1≤T≤200000)。每组数据有5行,每行是两个整数a, b(1≤a,b≤6,a ≤b)。
\hspace{17pt}数据保证,输入的烷烃基是以上5种之一。

Output

\hspace{17pt}每组数据,输出一行,代表烷烃基的英文名。

Sample Input 2 1 2 2 3 3 4 4 5 5 6 1 4 2 3 3 4 4 5 5 6 Sample Output n-hexane 3-methylpentane 解题思路 我的做法

\hspace{17pt}这个题是一个找规律的题,观察上面五种烷烃的不同,无非就是每个原子度数的不同。
n−hexane\hspace{17pt}n-hexanen−hexane有两个一度原子,四个二度原子。
2,3−dimethylbutane\hspace{17pt}2,3-dimethylbutane2,3−dimethylbutane有四个一度原子,两个三度原子。
2,2−dimethylbutane\hspace{17pt}2,2-dimethylbutane2,2−dimethylbutane有四个一度原子,一个两度原子,一个四度原子。
2−methylpentane\hspace{17pt}2-methylpentane2−methylpentane和3−methylpentane3-methylpentane3−methylpentane都是有三个一度原子,两个二度原子,一个三度原子。但是2−methylpentane2-methylpentane2−methylpentane的三度原子和两个一度原子相邻,而3−methylpentane3-methylpentane3−methylpentane的三度原子和一个一度原子相邻。
\hspace{17pt}代码中,使用num[x]表示x号原子的度数是num[x],ans[y]表示度数为y的原子出现了ans[y]次,代码如下:

if(ans[1]==2 && ans[2]==4) cout<<"n-hexane"<<endl; else if(ans[4]==1) cout<<"2,2-dimethylbutane"<<endl; else if(ans[3]==2) cout<<"2,3-dimethylbutane"<<endl; else { int flag=0; for (int j=1; j<=6; j++){ if((num[a[j]]==1 && num[b[j]]==3) || (num[a[j]]==3 && num[b[j]]==1)) flag++; } if(flag==2) cout<<"2-methylpentane"<<endl; else cout<<"3-methylpentane"<<endl; } 学长做法

\hspace{17pt}利用deg[x][y]表示有几对度数为x的点与度数为y的点相连,这样代码就非常精简。代码如下:

if(deg[4][1]==3) printf("2,2-dimethylbutane\n"); else if(deg[3][3]==2) printf("2,3-dimethylbutane\n"); else if(deg[3][2]==2) printf("3-methylpentane\n"); else if(deg[3][2]==1) printf("2-methylpentane\n"); else printf("n-hexane\n"); 完整代码 //#pragma GCC optimize(2)//比赛禁止使用! //#pragma G++ optimize(2) //#include #include #include #include #include #include #include #include #include #include #include using namespace std; int getint() { int x=0,s=1; char ch=' '; while(ch'9') { ch=getchar(); if(ch=='-') s=-1; } while(ch>='0' && ch>T; for (int i=1; i<=T; i++) { for (int j=1; j<=6; j++) { num[j]=0; ans[j]=0; } for (int j=1; j>a[j]>>b[j]; num[a[j]]++; num[b[j]]++; } for (int j=1; j<=6; j++) ans[num[j]]++; if(ans[1]==2 && ans[2]==4) cout<<"n-hexane"<<endl; else if(ans[4]==1) cout<<"2,2-dimethylbutane"<<endl; else if(ans[3]==2) cout<<"2,3-dimethylbutane"<<endl; else { int flag=0; for (int j=1; j<=6; j++){ if((num[a[j]]==1 && num[b[j]]==3) || (num[a[j]]==3 && num[b[j]]==1)) flag++; } if(flag==2) cout<<"2-methylpentane"<<endl; else cout<<"3-methylpentane"<<endl; } } return 0; }
作者:龙征天



gym 化学 CodeForces

需要 登录 后方可回复, 如果你还没有账号请 注册新账号