国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

相同的雪花

2019-11-14 11:21:39
字體:
來源:轉載
供稿:網友

相同的雪花

時間限制:1000 ms  |  內存限制:65535 KB難度:4描述 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.輸入The first line of the input will contain a single interger T(0<T<10),the number of the test cases.The first line of every test case 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.輸出For each test case,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.樣例輸入
121 2 3 4 5 64 3 2 1 6 5樣例輸出
Twin snowflakes found.

解題報告:Hash算法的簡單應用。對arms和Hash下就行了。

code:

#include<iostream>#include<stdio.h>#include<queue>#include<vector>#include<stack>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;const int maxn=100005;const int gcd=100000;int snow[maxn][6];  //存雪花arms值vector<int> v[maxn]; //存相同arms和的雪花bool deal(int a,int b){  //比較兩個雪花是否相同    for(int i=0;i<6;i++){        if(           (snow[a][0]==snow[b][i] &&      //順時針比較           snow[a][1]==snow[b][(i+1)%6] &&           snow[a][2]==snow[b][(i+2)%6] &&           snow[a][3]==snow[b][(i+3)%6] &&           snow[a][4]==snow[b][(i+4)%6] &&           snow[a][5]==snow[b][(i+5)%6])            ||           (snow[a][0]==snow[b][i] &&      //逆時針比較           snow[a][1]==snow[b][(i+5)%6] &&           snow[a][2]==snow[b][(i+4)%6] &&           snow[a][3]==snow[b][(i+3)%6] &&           snow[a][4]==snow[b][(i+2)%6] &&           snow[a][5]==snow[b][(i+1)%6])           )            return true;    }    return false;}int main(){  //  freopen("input.txt","r",stdin);    int t,n;    scanf("%d",&t);    while(t--){        memset(snow,0,sizeof(snow));        for(int i=0;i<maxn;i++){ //初始化            v[i].clear();        }        scanf("%d",&n);        for(int i=0;i<n;i++){            int sum=0;            for(int j=0;j<6;j++){                scanf("%d",&snow[i][j]);                sum+=snow[i][j];            }            sum=sum%gcd;            v[sum].push_back(i);        }        int flag=0;  //默認無相同雪花        for(int i=0;i<maxn;i++){            if(flag)                break;            if(v[i].size()>=2){                for(int j=0;j<v[i].size()-1;j++){                    for(int k=j+1;k<v[i].size();k++){                        if(deal(v[i][j],v[i][k])){                            flag=1;                            break;                        }                    }                }            }        }        if(!flag)            printf("No two snowflakes are alike./n");        else            printf("Twin snowflakes found./n");    }    return 0;}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阿瓦提县| 昭苏县| 莱西市| 淄博市| 鲁甸县| 斗六市| 龙州县| 贵定县| 龙里县| 华容县| 土默特右旗| 崇明县| 木兰县| 河源市| 平昌县| 长垣县| 长泰县| 沈阳市| 昭苏县| 德惠市| 长武县| 东至县| 禄劝| 南靖县| 滦南县| 八宿县| 柳河县| 沙坪坝区| 东辽县| 怀仁县| 集安市| 伊宁市| 呼和浩特市| 佛冈县| 会东县| 江西省| 安顺市| 横山县| 日土县| 肃宁县| 吉林市|