位运算 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的二进制序列的 ...
随机推荐
- 文件宝局域网传输/播放功能使用帮助(Windows电脑用户)
使用局域网账户密码登录,可以访问电脑上所有文件 使用游客无账户密码登录,只能访问电脑上指定共享文件夹的文件. 1.怎么设置共享文件夹请参考: 方法1 1.在文件资源管理器中选择自己一个想共享的文件夹, ...
- HDU 6114 Chess 【组合数】(2017"百度之星"程序设计大赛 - 初赛(B))
Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- poj 1724 ROADS 解题报告
题目链接:http://poj.org/problem?id=1724 题目意思:给出一个含有N个点(编号从1~N).R条边的有向图.Bob 有 K 那么多的金钱,需要找一条从顶点1到顶点N的路径(每 ...
- codeforces 451C. Predict Outcome of the Game 解题报告
题目链接:http://codeforces.com/problemset/problem/451/C 题目意思:有3支球队(假设编号为1.2.3),总共要打 n 场比赛,已知已经错过这n场比赛中的 ...
- Java变量和常量声明
一.变量 1.变量的定义 变量是内存中的一个存储区域,该区域有自己的名称(变量名)和类型(数据类型),Java中每个变量必须先声明,后使用 该区域的数据可以在同一类型范围内 ...
- codeforces 505C C. Mr. Kitayuta, the Treasure Hunter(dp)
题目链接: C. Mr. Kitayuta, the Treasure Hunter time limit per test 1 second memory limit per test 256 me ...
- 【Codeforces 757B】 Bash's big day
[题目链接] 点击打开链接 [算法] 若gcd(s1,s2,s3....sk) > 1, 则说明 : 一定存在一个整数d满足d|s1,d|s2,d|s3....,d|sk 因为我们要使|s|尽可 ...
- WIN7开机自动登录设置
WIN7开机自动登录设置 1 执行rundll32 netplwiz.dll,UsersRunDll 开始菜单中找到运行并单击运行:如下图1所示 ...
- HBase之四--(1):Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询
1.搭建环境 新建JAVA项目,添加的包有: 有关Hadoop的hadoop-core-0.20.204.0.jar 有关Hbase的hbase-0.90.4.jar.hbase-0.90.4-tes ...
- web前端安全机制问题全解析
摘要 web前端安全方面技术含有的东西较多,这里就来理一理web安全方面所涉及的一些问题 目录[-] 摘要 web前端安全方面技术含有的东西较多,这里就来理一理web安全方面所涉及的一些问题 web安 ...