题目大意 现在,给你两个位数为 n 和 m 的两个二进制数a,b,现在,我们要进行如下操作: 计算a&b 答案累加上一个操作的值 bbb右移一位,最后一位直接舍弃 现在,请你算出最终的答案,并输出,答案对998244353取模 输入输出格式: 输入格式: 第一行,两个整数n,m,(1≤n,m≤2×105) 第一行,一个长度为n的二进制数a 第一行,一个长度为m的二进制数b 输出格式: 一行,一个数,表示答案 思路: 因为第一个二进制数不动,第二个在动,所以我们可以通过预处理第一个数来获得答案 因…
E. Binary Numbers AND Sum 题目链接:https://codeforces.com/contest/1066/problem/E 题意: 给出两个用二进制表示的数,然后将第二个二进制不断地往右边移一位,每次答案加上这两个的交集,求最后的答案. 题解: 考虑第二个二进制每一位对答案的贡献就行了,然后对第一个二进制算前缀和就ok了. 代码如下: #include <bits/stdc++.h> using namespace std; typedef long long l…
题意:有两个\(01\)字符串\(a\)和\(b\),每次让\(a\)和\(b\)进行与运算,将值贡献给答案,然后将\(b\)右移一位,直到\(b=0\). 题解:因为\(a\)不变,而\(b\)每次右移一位,所以我们看\(b\)中\(1\)的位置在\(a\)中所对应的位置,从该位置到最低位,所有为\(1\)的位置都要算一次十进制的数贡献给答案,那么为了降低复杂度,很明显,我们使用前缀和,用十进制记录\(a\)中从低位到高位的和,然后再从低位到高位遍历\(b\),累加所有\(1\)位置在\(a\…
You are given two huge binary integer numbers aa and bb of lengths nn and mmrespectively. You will repeat the following process: if b>0b>0, then add to the answer the value a & ba & b and divide bb by 22 rounding down (i.e. remove the last d…
B. Hamming Distance Sum 题目连接: http://www.codeforces.com/contest/608/problem/A Description Genos needs your help. He was asked to solve the following programming problem by Saitama: The length of some string s is denoted |s|. The Hamming distance betw…
sum Accepts: 640 Submissions: 1744 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Problem Description Given a sequence, you're asked whether there exists a consecutive subsequence whose sum is divisible by m. outpu…
链接 [http://codeforces.com/contest/1066/problem/E] 题意 给你长度分别为n,m的二进制串,当b>0时,对a,b,&运算,然后b右移一位,把每次a&b的10进制结果累加对 998244353取余 分析 模拟这个过程,但有个技巧就是对b从高位开始求二进制的前缀和 具体看代码 代码 #include<bits/stdc++.h> using namespace std; #define ll long long const ll…
In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentagonal number, I can only wonder if we have to deal with septagonal numbers in Problem 46. Anyway the problem reads Pentagonal numbers are generated by t…
sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1126    Accepted Submission(s): 494 Problem Description Given a sequence, you're asked whether there exists a consecutive subsequence whose…
LINK 题目大意 给你一个数组,问你数组中的每个数是否可以在数组里面找到一个数和他and起来是0,如果可以就输出这个数,否则就输出-1 思路 首先很显然的是可以考虑找到每个数每一位都取反的数的子集 如果子集中存在一个数就满足,否则就不满足 然后就做一个子集前缀和 for (int i = 0; i < n; i++) { for (int s = 0; s <= up; s++) { if ((s >> i) & 1) dp[s] trans from dp[s ^ (1…
题意 题目链接 给出\(n\)个数,问任意选几个数,它们\(\&\)起来等于\(0\)的方案数 Sol 正解居然是容斥原理Orz,然而本蒟蒻完全想不到.. 考虑每一种方案 答案=任意一种方案 - 至少有\(1\)位为\(1\)的方案 + 至少有两位为\(1\)的方案 - 至少有三位为\(1\)的方案 至少有\(i\)位为\(1\)的方案可以dp算,设\(f[x]\)表示满足\(f[x] = a_i \& x = x\)的\(a_i\)的个数 最终答案$ = (-1)^{bit(i)} f[…
[题目链接] http://codeforces.com/problemset/problem/449/D [题目大意] 给出一些数字,问其选出一些数字作or为0的方案数有多少 [题解] 题目等价于给出一些集合,问其交集为空集的方案数, 我们先求交集为S的方案数,记为dp[S],发现处理起来还是比较麻烦, 我们放缩一下条件,求出交集包含S的方案数,记为dp[S], 我们发现dp[S],是以其为子集的方案的高维前缀和, 我们逆序求高维前缀和即可,之后考虑容斥,求出交集为0的情况, 我们发现这个容斥…
思路: 模拟.实现: #include <iostream> using namespace std; ; ], b[]; ]; int main() { int n, m; while (cin >> n >> m) { ; i >= ; i--) cin >> a[i]; ; i >= ; i--) { cin >> b[i]; sum[i] = sum[i + ] + b[i] - '; } , pw = ; ; i <…
这个题吧 你画一下就知道了 就拿这个例子来讲 4 5100110101 对于b串的话第5位只会经过a串的第4位,b串的第4位会经过a串的第3位和第4位.....b串的第1和第2位会经过a串的每一位 由于是&操作,计算1经过a串每一位所能带来的权值, 对b串进行处理,相加即可 #include <bits/stdc++.h> #define ll long long #define mp make_pair #define x first #define y second using n…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 贪心 日期 题目地址:https://leetcode-cn.com/contest/biweekly-contest-24/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k/ 题目描述 给你数字 k ,请你返回和为 k 的斐波那契数字的最少数目,其中,每个斐波那契…
public class Solution { public static void main(String[] args) { Scanner ip = new Scanner(System.in); ; ; ; ) { System.out.print("Enter input:(-1 to stop): "); input = ip.nextDouble(); ) { sum = sum + input; ++count; } } System.out.println("…
1022. 从根到叶的二进制数之和 1022. Sum of Root To Leaf Binary Numbers 题目描述 Given a binary tree, each node has value 0 or 1. Each root-to-leaf path represents a binary number starting with the most significant bit. For example, if the path is 0 -> 1 -> 1 ->…
Problem Statement There is an integer sequence A of length N. Find the number of the pairs of integers l and r (1≤l≤r≤N) that satisfy the following condition: Al xor Al+1 xor … xor Ar=Al + Al+1 + … + Ar Here, xor denotes the bitwise exclusive OR. Def…
public class StrBinaryTurn { // 将Unicode字符串转换成bool型数组 public boolean[] StrToBool(String input) { boolean[] output = Binstr16ToBool(BinstrToBinstr16(StrToBinstr(input))); return output; } // 将bool型数组转换成Unicode字符串 public String BoolToStr(boolean[] inpu…
题目链接: [PKUSC2018]最大前缀和 设$f[S]$表示二进制状态为$S$的序列,任意前缀和都小于等于$0$的方案数. 设$g[S]$表示二进制状态为$S$的序列是整个序列的最大前缀和的方案数. 设$sum[S]$表示二进制状态为$S$的序列的每个数的和. 那么答案就是$\sum\limits_{S=1}^{2^n-1}sum[S]*g[S]*f[(2^n-1)-S]$. 对于$f[S]$,转移相当于在序列前面加一个数,只有当前集合中数的和小于等于$0$时可以转移. 对于$g[S]$,只…
Design and implement a TwoSum class. It should support the following operations:add and find. add - Add the number to an internal data structure.find - Find if there exists any pair of numbers which sum is equal to the value. For example,add(1); add(…
Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example:Given the below binary tree, 1 / \ 2 3 Return 6. 这道求二叉树的最大路径和是一道蛮有难度的题,难就难在起始位置和结束位置可以为任意位置,我当然是又不会了,于是上网看看大神们的解法,看了很多人的都没太看明白,最后发现了网友Yu's…
Design and implement a TwoSum class. It should support the following operations: add and find. add - Add the number to an internal data structure.find - Find if there exists any pair of numbers which sum is equal to the value. For example, add(1); ad…
原题链接在这里:https://leetcode.com/problems/two-sum-iii-data-structure-design/ 题目: Design and implement a TwoSum class. It should support the following operations: add and find. add - Add the number to an internal data structure.find - Find if there exists…
Given an array which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. Write an algorithm to minimize the largest sum among these m subarrays. Note: Given m satisfies the following cons…
K SUM My Submissions http://www.lintcode.com/en/problem/k-sum/ 题目来自九章算法 13% Accepted Given n distinct positive integers, integer k (k <= n) and a number target. Find k numbers where sum is target. Calculate how many solutions there are? Example Given…
Design and implement a TwoSum class. It should support the following operations: add and find. add - Add the number to an internal data structure.find - Find if there exists any pair of numbers which sum is equal to the value. 这个解法很容易想到,但很容易超时. 基本来说有…
k Sum Given n distinct positive integers, integer k (k <= n) and a number target. Find k numbers where sum is target. Calculate how many solutions there are? Example Given [1,2,3,4], k = 2, target = 5. There are 2 solutions: [1,4] and [2,3]. Return 2…
Two Sum I Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please…
Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that…