列表

详情


NC50985. Snowflake Snow Snowflakes

描述

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 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.

输出描述

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.

示例1

输入:

2
1 2 3 4 5 6
4 3 2 1 6 5

输出:

Twin snowflakes found.

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 403ms, 内存消耗: 6752K, 提交时间: 2020-01-01 17:09:15

#include<iostream>
#include<map>
#define int long long
using namespace std;
const int mod=100007;
map<int,int> m;
signed main(){
    int n;
    int flag=0;
    cin>>n;
    while(n--){
        int ans=0;
        int x;
        int y=1;
        for(int i=1;i<=6;i++) {
            cin>>x;
            ans+=x;
            y*=x*x;
            ans%=mod;
        }
        ans+=y;
        if(m.count(ans)) flag=1;
        else m[ans]=1;
    }
    if(flag) cout<<"Twin snowflakes found."<<endl;
    else cout<<"No two snowflakes are alike."<<endl;
}

pypy3(pypy3.6.1) 解法, 执行用时: 995ms, 内存消耗: 41912K, 提交时间: 2021-04-02 12:50:21

n=int(input())
cnt=dict()
flag=0
f=[0]*6
f[0]=1
for i in range(1,6):
	f[i]=f[i-1]*10000000

for i in range(n):
	a=list(map(int,input().split()))
	for t in range(2):
		for k in range(6):
			sum=0
			for j in range(6):
				sum+=a[(j+k)%6]*f[j]
			if sum in cnt:
				if cnt[sum]!=i:
					flag=1
			if k==5 and t==1:
				cnt[sum]=i
		a=list(reversed(a))
if flag:
	print("Twin snowflakes found.")
else:
	print("No two snowflakes are alike.")

C++(clang++11) 解法, 执行用时: 290ms, 内存消耗: 6648K, 提交时间: 2021-02-27 10:05:29

#include<bits/stdc++.h>
using namespace std;
map<long long,bool> s;long long t,sum,mul,x;
signed main(){
	cin>>t;
	while(t--){
		sum=0,mul=1;
		for(int i=0;i<6;i++){
			cin>>x;sum+=x,mul*=x;
		}sum+=mul;
		if(s.find(sum)!=s.end()){
			puts("Twin snowflakes found.");return 0;
		}s[sum]=1;
	}puts("No two snowflakes are alike.");
	return 0;
}

Python3 解法, 执行用时: 406ms, 内存消耗: 18212K, 提交时间: 2023-07-27 19:44:17

n=int(input())
dic=set()
f=1
for _ in range(n):
    arr=input().split()
    q=','.join(sorted(arr))
    if q in dic:
        f=0
        print('Twin snowflakes found.')
    else: dic.add(q)
if f: print('No two snowflakes are alike.')

上一题