ural 1932 The Secret of Identifier 容斥
主题链接:点击打开链接
stl+容斥
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <set>
using namespace std;
#define N 65540
#define ll __int64
ll n;
ll a[N][4], mul[4]={1,16,256,4096};
ll h[N];
vector<ll>G[N];
set<ll>myset;
set<ll>::iterator p;
ll find1(ll x){ //设除了x位。其它3位同样
myset.clear();
for(ll i = 0; i < n; i++){
ll now = 0;
for(ll j = 0; j < 4; j++)if(j!=x)
now += a[i][j];
G[now].push_back(i);
myset.insert(now);
}
ll ans = 0;
for(p = myset.begin(); p!=myset.end(); p++) {
ll siz = G[*p].size();
ans += (siz*(siz-1))>>1;
G[*p].clear();
}
return ans;
} ll find2(ll x,ll y){
myset.clear();
for(ll i = 0; i < n; i++) {
ll now = 0;
for(ll j = 0; j < 4; j++)if(j!=x&&j!=y)
now += a[i][j];
G[now].push_back(i);
myset.insert(now);
}
ll ans = 0;
for(p = myset.begin(); p!=myset.end(); p++) {
ll siz = G[*p].size();
ans += (siz*(siz-1))>>1;
G[*p].clear();
}
return ans;
}
ll find3(ll x){
myset.clear();
for(ll i = 0; i < n; i++){
ll now = 0;
now += a[i][x];
G[now].push_back(i);
myset.insert(now);
}
ll ans = 0;
for(p = myset.begin(); p!=myset.end(); p++) {
ll siz = G[*p].size();
ans += (siz*(siz-1))>>1;
G[*p].clear();
}
return ans;
}
int main(){
ll i,j;
for(ll i = 0; i < N; i++)G[i].clear();
while(cin>>n) {
for(i=0;i<n;i++)
{
char s[10]; scanf("%s",s);
for(j=0;j<4;j++) {
a[i][j] = ('0'<=s[j]&&s[j]<='9')?s[j]-'0':s[j]-'a'+10;
a[i][j] *= mul[j];
}
}
ll ans[5] = {0};
ans[1] = find1(0) + find1(1) + find1(2) + find1(3);
ans[2] = find2(0,1) + find2(0,2) + find2(0,3) + find2(1,2) + find2(1,3) + find2(2,3) - ans[1]*3;
ans[3] = find3(0) + find3(1) + find3(2) + find3(3) - ans[1]*3 - ans[2]*2;
ll all = (ll) ((n*(n-1))/2);
ans[4] = all - ans[1] - ans[2] - ans[3];
cout<<ans[1]<<" "<<ans[2]<<" "<<ans[3]<<" "<<ans[4]<<endl; }
return 0;
}
/*
4
abcd
abca
abce
abcf
10
0000
1111
2222
3333
4444
5555
6666
7777
8888
9999 */
版权声明:本文博主原创文章,博客,未经同意不得转载。
ural 1932 The Secret of Identifier 容斥的更多相关文章
- 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 题解
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 ...
随机推荐
- 给EasyUI的DateBox控件添加清除button
EasyUI中间DateBox控制甚至没有被清除button.例如下面的附图: 真是不可思议,对于要求日期格式必须选择的情况下,不能清空日期,很不方便. 尽管能够通过手工改动EasyU ...
- 说说nio2
利不百不变法,功不十不易器 为什么会出现nio,之前的io有什么问题? 请先看 说说nio1 nio类图例如以下 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZX ...
- Unbound classpath container: 'JRE System Library [jdk17060]' in project ***
项目报告的错误列表 Unbound classpath container: 'JRE System Library [jdk17060]' in project **** 误. 原因是,我升级JDK ...
- WebLogic部署集群和代理服务器
应公司要求,最近在学习weblogic集群这块的知识,下面我把我这几天学到的,以及过程中遇到的问题及如何解决的,分享给大家.首先,weblogic是Orcale公司的一款产品,至于其作用,我想就不用我 ...
- 相关Jquery Validator采用
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs& ...
- 的无线通信网络的学习LTE的关键技术HARQ(20141217)
今天,我们就来一起看一下LTE申请的关键技术HARQ(自己主动混合重传技术) 因为在信道传输过程中的信息,它会产生信息丢失,因此,为了维持的信息的完整性.总是有重发信息,完成所有的迄今收到的资料. 首 ...
- 恶意软件"跨平台" 小心钱包很受伤
什么是跨平台攻击? 举例来说.就像网络诈骗犯为了避开电子商务平台的监控.会在微博上发消息.百度上撒网,腾讯上联系,最后在淘宝上交易.这样的跨平台操作的模式会大大添加犯罪过程监控和取证的难度.而跨平台攻 ...
- MemoryBarrier,Volatile
使用MemoryBarrier,Volatile进行同步 上一节介绍了使用信号量进行同步,本节主要介绍一些非阻塞同步的方法.本节主要介绍MemoryBarrier,volatile,Interlock ...
- H.265/HEVC Codec 编解码 (MP4 和 TS)
1. H.265/HEVC 播放器 1) VLC media player 2.1.3 (眼下不支持H.265 TS播放) 2)ffmpeg中的ffplay (如:ffplay hevc.ts) 3 ...
- 【翻译】Ext JS最新技巧——2014-10-30
原文:Top Support Tips Greg Barry:Ext JS 5的ExtraParams Ext JS 4同意用户直接将extraParams加入到一个链接,相似例如以下代码: Ext. ...