URAL 1932 The Secret of Identifier(容斥)
Description
Input
Output
题目大意:给n个字符串,每个字符串有4个字符(其实是4位16进制数),输出这些字符串中有1位不同的字符串个数、有2位不同的字符串个数、有3位不同的字符串个数、有4位不同的字符串个数.
思路:用一个数组sum[i][j]存下在状态 i 下 j 的出现次数,如sum[3][244]就代表XXF4的出现次数:其中3是二进制的0011,代表是计算最后两位的出现次数,前面两位为任意字符;F4(10进制为244)则为后两位为F4的字符串的出现次数;XX为任意字符。
那么,扫一遍,统计一下,就能知道:一个字符相同的对数、两个字符相同的对数、三个字符相同的对数。注意,这样算的时候,如aaaa和aaab,这个一个字符相同的对数是算了3遍的,所以要减回去。
至于怎么减回去大概可以用容斥原理,我写的那些其实是我自己YY的,我不会容斥o(╯□╰)o
代码(62MS):
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long LL; LL sum[][ << ];
char s[];
int n, maxl; inline int trans(char c) {
if(isdigit(c)) return c - '';
return c - 'a' + ;
} void init() {
for(int p = ; p < n; ++p) {
scanf("%s", &s[]);
for(int i = ; i <= ; ++i) {
int t = ;
if(i&) t += trans(s[]) * (<<);
if(i&) t += trans(s[]) * (<<);
if(i&) t += trans(s[]) * (<<);
if(i&) t += trans(s[]);
++sum[i][t];
maxl = max(maxl, t);
}
}
} LL ans[], tmp[]; inline int bit_count(int x) {
int ret = ;
while(x > ) ret += (x & ), x >>= ;
return ret;
} void solve() {
for(int i = ; i <= ; ++i) {
int x = bit_count(i);
for(int j = ; j <= maxl; ++j) tmp[x] += sum[i][j] * (sum[i][j] - ) / ;
}
ans[] = tmp[];//1位不同=3位相同
ans[] = tmp[] - * tmp[];
ans[] = tmp[] - * tmp[] + * tmp[];
ans[] = LL(n - ) * n / - ans[] - ans[] - ans[];
cout<<ans[]<<' '<<ans[]<<' '<<ans[]<<' '<<ans[]<<endl;
} int main() {
scanf("%d", &n);
init();
solve();
}
URAL 1932 The Secret of Identifier(容斥)的更多相关文章
- ural 1932 The Secret of Identifier 容斥
主题链接:点击打开链接 stl+容斥 #include <cstdio> #include <cstring> #include <algorithm> #incl ...
- URAL 1932 The Secret of Identifier 题解
http://acm.timus.ru/problem.aspx?space=1&num=1932 B - The Secret of Identifier Time Limit:1000MS ...
- ural 1932 The Secret of Identifier (容斥原理)
标题效果: 计算到n字符串. 精确到只是有一个不同的字符,两个不同的字符.三个不同的字符,四对不同的字符. IDEAS: 枚举状态. dp[i] [j] ...当前串取出 i 状态下的全部字符转化成十 ...
- Tmutarakan Exams URAL - 1091(莫比乌斯函数 || 容斥)
题意: 求1 - s 中 找出k个数 使它们的gcd > 1 求这样的k个数的对数 解析: 从每个素数的倍数中取k个数 求方案数 然后素数组合,容斥一下重的 奇加偶减 莫比乌斯函数的直接套模 ...
- HDU 5514 Frogs 容斥定理
Frogs Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5514 De ...
- hdu 5514 Frogs(容斥)
Frogs Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- hdu 5514 Frogs 容斥思想+gcd 银牌题
Frogs Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- Lucky HDU - 5213 (莫队,容斥)
WLD is always very lucky.His secret is a lucky number . is a fixed odd number. Now he meets a strang ...
- POJ1091跳蚤(容斥 + 唯一分解 + 快速幂)
题意:规定每次跳的单位 a1, a2, a3 …… , an, M,次数可以为b1, b2, b3 …… bn, bn + 1, 正好表示往左,负号表示往右, 求能否调到左边一位,即 a1* b1 ...
随机推荐
- java的异常分类
结构关系 throwable error exception checked异常 runtime异常 checked异常也叫io异常这种异常一般我们会在程序块加入trycatch处理它. runt ...
- Zabbix: Database Monitor Installation
1. Install ODBC MS SQL Connector On Zabbix Server https://support.zabbix.com/browse/ZBX-6839 ...
- Redis-cluster详解
redis集群结构 特点: 1 所有redis节点(包括主和从)彼此互联(两两通信),底层使用内部的二进制传输协议,优化传输速度;(所有功能特点的基础) 2 集群中也有主从,也有高可用的 ...
- iOS之Xcode自动管理证书、打包adhoc和testFlight测试安装
引言:Xcode8 之后引用Automatic manage signing .对于开发者而言,在证书上栽的坑肯定不少. 准备:1.开发者账号是必须的吧. 2. Xcode设置account (不给 ...
- JavaScript 基础(六) 数组方法 闭包
在一个对象中绑定函数,称为这个对象的方法.在JavaScript 中,对象的定义是这样的: var guagua = { name:'瓜瓜', birth:1990 }; 但是,如果我们给瓜瓜绑定一个 ...
- js前台加密,java后端解密
1.前台JS <script type="text/javascript"> $(function() { $(" ...
- php接口数据加密、解密、验证签名【转】
<?php/** * 数据加密,解密,验证签名 * @edit http://www.lai18.com * @date 2015-07-08 **///header('Content-Type ...
- typecho博客组插件:openSug.js百度搜索框下拉提示免费代码
Typecho候选搜索增强插件:安装openSug插件即可获得带有“搜索框提示”功能的搜索框,让Typecho搜索更便捷! 支持百度.谷歌.雅虎.Yandex.360好搜.UC神马.酷狗.优酷.淘 ...
- [转]不让iTunes备份到c盘
很多人现在的C盘都是空间不大的SSD硬盘,ITUNES备份老是占越来越大的空间,不如动手把它改成其它盘好了.下面7个步骤教你转移备份. 1.需要一个小工具:Juction.exe,如果你已经是WIN7 ...
- atlas+mysql部署mysql读写分离
1.atlas 简介 Atlas是由 Qihoo 360公司Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目.它在MySQL官方推出的MySQL-Proxy 0.8.2版本的基 ...