主题链接:点击打开链接

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 容斥的更多相关文章

  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 题解

    http://acm.timus.ru/problem.aspx?space=1&num=1932 B - The Secret of Identifier Time Limit:1000MS ...

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

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

  4. Tmutarakan Exams URAL - 1091(莫比乌斯函数 || 容斥)

    题意: 求1 - s 中 找出k个数 使它们的gcd  > 1 求这样的k个数的对数 解析: 从每个素数的倍数中取k个数  求方案数 然后素数组合,容斥一下重的 奇加偶减 莫比乌斯函数的直接套模 ...

  5. HDU 5514 Frogs 容斥定理

    Frogs Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5514 De ...

  6. hdu 5514 Frogs(容斥)

    Frogs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  7. hdu 5514 Frogs 容斥思想+gcd 银牌题

    Frogs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  8. Lucky HDU - 5213 (莫队,容斥)

    WLD is always very lucky.His secret is a lucky number . is a fixed odd number. Now he meets a strang ...

  9. POJ1091跳蚤(容斥 + 唯一分解 + 快速幂)

      题意:规定每次跳的单位 a1, a2, a3 …… , an, M,次数可以为b1, b2, b3 …… bn, bn + 1, 正好表示往左,负号表示往右, 求能否调到左边一位,即 a1* b1 ...

随机推荐

  1. iframe页面控制父页面跳转

    <script> window.onload=function(){   window.location.href="http://www.baidu.com";    ...

  2. redis client protocol 分解

    在官方网站http://redis.io/topics/protocol我们必须redis通信协议做说明. 根据以下某些原因.我想解决redis client protocol: 1.足够了解通信协议 ...

  3. iphone内容开发技术学习

    一.iOS基础 1 开发环境搭建以及IOS组件.框架的概要介绍. 2 mac操作系统与iOS操作系统 3 xcode IDE开发环境的初始 二.C语言基础 1数据类型.表达式与控制流程语句 2数组.函 ...

  4. DevExpress 12.1 换肤 超级简单的方法(2013-11-5版)

    本例子是按照DevExpress 12.1 版本 进行演示.请先准备好DevExpress.BonusSkins.v12.1.dll 和DevExpress.Utils.v12.1.dll 1.首先添 ...

  5. Windows8和Windows Phone应用开发主题编码汇总

    原文:Windows8和Windows Phone应用开发主题编码汇总 在Windows 8和Windows Phone应用开发中经常需要自定义一些Windows Store应用风格主题,下面列举一些 ...

  6. 什么时候PHP经验MySQL存储过程

    1.MySQL存储过程 数据库语言,我们经常使用的操作SQL语句必须首先编译在运行时.然后运行,存储过程(Stored Procedure)它被设置为完成一个特定的功能SQL报表设置.编译存储在数据库 ...

  7. winform正在使用dsoframer迅速&quot;Unable to display the inactive document.Click here to reacitive the document.&quot;

    于winform正在使用dsoframer 1.3加载word档,但在axFramerControl1.Open("NPOI.docx");于axFramerControl1控制显 ...

  8. 性能优化——统计信息——SQLServer自动更新和自动创建统计信息选项

    原文:性能优化--统计信息--SQLServer自动更新和自动创建统计信息选项 原文译自:http://www.mssqltips.com/sqlservertip/2766/sql-server-a ...

  9. HDU 2203 亲串(kmp)

    Problem Description 随着人们年龄的增长更大,更聪明还是越大越愚蠢,这是一个值,相同的问题Eddy也一直在思考,由于他在非常小的时候就知道亲和串怎样推断了,可是发现,如今长大了却不知 ...

  10. mvc验证jquery.unobtrusive-ajax

    Unobtrusive Ajax Ajax (Asynchronous JavaScript and XML 的缩写),如我们所见,这个概念的重点已经不再是XML部分,而是 Asynchronous ...