ural 1932 The Secret of Identifier 容斥
来源:互联网 发布:黑马餐饮软件 编辑:程序博客网 时间:2024/05/02 03:03
题目链接:点击打开链接
stl+容斥
#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <iostream>#include <set>using namespace std;#define N 65540#define ll __int64ll 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;}/*4abcdabcaabceabcf100000111122223333444455556666777788889999*/
0 0
- ural 1932 The Secret of Identifier 容斥
- ural 1932 The Secret of Identifier (容斥原理)
- URAL 1932 The Secret of Identifier (dp+容斥,4级)
- URAL_1932_The Secret of Identifier(状态压缩+容斥)
- The secret of ROWID
- The Secret of String Formating
- The Singular Secret of the Rockstar Programmer
- The Secret Life Of The Finalizer
- The Singular Secret of the Rockstar Programmer
- The Secret of Strand Hill (Episode 113)
- The Secret of Monkey Island Coming?
- 英语练习112 The secret of longevity
- The Top Secret Of Photoshop Package
- URAL 1747 Kingdom Inspection 容斥原理
- ural 1091. Tmutarakan Exams(容斥)
- Ural 1091 Tmutarakan Exams [容斥原理]
- URAL 1091. Tmutarakan Exams 容斥
- Ural 1091 Tmutarakan Exams【容斥原理】
- 用BAT批量修改文件名方法
- WIN7安装最新版VirtualBox报错“创建 COM 对象失败”解决方法
- 黑马程序员 C语言一些常见的注意6(尾)
- android devlop:adb如何使用 &&& 消除工程导入时的“Invalid project description”错误
- ps 构图 笔记(二)
- ural 1932 The Secret of Identifier 容斥
- 还是学校里好
- POJ 1014 Dividing 背包
- 第一个html程序
- 用Maven部署项目
- c++ Primer(第五版) 课后题答案(七)
- Oracle数据库的导入导出
- 有向图单源最短路径之Bellman-Ford算法
- openfire插件开发