您的位置:首页 > 其它

URAL 1932 The Secret of Identifier 题解

2014-06-07 23:04 330 查看
http://acm.timus.ru/problem.aspx?space=1&num=1932

//最终版本,我哭了
#include<cstdio>
#include<cstring>
typedef long long ll;
const ll MAXN=66666;
const ll psn=15;
const ll ps[psn]= {0x000f,0x00f0,0x00ff,0x0f00,0x0f0f,0x0ff0,0x0fff,0xf000,
0xf00f,0xf0f0,0xf0ff,0xff00,0xff0f,0xfff0,0xffff};
const ll pa[psn]= {1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
ll t[MAXN],a[MAXN],ans[5];
ll C(ll a,ll b){
ll re=1;
for(ll i=0;i<b;i++){
re=re*(a-i)/(i+1);
}
return re;
}

int main()
{
int i,j,n;
while(scanf("%d",&n)!=EOF)
{
memset(ans,0,sizeof(ans));
for(i=0; i<n; i++)
scanf("%x",&a[i]);
for(i=0; i<psn; i++)
{
memset(t,0,sizeof(t));
for(j=0; j<n; j++)
t[a[j]&ps[i]]++;
for(j=0; j<=0xffff; j++)
ans[pa[i]]+=t[j]*(t[j]-1)/2;
}
for(i=3; i>0; i--)
for(j=1;j<i;j++)
ans[j]-=C(i,j)*ans[i];
ans[0]=C(n,2)-ans[1]-ans[2]-ans[3];
printf("%I64d %I64d %I64d %I64d\n",ans[3],ans[2],ans[1],ans[0]);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: