Snowflake Snow Snowflakes 根据相似度排序,有点暴力
Problem Description
You may have heard that no two snowflakes are alike. Your task is to write a program to determine whether this is really true. Your program will read information about a collection of snowflakes, and search for a pair that may be identical. Each snowflake has six arms. For each snowflake, your program will be provided with a measurement of the length of each of the six arms. Any pair of snowflakes which have the same lengths of corresponding arms should be flagged by your program as possibly identical.
Input
The first line of input will contain a single integer n, 0 < n ≤ 100000, the number of snowflakes to follow. This will be followed by n lines, each describing a snowflake. Each snowflake will be described by a line containing six integers (each integer is at least 0 and less than 10000000), the lengths of the arms of the snow ake. The lengths of the arms will be given in order around the snowflake (either clockwise or counterclockwise), but they may begin with any of the six arms. For example, the same snowflake could be described as 1 2 3 4 5 6 or 4 3 2 1 6 5.
Output
If all of the snowflakes are distinct, your program should print the message: No two snowflakes are alike. If there is a pair of possibly identical snow akes, your program should print the message: Twin snowflakes found.
Sample Input
2
1 2 3 4 5 6
4 3 2 1 6 5
Sample Output
Twin snowflakes found.
***************************************************************************************************************************
排序有技巧
***************************************************************************************************************************

1 #include<iostream> 2 #include<string> 3 #include<cstring> 4 #include<cstdio> 5 #include<cmath> 6 #include<queue> 7 #include<algorithm> 8 using namespace std; 9 const int maxn=100200; 10 struct node 11 { 12 int f[6]; 13 }no[100200]; 14 int i,j,k,n; 15 bool cmp1(int a,int b)//对每个根据大小排序 16 { 17 return a<b; 18 } 19 bool cmp2(node a,node b)//根据相似度排序 20 { 21 int it; 22 //struct node *a=(struct node*)c; 23 //struct node *b=(struct node*)d; 24 for(it=0;it<6;it++) 25 if((a.f[it])!=(b.f[it])) 26 return (a.f[it])>(b.f[it]); 27 return true; 28 } 29 int main() 30 { 31 int a[7]; 32 while(scanf("%d",&n)!=EOF) 33 { 34 for(i=0;i<n;i++) 35 { 36 for(j=0;j<6;j++) 37 scanf("%d",&a[j]); 38 sort(a,a+6,cmp1); 39 for(j=0;j<6;j++) 40 no[i].f[j]=a[j]; 41 42 } 43 sort(no,no+n,cmp2); 44 bool gs; 45 for(i=0;i<n-1;i++)//根据相似度,前后比较 46 { 47 gs=true; 48 for(j=0;j<6;j++) 49 { 50 if(no[i].f[j]!=no[i+1].f[j]) 51 { 52 gs=false; 53 break; 54 } 55 } 56 if(gs==true) 57 break; 58 } 59 if(gs) 60 printf("Twin snowflakes found.\n"); 61 else 62 printf("No two snowflakes are alike.\n"); 63 } 64 return 0; 65 66 }
分类:
普通题
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
· ThreeJs-16智慧城市项目(重磅以及未来发展ai)
· 软件产品开发中常见的10个问题及处理方法
· Vite CVE-2025-30208 安全漏洞
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(四):结合BotSharp
· MQ 如何保证数据一致性?