麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

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

相同的雪花

2019-11-14 10:26:38
字體:
來源:轉載
供稿:網友

相同的雪花

時間限制: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;}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久久一区二区三区四区 | 欧美精品免费一区二区三区 | www亚洲成人| 亚洲成人在线视频网站 | 精品国产一区二区久久 | 好吊色37pao在线观看 | 91精品国产九九九久久久亚洲 | 日韩一级免费毛片 | 亚洲一区二区三区四区精品 | 一本色道久久综合狠狠躁篇适合什么人看 | 色综合久久久久综合99 | 国产一级在线免费观看 | av成人在线免费观看 | 国产成人精品免费视频大全最热 | 成人免费毛片在线观看 | 成人免费午夜视频 | 羞羞答答xxdd在线播放 | 3344永久免费 | 国产成人精品日本亚洲语音 | 免费久久久 | 国产精品999在线观看 | 免费人成在线观看网站 | 97风流梦电影 | 日韩精品久久久久久久九岛 | 国产午夜网| 中国产一级毛片 | 啊~用cao嗯力cao烂我视频 | 亚洲91网站 | 色淫影院 | 九九热在线精品视频 | 久久55| 欧美一区在线观看视频 | 狠狠干网站 | 青草久久av | 欧美久久久久久久久 | 中文在线观看视频 | 黄色成人在线播放 | 久久综合综合 | 久久tv免费国产高清 | 久草在线资源福利站 | 日韩欧美综合在线 |