zoukankan      html  css  js  c++  java
  • 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.
    ");
    61         else
    62            printf("No two snowflakes are alike.
    ");
    63     }
    64     return 0;
    65 
    66 }
    View Code
  • 相关阅读:
    自己重写HTMLEditorExtender控件
    Sys.InvalidOperationException: A control is already associated with the element 错误处理方法
    navigationbar tabbar 状态栏的 高度
    iOS之正则表达式(转载)
    Mesonry的使用方法
    SimulatorXcode模拟器如何使用PC键盘进行输入
    Masonry第三方代码约束
    卸载openfire
    安装和使用cocoapods
    js选择颜色小游戏(随机生成不含重复数字的数组,通过数组中的数控制定义好的数组)
  • 原文地址:https://www.cnblogs.com/sdau--codeants/p/3392883.html
Copyright © 2011-2022 走看看