博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
URAL 1932 The Secret of Identifier 题解
阅读量:6236 次
发布时间:2019-06-22

本文共 3043 字,大约阅读时间需要 10 分钟。

B - The Secret of IdentifierTime Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64uSubmit Status Practice URAL 1932DescriptionDavy Jones: You've been captain of the Black Pearl for 13 years. That was our agreement.Jack: Technically I was only captain for two years, then I was mutinied upon.Davy Jones: Then you were a poor captain, but a captain nonetheless. Have you not introduced yourself as Captain Jack Sparrow?According to the Pirate Code, each of the pirates of the Caribbean at the beginning of their professional career (hereditary pirates –– at birth) is assigned by a unique identifier. Pirate's identifier is a string of four hexadecimal digits. However, it is not a usual row of numbers, it is said that personal qualities and life path of its owner are encoded in it by a mysterious way. But no one still could guess this mystical connection.Once Captain Jack Sparrow, while sitting in captain’s cabin, decided to try to find the way to derive some data about a pirate using the identifier. Memories about how he lost the Black Pearl last time gave him the idea that more similar identifiers of two pirates are, bigger chances for these pirates to unite against the Captain, and, as a result, to make a mutiny. The Captain Jack Sparrow, of course, doesn’t want to have the mutiny on his ship, but he chose the new team this time and it is going to be a long voyage. Now Jack needs to estimate the opportunities of raising the mutiny on his ship, based on the conclusions. For this aim he first wants to know for each pair of pirates a number of positions in their identifiers in which they are different.InputThe first line contains an integer n –– the number of pirates aboard the Black Pearl (2 ≤ n ≤ 65536). Each of the following n lines contains four-digit identifier of the respective pirate. Only decimal digits and lowercase Latin letters from “a” to “f” inclusive are used in writing identifiers. Identifiers of all pirates are different.OutputOutput four space separated integers –– the amount of pairs of pirates, which have different identifiers exactly in one, two, three and four positions respectively.Sample Inputinput    output3deadbeeff00d    0 0 2 1
题目(格式混乱,请点击上面链接查看原题)

给n个不同的4位十六进制数,两两按位比较,输出有1位不同的、两位不同的、3位不同的、4位不同的组合的个数。(输出4个数)

先弄15个4位十六进制数,像掩码之类的一样,虽然我也不懂掩码具体是怎么弄的。比如现在用的是0F0F,和输入的那些数按位与(&)一下,得到数x,把a[x]++,最后统计a[i]>1的就是0F0F这两个F的位置相同的数的个数,然后这有2个F,就把代表2个相同的t[2]+=a[i]*(a[i]-1)/2;

好像有点说不清楚,不过就是这样!

掩码和F的数量可以开始先打好表,也可以每次算一下,我是先打好表的。

1 //最终版本,我哭了 2 #include
3 #include
4 typedef long long ll; 5 const ll MAXN=66666; 6 const ll psn=15; 7 const ll ps[psn]= {
0x000f,0x00f0,0x00ff,0x0f00,0x0f0f,0x0ff0,0x0fff,0xf000, 8 0xf00f,0xf0f0,0xf0ff,0xff00,0xff0f,0xfff0,0xffff}; 9 const ll pa[psn]= {
1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};10 ll t[MAXN],a[MAXN],ans[5];11 ll C(ll a,ll b){12 ll re=1;13 for(ll i=0;i
0; i--)36 for(j=1;j
View Code

 

转载于:https://www.cnblogs.com/yuiffy/p/3775515.html

你可能感兴趣的文章
使用ngnix做服务器的负载均衡
查看>>
盒子传值
查看>>
使用NSStream来实现Socket
查看>>
iPhone开发之调用系统提示音教程
查看>>
OAuth认证协议原理分析及使用方法
查看>>
二叉树
查看>>
linux 文件搜索命令
查看>>
黄聪:登陆页优化
查看>>
黄聪:Python+NLTK自然语言处理学习(一):环境搭建
查看>>
leetcode110
查看>>
剑指Offer 10 斐波那契数列
查看>>
Ruby之基本数据类型(三)
查看>>
集合框架
查看>>
技术总结
查看>>
mysql基本操作
查看>>
redis设置最大内存上限对置换策略的解读
查看>>
IOS代码布局(一) UIView
查看>>
北大光华管理学院公开课北京站
查看>>
android 随手记 图片缓存
查看>>
HTTP请求协议中请求报文(Request Headers)跟响应报文(Response Headers)的简单理解...
查看>>