位运算 UEST 84 Binary Operations
题意:所有连续的子序列的三种位运算计算后的值的和的期望分别是多少
分析:因为所有连续子序列的组数有n * (n + 1) / 2种,所以要将他们分类降低复杂度,以ai为结尾的分成一组,至于具体的做法,我觉得这篇题解已经写的很详细了,UESTC 1709 Binary Operations
吐槽一下,题解的代码交上去是TLE的,至今不知道为何,我写的是WA,将所有类型改成ll才AC。。。
/************************************************
* Author :Running_Time
* Created Time :2015/10/8 星期四 17:43:10
* File Name :B.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 5e4 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
ll a[N], num[35], s[N]; void add(int x) {
int k = 0;
while (x) {
if (x & 1) num[k]++;
x >>= 1; k++;
}
} int main(void) {
ll T, cas = 0; scanf ("%d", &T);
while (T--) {
ll n; scanf ("%lld", &n);
for (int i=0; i<n; ++i) scanf ("%lld", &a[i]);
memset (num, 0, sizeof (num));
memset (s, 0, sizeof (s));
double ans1 = 0, ans2 = 0, ans3 = 0;
ll tmp;
for (int i=0; i<n; ++i) {
s[i] = a[i];
if (i == 0) add (a[i]);
else {
tmp = a[i];
for (int j=0; j<31; ++j) {
if (tmp & (1 << j)) {}
else num[j] = 0;
s[i] += (num[j] * (1 << j));
}
add (a[i]);
}
ans1 += s[i];
} memset (num, 0, sizeof (num));
for (int i=0; i<n; ++i) {
s[i] = a[i];
if (i == 0) add (a[i]);
else {
tmp = a[i];
for (int j=0; j<31; ++j) {
if (tmp & (1 << j)) num[j] = i;
s[i] += (num[j] * (1 << j));
}
add (a[i]);
}
ans2 += s[i];
} memset (num, 0, sizeof (num));
for (int i=0; i<n; ++i) {
s[i] = a[i];
if (i == 0) add (a[i]);
else {
tmp = a[i];
for (int j=0; j<31; ++j) {
if (tmp & (1 << j)) num[j] = i - num[j];
s[i] += (num[j] * (1 << j));
}
add (a[i]);
}
ans3 += s[i];
}
ll len = n * (n + 1) / 2;
printf ("Case #%lld: %.6lf %.6lf %.6lf\n", ++cas, ans1 / len, ans2 / len, ans3 / len);
} return 0;
}
位运算 UEST 84 Binary Operations的更多相关文章
- uestc 1709 Binary Operations 位运算的灵活运用
Binary Operations Time Limit: 2000 ms Memory Limit: 65535 kB Solved: 56 Tried: 674 Description B ...
- Codeforces 868D Huge Strings - 位运算 - 暴力
You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...
- PHP中的位运算与位移运算(其它语言通用)
/* PHP中的位运算与位移运算 ======================= 二进制Binary:0,1 逢二进1,易于电子信号的传输 原码.反码.补码 二进制最高位是符号位:0为正数,1为负数( ...
- CodeForces 282C(位运算)
C. XOR and OR time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- C语言位运算详解[转]
作者:911 说明:本文参考了http://www2.tsu.edu.cn/www/cjc/online/cyuyan/,算是对其的修正,在此将本文列为原创,实有抄袭之嫌疑.甚是惭愧! 位运算是指按二 ...
- C语言位运算详解
位运算是指按二进制进行的运算.在系统软件中,常常需要处理二进制位的问题.C语言提供了6个位操作运算符.这些运算符只能用于整形操作数,即只能用于带符号或无符号的char.short.int与long类型 ...
- C语言位运算详解(转载)
转载自:http://www.cnblogs.com/911/archive/2008/05/20/1203477.html 位运算是指按二进制进行的运算.在系统软件中,常常需要处理二进制位的问题.C ...
- C 语言 ----位运算
位运算是指按二进制进行的运算.在系统软件中,常常需要处理二进制位的问题.C语言提供了6个位操作 运算符.这些运算符只能用于整型操作数,即只能用于带符号或无符号的char,short,int与long类 ...
- Codeforces 551D GukiZ and Binary Operations(矩阵快速幂)
Problem D. GukiZ and Binary Operations Solution 一位一位考虑,就是求一个二进制序列有连续的1的种类数和没有连续的1的种类数. 没有连续的1的二进制序列的 ...
随机推荐
- Hihocoder #1527 : 快速乘法 DP
时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 在写代码时,我们经常要用到类似 x × a 这样的语句( a 是常数).众所周知,计算机进行乘法运算是非常慢的,所以我们需 ...
- 4408: [Fjoi 2016]神秘数
4408: [Fjoi 2016]神秘数 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 452 Solved: 273 [Submit][Stat ...
- eclipse创建maven web app
1 这个功能是由eclipse的插件maven archetype plugin支持的 2 创建过程 File->New->Maven Project 选择archetype为maven- ...
- 在C++中使用Libmd5计算字符串或文件的MD5值
CppMD5Demo.cpp #include <iostream> #include <fstream> #include <chrono> #include & ...
- 使用Microsoft Office 2007将文档转换为PDF
点击帮助 输入关键词PDF后搜索 点击进入Save or convert to PDF or XPS 点击进入2007 Microsoft Office Add-in: Microsoft Save ...
- YTU 2417: C语言习题 字符串长度
2417: C语言习题 字符串长度 时间限制: 1 Sec 内存限制: 128 MB 提交: 758 解决: 548 题目描述 写一函数,求一个字符串的长度.在main函数中输入字符串,并输出其长 ...
- ExtJS常用代码集合
ExtJS常用代码集合,包括弹出提示框,登陆框,树状结构等等.1. [代码]弹出提示框 <html> <head> <title>Ge ...
- I.MX6 u-boot 2009 lvds hdmi lcd 补丁
/************************************************************************* * I.MX6 u-boot 2009 lvds ...
- BZOJ_3963_[WF2011]MachineWorks_斜率优化+CDQ分治
BZOJ_3963_[WF2011]MachineWorks_斜率优化+CDQ分治 Description 你是任意性复杂机器公司(Arbitrarily Complex Machines, ACM) ...
- Codefroces #404 Div2
A题 分析:把多面体和面数一一对应即可 #include<iostream> #include<map> #include<cstring> #include< ...