# bzoj3687: 简单题

bitset很好用的样子？

 1 #include<cstdio>
2 #include<cstdlib>
3 #include<algorithm>
4 #include<iostream>
5 #include<cstring>
6 #include<string>
7
8 using namespace std;
9
10 void setIO(const string& a) {
11     freopen((a + ".in").c_str(), "r", stdin);
12     freopen((a + ".out").c_str(), "w", stdout);
13 }
14
15 #include<bitset>
16 bitset<2000010> a;
17
18 int main() {
19 #ifdef DEBUG
20     freopen("in.txt", "r", stdin);
21     freopen("out.txt", "w", stdout);
22 #endif
23
24     int n, x, res = 0;
25     scanf("%d", &n);
26     a[0] = 1;
27     while(n--) {
28         scanf("%d", &x);
29         a ^= (a << x);
30     }
31     for(int i = 1; i <= 2000000; i++) {
32         if(a[i]) res ^= i;
33     }
34     printf("%d\n", res);
35
36     return 0;
37 }

nlogv做法：

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>

template<typename Q> Q &read(Q &x) {
static char c, f;
for(f = 0; c = getchar(), !isdigit(c); ) if(c == '-') f = 1;
for(x = 0; isdigit(c); c = getchar()) x = x * 10 + c - '0';
if(f) x = -x; return x;
}
static Q x; read(x); return x;
}

typedef long long LL;
const int N = 100000 + 10, mod = 1e9 + 7;

int cnt[40];

int calc() {
int res = 0;
for(int i = 0; i <= 30; i++) {
(res += (LL) cnt[i] * (1 << i) % mod) %= mod;
}
return res;
}

int main() {
#ifdef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif

int n;
int powers = 1;
for(int i = 0; i < n; i++) {
for(int j = 0; j <= 30; j++) {
if(x >> j & 1) (cnt[j] += (powers - cnt[j] + mod) % mod) %= mod;
else (cnt[j] <<= 1) %= mod;
}
(powers <<= 1) %= mod;
}

printf("%d\n", calc());

return 0;
}


sigma(C(a, i)*2n-a)

=sigmaC(a, i) * 2n-a

=2a-1 * 2n-a

=2n-1.(i = 2k + 1)

#include<cstdio>
using namespace std;
void IO(){
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
}
typedef long long ll;
const int N=2e6+5,Mod=10086;
int n;
int orsum;
ll qpow(ll a,int b){
ll c=1;
while(b){
if(b&1) c=c*a%Mod;
if(b>>=1) a=a*a%Mod;
}
return c;
}
void Init(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
int x;
scanf("%d",&x);
orsum |= x;
}
}
ll ans;
int main(){
IO();
Init();
printf("%d\n", orsum * qpow(2, n - 1) % Mod);
return 0;
}


posted @ 2015-11-30 11:39  Showson  阅读(203)  评论(0编辑  收藏  举报