位运算 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的二进制序列的 ...
随机推荐
- python第三方库系列之十八--python/django test库
django是属于python语音的web框架,要说django測试.也能够先说说python的測试.django能够用python的方式測试,当然,django也基于python封装了一个自己的測试 ...
- subclassdlgitem
subclassdlgitem 该函数用来子类化一个控件. Subclass(子类化)是MFC中最常用的窗体技术之一.子类化完成两个工作:一是把窗体类对象attach到一个windows窗体实体中(即 ...
- java面试题(摘录)
1.抽象,继承,封装,多态 2.基本数据类型的字节数 byte:1.int:4.char:2.long:8.float:4.double:8.boolean:1 和short:2 3.String , ...
- 解析SQL中的包含的列和表
using System; using System.IO; using System.Collections.Generic; namespace SQLProcess { class Progra ...
- css简单的数学运算
calc()是css3的一个新增的属性, .box{border:1px solid #ddd; width:calc(100% - 100px); background:#9AC8EB;} 兼容 ...
- gravity layout_gravity
gravity:控制当前视图的内容/子view layout_gravity:控制视图本身
- js-easyUI格式化时间
formatter : function(value, row) { if(value != null){ var date = new Date(value); var y = date.getFu ...
- 如何使用git 生成patch 和打入patch【转】
本文转载自:http://blog.csdn.net/liuhaomatou/article/details/54410361 平时我们在使用git 管理项目的时候,会遇到这样一种情况,那就是客户使用 ...
- oracle实例的内存(SGA和PGA)调整,优化数据库性能
一.名词解释 (1)SGA:SystemGlobal Area是OracleInstance的基本组成部分,在实例启动时分配;系统全局域SGA主要由三部分构成:共享池.数据缓冲区.日志缓冲区. (2) ...
- iOS 编程之使用Precompile Prefix Header
一:为什么Xcode6没有自动创建Precompile Prefix Header 我们在写项目的时候,大部分宏定义,头文件导入都在Precompile Prefix Header文件里面.在Xcod ...