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 ...
随机推荐
- linux---Vim命令集
Vim命令集 命令历史 以:和/开头的命令都有历史纪录,能够首先键入:或/然后按上下箭头来选择某个历史命令. 启动vim 在命令行窗体中输入下面命令就可以 vim 直接启动vim vim filena ...
- 江湖急救篇:slave 复制错误
这样的事情是,我们DBA的一个暂时表,导致复制出错 老大给力,江湖救急. 关于该參数.淘宝丁奇写了篇文章还不错:MySQL小误区:关于set global sql_slave_skip_counter ...
- C语言习题 链表建立,插入,删除,输出
Problem B: C语言习题 链表建立,插入,删除,输出 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 222 Solved: 92 [Subm ...
- RH033读书笔记(11)-Lab 12 Configuring the bash Shell
Sequence 1: Configuring the bash Shell Deliverable: A system with new aliases that clear the screen, ...
- 怎样用C#代码管理SharePoint解决方式
怎样用C#代码管理SharePoint解决方式 本文我们将了解怎样用代码管理SharePoint解决方式.我们使用server端对象模型抽取解决方式. SharePoi ...
- 【原版的】Redis事件驱动内核
Redis事件驱动内核 作者:cf (360电商技术组) 概述 Redis实现了自己的事件驱动,与开源事件库libevent.libev一样,都是基于I/O多路复用技术实现的.出于性能和代码精炼双方面 ...
- 解决ASP.NET Web API Json对象循环参考错误
前言 一般我们在开法 ASP.NET Web API 时,如果是使用 Entity Framework 技术来操作数据库的话,当两个 Entity 之间包含导览属性(Navigation Proper ...
- 【转】[Android实例] Handler+ExecutorService(线程池)+MessageQueue模式+缓存模式
android线程池的理解,晚上在家无事 预习了一下android异步加载的例子,也学习到了一个很重要的东东 那就是线程池+缓存 下面看他们的理解. [size=1.8em]Handler+Runn ...
- A == B ?(杭州电2054)
A == B ? Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- 【转】Oracle Outline使用方法及注意事项
概要 Oracle Outline是用来保持SQL运行计划(execution plan)的一个工具. 我们能够通过outline工具防止SQL运行计划在数据库环境变更(如统计信息,部分參数等)而引 ...