HDU4737A Bit Fun

2024-08-24 04:18
文章标签 hdu4737a bit fun

本文主要是介绍HDU4737A Bit Fun,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目:HDU4737A Bit Fun


题目大意:给出N个数,然后问里面有多少个子串,对于每个子串做或运算的结果小于m。


解题思路:这题测试数据比较水,暴力就可以过。正解:把每个数都用二进制存起来,然后一开始head和tail都指向1.每次tail都++,对于每个tail求出离他最远的head。然后求和一下每个tail满足条件的子串。注意当head到tail的和超过m的时候,就要将head往后移动,这个时候就要将head的数字对应有1的位置--。


代码:

#include <cstdio>
#include <cstring>
#include <algorithm>using namespace std;typedef long long ll;const int maxn = 1e5 + 5;
int n;
int num[maxn], m;
int Num[maxn][35], cnt[35];
int t[35];void init () {t[0] = 1;for (int i = 1; i <= 30; i++)t[i] = t[i - 1] * 2;
}bool judge () {ll Sum = 0;for (int i = 0; i <= 30; i++) if (cnt[i])Sum += t[i];if (Sum < m)return true;return false;
}ll solve () {ll ans = 0;for (int k = 1; k <= n; k++) {for (int i = 30; i >= 0; i--) {if (num[k] >= t[i]) {Num[k][i] = 1;num[k] -= t[i];} elseNum[k][i] = 0;}}int head, tail;head = tail = 1;for (int i = 0; i <= 30; i++)cnt[i] = 0;ll tmp; while (tail <= n) {for (int i = 0; i <= 30; i++)if (Num[tail][i])cnt[i]++;if (!judge()) {	while (head <= tail && !judge()) {//注意head移动的边界for (int i = 0; i <= 30; i++)if (Num[head][i])cnt[i]--;head++;}}ans += tail - head  + 1;tail++;}return ans;
}int main () {int T;scanf ("%d", &T);init();for (int cas = 1; cas <= T; cas++) {printf ("Case #%d: ", cas);scanf ("%d%d", &n, &m);for (int i = 1; i <= n; i++)scanf ("%d", &num[i]);printf ("%I64d\n", solve());}return 0;
}



这篇关于HDU4737A Bit Fun的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1101426

相关文章

[Gym103960B] Fun with Stones

并不是多困难或者有趣的题,写sol仅仅是因为觉得好笑()。 题目大意 三堆石子 Nim 游戏,第 i i i 堆石子数量在 [ l i , r i ] [l_i , r_i] [li​,ri​] 中随机,求先手必胜的概率,对 1 0 9 + 7 10^9+7 109+7 取模。 l i , r i ≤ 1 0 9 l_i , r_i≤10^9 li​,ri​≤109。 题解 说人

[论文笔记]LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale

引言 今天带来第一篇量化论文LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale笔记。 为了简单,下文中以翻译的口吻记录,比如替换"作者"为"我们"。 大语言模型已被广泛采用,但推理时需要大量的GPU内存。我们开发了一种Int8矩阵乘法的过程,用于Transformer中的前馈和注意力投影层,这可以将推理所需

得到验证码fun

{得到验证码} function  TFrmLogin.GetVerfCode():string; var    i,iLen : integer;    sNum : string;    t:TSIzeF; begin   Randomize;   sNum := Format('%.4d', [Random(10000)]);   t.cx :=48;

【论文分享】GPU Memory Exploitation for Fun and Profit 24‘USENIX

目录 AbstractIntroductionResponsible disclosure BackgroundGPU BasicsGPU architectureGPU virtual memory management GPU Programming and ExecutionGPU programming modelGPU kernelDevice function NVIDIA

【HDU】5333 Undirected Graph【LCT+BIT】

传送门:【HDU】5333 Undirected Graph my  code: my~~code: #pragma comment(linker, "/STACK:1024000000")#include <stdio.h>#include <string.h>#include <map>#include <algorithm>using namespace std ;typed

【HDU】5574 Colorful Tree【子树染色,询问子树颜色数——线段树+bit+lca+set】

题目链接:【HDU】5574 Colorful Tree 题目大意:对一个子树染色,询问一个子树的颜色数。 题目分析: set set维护每种颜色所在的 dfs dfs序区间,修改均摊 nlogn nlogn。 #include <bits/stdc++.h>using namespace std ;typedef long long LL ;typedef pair < int , i

Python基础知识:bit(比特)与Byte(字节)的区别与关系

1.bit:位 (小写b) 也称比特 是英文 binary digit的缩写 二进制数系统中,每个0或1就是一个位(bit) 位是数据存储(计算机中信息)的最小单位 计算机中的CPU位数指的是CPU一次能处理的最大位数。例如32位计算机的CPU一次最多能处理32位数据 2.Byte:字节(大写B) 8bit就称为一个字节(Byte), 1Byte=8bit 记为Byte或B,是计算机中信息的

mysql关于bit类型用法

本文来源于:http://www.server110.com/mysql/201403/7117.html Mysql关于bit类型的用法: 官方的资料如下: 9.1.5. 位字段值 可以使用b'value'符号写位字段值。value是一个用0和1写成的二进制值。 位字段符号可以方便指定分配给BIT列的值: mysql> CREATE TABLE t (b BIT

【华为OJ】求最大连续bit数

题目描述 功能: 求一个byte数字对应的二进制数字中1的最大连续数,例如3的二进制为00000011,最大连续2个1 输入: 一个byte型的数字 输出: 无 返回: 对应的二进制数字中1的最大连续数 输入描述: 输入一个byte数字 输出描述: 输出转成二进制之后连续1的个数 输入例子: 3 输出例子: 2 题目分析 方法一:将输入数字转换成二进制,统计连

TensorFlow 2.1.0 + Windows 10 - 64 bit + Python 3.7 安装

先来看看TensorFlow2.1.0安装要求 那就先安装 Python3.7 !!!!!!!!!!!!! 在使用Python时,我们经常需要用到很多第三方库,例如,上面提到的Pillow,以及MySQL驱动程序,Web框架Flask,科学计算Numpy等。用pip一个一个安装费时费力,还需要考虑兼容性。 推荐直接安装 Anaconda,刚好支持Python3.7 下载-安装,一