http://acm.timus.ru/problem.aspx?space=1&num=1932

B - The Secret of Identifier
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit Status Practice URAL Description
Davy 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. Input
The first line contains an integer n –– the number of pirates aboard the Black Pearl ( ≤ n ≤ ). 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. Output
Output four space separated integers –– the amount of pairs of pirates, which have different identifiers exactly in one, two, three and four positions respectively. Sample Input
input output dead
beef
f00d

题目(格式混乱,请点击上面链接查看原题)

给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的数量可以开始先打好表,也可以每次算一下,我是先打好表的。

 //最终版本,我哭了
#include<cstdio>
#include<cstring>
typedef long long ll;
const ll MAXN=;
const ll psn=;
const ll ps[psn]= {0x000f,0x00f0,0x00ff,0x0f00,0x0f0f,0x0ff0,0x0fff,0xf000,
0xf00f,0xf0f0,0xf0ff,0xff00,0xff0f,0xfff0,0xffff};
const ll pa[psn]= {,,,,,,,,,,,,,,};
ll t[MAXN],a[MAXN],ans[];
ll C(ll a,ll b){
ll re=;
for(ll i=;i<b;i++){
re=re*(a-i)/(i+);
}
return re;
} int main()
{
int i,j,n;
while(scanf("%d",&n)!=EOF)
{
memset(ans,,sizeof(ans));
for(i=; i<n; i++)
scanf("%x",&a[i]);
for(i=; i<psn; i++)
{
memset(t,,sizeof(t));
for(j=; j<n; j++)
t[a[j]&ps[i]]++;
for(j=; j<=0xffff; j++)
ans[pa[i]]+=t[j]*(t[j]-)/;
}
for(i=; i>; i--)
for(j=;j<i;j++)
ans[j]-=C(i,j)*ans[i];
ans[]=C(n,)-ans[]-ans[]-ans[];
printf("%I64d %I64d %I64d %I64d\n",ans[],ans[],ans[],ans[]);
}
return ;
}

URAL 1932 The Secret of Identifier 题解的更多相关文章

  1. URAL 1932 The Secret of Identifier(容斥)

    Description Davy Jones: You've been captain of the Black Pearl for 13 years. That was our agreement. ...

  2. ural 1932 The Secret of Identifier (容斥原理)

    标题效果: 计算到n字符串. 精确到只是有一个不同的字符,两个不同的字符.三个不同的字符,四对不同的字符. IDEAS: 枚举状态. dp[i] [j] ...当前串取出 i 状态下的全部字符转化成十 ...

  3. ural 1932 The Secret of Identifier 容斥

    主题链接:点击打开链接 stl+容斥 #include <cstdio> #include <cstring> #include <algorithm> #incl ...

  4. Ural 1201 Which Day Is It? 题解

    目录 Ural 1201 Which Day Is It? 题解 题意 输入 输出 题解 程序 Ural 1201 Which Day Is It? 题解 题意 打印一个月历. 输入 输入日\((1\ ...

  5. URAL 1707. Hypnotoad&#39;s Secret(树阵)

    URAL 1707. Hypnotoad's Secret space=1&num=1707" target="_blank" style="" ...

  6. URAL题解三

    URAL题解三 URAL 1045 题目描述:有\(n\)个机场,\(n-1\)条航线,任意两个机场有且只有一种方案联通.现有两个恐怖分子从\(m\)号机场出发,第一个人在机场安装炸弹,乘坐飞机,引爆 ...

  7. URAL题解二

    URAL题解二 URAL 1082 题目描述:输出程序的输入数据,使得程序输出"Beutiful Vasilisa" solution 一开始只看程序的核心部分,发现是求快排的比较 ...

  8. URAL题解一

    URAL题解一 URAL 1002 题目描述:一种记住手机号的方法就是将字母与数字对应,如图.这样就可以只记住一些单词,而不用记住数字.给出一个数字串和n个单词,用最少的单词数来代替数字串,输出对应的 ...

  9. ural 1707. Hypnotoad's Secret(线段树)

    题目链接:ural 1707. Hypnotoad's Secret 题目大意:给定N和M,然后N组s0, t0, Δs, Δt, k,每组能够计算出k个星星的坐标:M组a0, b0, c0, d0, ...

随机推荐

  1. Activiti系列:如何让Activiti-Explorer使用sql server数据库

    从官网下载的Activiti-explorer的war文件内部默认是使用h2内存数据库的,如果想改用其他的数据库来做持久化,比如sql server,需要做如下配置. 1)修改db.propertie ...

  2. [MetaHook] Load TGA texture to OpenGL

    This function load a *.tga texture file and convert to OpenGL pixel format, uncompress only. #pragma ...

  3. Week2学习过程报告

    一.学习内容 1. 熟悉Linux系统下的开发环境   2. 熟悉vi的基本操作   3. 熟悉gcc编译器的基本原理   4. 熟练使用gcc编译器的常用选项   5 .熟练使用gdb调试技术    ...

  4. UIAccessibilityElement

    UIaccessibilityElement类封装的项目信息对一些特殊的人可见,默认情况下是不可访问的.例如,一个图标或文字图像不会自动访问,因为它没有继承的UIView(或UIControl).一个 ...

  5. aptana studio 3汉化方法 及支持jquery的方法

    之前看弦哥的 Asp.Net大型项目实践系列第二季(一)哥欲善其事,必先利其器 看到他介绍了aptana,好像用来学习js是个好工具... 因为不论你写什么,都会提示你它在各个浏览器中是否被支持... ...

  6. 安装.NET CORE

    需要安装两个包 https://github.com/dotnet/cli 1. .NET Core Installer 2. .NET Core SDK Installer

  7. 微信小程序全面实战,架构设计 && 躲坑攻略(小程序入门捷径教程)

    最近集中开发了两款微信小程序,分别是好奇心日历(每天一条辞典+一个小投票)和好奇心日报(轻量版),直接上图: Paste_Image.png 本文将结合具体的实战经验,主要介绍微信小程序的基础知识.开 ...

  8. [USACO]6.1.3 cow xor(二进制+Trie)

    题意:给你一个序列(n<=100000),求出一个连续的子序列[i,j]使得ai xor ai+1 xor…… xor aj最大,求出这个最大值(其中每个数<=2^21) 分析:题目和求一 ...

  9. codevs1227 方格取数2 注意数组啊啊啊啊啊啊啊啊啊啊

    一开始T了一组RE了一组,实在找不出错来,就把数组加了一个0竟然就多A了一组.很惊讶的又加了几个0最后竟然全A了!!! 懒得做了,改的是之前的那个蚯蚓的游戏问题.还是需要拆点,至于为什么不能重复走结点 ...

  10. Hibernate-一对多的关系维护

    一对多 和多对一 一般是看需求来确定的,很多时候都是设置成双向的 举个最最普通的离子 :一个班级里面有多个学生 多个学生属于一个班级 从学生表来看 就是多对一的关系 从班级表来看就是一对多的关系 需求 ...