Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
0ms AC,附代码位压缩,用两个unsigned long long型(共128位)表示一个人听到的树编号,排序,统计互异的元素个数 #include <stdio.h> #include <math.h> unsigned long long a[100] = {0}; unsigned long long b[100] = {0}; void bubble_sort(int n){ for(int i = 0; i < n; i++){ for(int j = n-1; j > i; j--){ if(b[j] < b[j-1] || (b[j] == b[j-1] && a[j] < a[j-1])){ unsigned long long tmp1 = b[j]; b[j] = b[j-1]; b[j-1] = tmp1; unsigned long long tmp2 = a[j]; a[j] = a[j-1]; a[j-1] = tmp2; } } } } int main(){ int p, t; int i, k; //i是人编号,k是树编号 scanf("%d%d", &p, &t); while(scanf("%d%d", &i, &k) != EOF){ if(k <= 50) //因为有重复说的,所以这里只能用|=而不能用+= a[i-1] |= (unsigned long long)pow(2, k-1); else b[i-1] |= (unsigned long long)pow(2, k-50-1); } bubble_sort(p); int cnt = 1; for(int i = 1; i < p; i++) if(a[i] != a[i-1] || b[i] != b[i-1]) cnt++; printf("%d\n", cnt); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator