ural 1932 The Secret of Identifier (容斥原理)
标题效果:
计算到n字符串。
精确到只是有一个不同的字符,两个不同的字符。三个不同的字符,四对不同的字符。
IDEAS:
枚举状态。
dp[i] [j] ...当前串取出 i 状态下的全部字符转化成十进制数为 j 的出现的次数。
这种话,就记录了全部串的子串的状态。
然后计数就得到了全部的状态。
然后我们要得到精确不同的,能够用补集的思想,假设要精确到三个不同样,意味着要精确到1 个是同样的。
注意的问题是
在最后要运用容斥去重。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring> using namespace std;
typedef long long ll; char str[6];
ll dp[16][1<<16]; int trans(char ch)
{
if(isdigit(ch))return ch-'0';
return ch-'a'+10;
}
int Count(int x)
{
int ret=0;
while(x){
ret+=(x&1);
x>>=1;
}
return ret;
}
ll tmp[5],ans[5];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int maxm=-1;
memset(dp,0,sizeof dp);
memset(tmp,0,sizeof tmp); for(int i=1;i<=n;i++)
{
scanf("%s",str);
for(int s=1;s<16;s++)
{
int t=0;
if(s&8) t += trans(str[0])*(1<<12);
if(s&4) t += trans(str[1])*(1<<8);
if(s&2) t += trans(str[2])*(1<<4);
if(s&1) t += trans(str[3]);
dp[s][t]++;
maxm=max(t,maxm);
}
}
for(int s=1;s<16;s++)
{
int x=Count(s);
for(int i=0;i<=maxm;i++)
{
tmp[x]+=dp[s][i]*(dp[s][i]-1)/2;
}
} ans[1]=tmp[3];
ans[2]=tmp[2]-3*tmp[3];
ans[3]=tmp[1]-2*tmp[2]+3*tmp[3];
printf("%I64d %I64d %I64d %I64d\n",ans[1],ans[2],ans[3],(ll)n*(n-1)/2-ans[1]-ans[2]-ans[3]);
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
ural 1932 The Secret of Identifier (容斥原理)的更多相关文章
- 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(容斥)
Description Davy Jones: You've been captain of the Black Pearl for 13 years. That was our agreement. ...
- ural 1932 The Secret of Identifier 容斥
主题链接:点击打开链接 stl+容斥 #include <cstdio> #include <cstring> #include <algorithm> #incl ...
- URAL 1707. Hypnotoad's Secret(树阵)
URAL 1707. Hypnotoad's Secret space=1&num=1707" target="_blank" style="" ...
- ural 1707. Hypnotoad's Secret(线段树)
题目链接:ural 1707. Hypnotoad's Secret 题目大意:给定N和M,然后N组s0, t0, Δs, Δt, k,每组能够计算出k个星星的坐标:M组a0, b0, c0, d0, ...
- 容斥原理--计算并集的元素个数 URAL 1091
在计数时,必须注意没有重复,没有遗漏.为了使重叠部分不被重复计算,人们研究出一种新的计数方法,这种方法的基本思想是:先不考虑重叠的情况,把包含于某内容中的所有对象的数目先计算出来,然后再把计数时重复计 ...
- 数学分析 + 容斥原理 - URAL 1907 Coffee and Buns
Coffee and Buns Problem's Link: http://www.bnuoj.com/v3/contest_show.php?cid=6415#problem/H Mean: 给定 ...
- ural 1091. Tmutarakan Exams(容斥原理)
1091. Tmutarakan Exams Time limit: 1.0 secondMemory limit: 64 MB University of New Tmutarakan trains ...
- URAL - 1091 Tmutarakan Exams (简单容斥原理)
题意:K个不同数组成的集合,每个数都不超过S且它们的gcd>1.求这样的数的个数 分析:从2开始枚举gcd,但这样会发生重复.譬如,枚举gcd=2的集合个数和gcd=3的集合个数,枚举6的时候就 ...
随机推荐
- 修改linux系统时间、rtc时间以及时间同步
修改linux的系统时间用date -s [MMDDhhmm[[CC]YY][.ss]] 但是系统重启就会从新和硬件时钟同步. 要想永久修改系统时间,就需要如下命令:hwclock hwclock - ...
- TCP header
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3Vzc2VyNDM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ...
- 讨论JDK的File.equal()
我们一般比较两个文件中的对象是相同的文件,通常使用java.io.File.equal().这里,equal()是不是文件内容的比较结果为.象是否指向同一个文件. File的equal()方法.实际上 ...
- Swift正在使用NSURLConnection异步下载同步(实例解析)
原版的blog.转载请注明出处 http://blog.csdn.net/hello_hwc 一.同步异步两个概念 简单来讲.同步就是函数或者闭包(objective c中的block)运行完成才干返 ...
- HDU-3502-Huson's Adventure Island(BFS+如压力DP)
Problem Description A few days ago, Tom was tired of all the PC-games, so he went back to some old F ...
- 高仿快车100--实战RadioGroup和RadioButton应用
1.RadioButtonCheckBox的差别: a.单个RadioButton在选中后,通过点击无法变为未选中 单个CheckBox在选中后.通过点击能够变为未选中 b.一组RadioButton ...
- 谈论高并发(二十二)解决java.util.concurrent各种组件(四) 深入了解AQS(二)
上一页介绍AQS其基本设计思路以及两个内部类Node和ConditionObject实现 聊聊高并发(二十一)解析java.util.concurrent各个组件(三) 深入理解AQS(一) 这篇说一 ...
- 冒泡排序算法(Java)
冒泡排序即每次遍历.相邻数字间进行比較,前者大于后者进行交换,不断将最大值后移,直至沉至最后位置:算法关键要点在于确定每次循环的边界. 后面两种算法则是对冒泡排序一定程度上的改良,但相对于其它排 ...
- java中间==、equals和hashCode差额
java于==.equals().hashCode()和比较两个对象. 关于== ==是easy理解的.java设计java就是要比較两个对象是不是同一个对象. 对于引用变量而言.比較的时候两个引用变 ...
- NOI 评价体系 arbiter 安装方法 常见的问题 移植
#!/bin/bash AppPath="$PWD" 读取当前文件夹 echo "Arbiter is installing..." sudo apt-ge ...