acdream 1154 Lowbit Sum】的更多相关文章

先贴代码,以后再写题解... 首先,直接枚举肯定是会超时的,毕竟n就有10^9那么多... 对于每个数,我们先把它转化为二进制:例:21-->10101: 对于00001~10101,可以分为几个部分: 00001~10000: 10001~10100: 10101 因为对于每个数,从最右边的1截断,于是就可以理解为为: 00001~10000:: 001~100: 1: 设s[i]为二进制从右边数第 i+1 个数为1 (且其他数都为0)的lowbit sum: 则 s[i]=s[i-1]*2+…
Lowbit Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description long long ans = 0; for(int i = 1; i <= n; i ++)     ans += lowbit(i) lowbit(i)的意思是将i转化成二进制数之后,仅仅保留最低位的1及其后面的0,截断前面的内容,然后再转成10…
ACdreamOJ 1154 Lowbit Sum (数位dp) ACM 题目地址:pid=1154" target="_blank" style="color:rgb(0,136,204); text-decoration:none">ACdreamOJ 1154 题意: long long ans = 0; for(int i = 1; i <= n; i ++) ans += lowbit(i) lowbit(i)的意思是将i转化成二进制…
先上题目: C - Lowbit Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description long long ans = 0;for(int i = 1; i <= n; i ++)    ans += lowbit(i)lowbit(i)的意思是将i转化成二进制数之后,只保留最低位的1及其后面的0,截断前面的内容,然…
Lowbit Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description long long ans = 0;for(int i = 1; i <= n; i ++)    ans += lowbit(i)lowbit(i)的意思是将i转化成二进制数之后,只保留最低位的1及其后面的0,截断前面的内容,然后再转成10进制数比…
GCD SUM Time Limit: 8000/4000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) SubmitStatisticNext Problem Problem Description 给出N,M执行如下程序:long long  ans = 0,ansx = 0,ansy = 0;for(int i = 1; i <= N; i ++)   for(int j = 1; j <= M; j ++)     …
 Time limit: 1000ms         Memory limits: 256MB Description 2048曾经是一款风靡全球的小游戏.今天,我们换一种方式来玩这个小游戏.现在,你有一个双端队列,你只能把元素从左端或从右端放入双端队列中.一旦放入就不得取出.放入后,若队列中有连续两个相同的元素,它们将自动合并变成一个新的元素——原来那两个元素的和.若新的元素与它相邻的元素相同,则继续合并……如:双端队列中有2, 4, 16三个元素.若将2从左端插入双端队列中,该队列将变成8…
http://www.lydsy.com/JudgeOnline/problem.php?id=2064 Description 背景: 和久必分,分久必和... 题目描述: 中国历史上上分分和和次数非常多..通读中国历史的WJMZBMR表示毫无压力. 同时经常搞OI的他把这个变成了一个数学模型. 假设中国的国土总和是不变的. 每个国家都可以用他的国土面积代替, 又两种可能,一种是两个国家合并为1个,那么新国家的面积为两者之和. 一种是一个国家分裂为2个,那么2个新国家的面积之和为原国家的面积.…
Divide Sum Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) SubmitStatisticNext Problem Problem Description long long ans = 0;for(int i = 1; i <= n; i ++)    for(int j = 1; j <= n; j ++)        ans += a[i] / a[j];给出n,a…
Sum Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) SubmitStatisticNext Problem Problem Description You are given an N*N digit matrix and you can get several horizontal or vertical digit strings from any position. For…
Sum vs Product Time Limit: 4000/2000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) SubmitStatisticNext Problem Problem Description Peter has just learned mathematics. He learned how to add, and how to multiply. The fact that 2 + 2 = 2 × 2…
Sum vs Product Time Limit: 2000/1000MS (Java/Others)    Memory Limit: 128000/64000KB (Java/Others) Submit Status Problem Description Peter has just learned mathematics. He learned how to add, and how to multiply. The fact that 2 + 2 = 2 × 2 has amaze…
先上题目: Sum Time Limit: 6000/3000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description 给出N,a[1]... a[N],还有M,b[1]... b[M]long long ans = 0;for(int i = 1; i <= N; i ++)    for(int j = 1; j <= M; j ++)        ans +=…
先上题目: Power Sum Time Limit: 20000/10000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description 给出n,m,p,求 (1^m + 2^m + 3^m + 4^m + ... + n^m) % p Input 第一行一个数T( <= 10),表示数据总数 然后每行给出3个数n,m,p(1 <= n <= m <= 10…
D. Sum of Medians time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output In one well-known algorithm of finding the k-th order statistics we should divide all elements into groups of five consecu…
传送门 之前看挑战的时候看到一道分桶法的题目,其实我不是很明白分桶法应该怎么写.看到poj后面的讨论版上写着划分树裸题,而我以前就听说过了划分树,就干脆拿来学习一下.在写这篇博客的时候,其实我还是对这个东西不是很明白.在此先mark一下,以便日后再次学习. 划分树是利用模拟快速排序的方法,以树状结构保存信息的数据结构.作用是快速查找区间内第k大的值,我目前学习下来,应该是不能在线操作的.至于划分树怎么写,各位大能菊苣非常多,先贴上一个传送门. 别人的划分树链接 hdu这道题也算是划分树的裸题了吧…
树状数组,与Turing Tree类似. xr[i]表示从1到i的抑或,树状数组维护从1到i每个数只考虑一次的异或,结果为sum(r) ^ sum(l) ^ xr[r] ^ xr[l] 其中xr[r] ^ xr[l] 相当于l + 1到r出现奇数次的数的异或,sum(r) ^ sum(l)表示l + 1到r每个数只考虑一次的异或,则两者异或为出现偶数次的数的异或. #include<cstdio> #include<iostream> #include<cstdlib>…
枚举,每次增加点,删除点 #include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> #include<, INF =  ; ;     ;i-=lowbit(i)){         ret+=C[i];     }     , r = n + ;     ;         ;         }].num; } ; i < n; i++){         …
ACdream 1214---矩阵连乘 Problem Description You might have noticed that there is the new fashion among rich people to have their yards tiled with black and white tiles, forming a pattern. The company Broken Tiles is well known as the best tiling company…
Read Phone Number Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit Status Practice ACdream 1188 Description Do you know how to read the phone numbers in English? Now let me tell you. For example, In China, the phone n…
Alice and Bob Time Limit:3000MS     Memory Limit:128000KB     64bit IO Format:%lld & %llu Submit Status Practice ACdream 1112 Description Here  is Alice and Bob again ! Alice and Bob are playing a game. There are several numbers. First, Alice choose…
题目链接:http://acdream.info/problem?pid=1157 Problem Description 由3钟类型操作:1)D L R(1 <= L <= R <= 1000000000) 增加一条线段[L,R]2)C i (1-base) 删除第i条增加的线段,保证每条插入线段最多插入一次,且这次删除操作一定合法3) Q L R(1 <= L <= R <= 1000000000) 查询目前存在的线段中有多少条线段完全包含[L,R]这个线段,线段X…
题目链接:http://acdream.info/problem?pid=1128 Problem Description wuyiqi陷入了一个迷宫中,这个迷宫是由N*M个格子组成的矩阵.每个格子上堆放了一定数量的箱子.(i,j)表示第i行,第j列的格子.wuyiqi可以将一个格子上的箱子移动到相邻的格子上,或者在这个格子上销毁.也就是在(i,j)的箱子可以移动到(i-1,j).(i+1,j).(i,j-1)和(i,j+1),但是不能移动到矩阵范围外.将(i,j)的格子上的一个箱子移动到相邻格…
原题链接:http://acdream.info/problem?pid=1738 树套树裸题,如下: #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #define lc root<<1 #define rc root<<1|1 using std::sort; using std::l…
大意:给一个数组,先求出SUM[I],然后动态的求出1-I的SUM[I]的和, 这题得化公式: 树状数组维护两个和:SUM(A[I])(1<=I<=X); SUM(A[I]*(N-I+1)) (1<=I<=X); 答案就是:SUM(A[I]*(N-I+1))-SUM[A[I]]*(N-X) (1<=I<=X); #include<stdio.h> #include<string.h> #include<algorithm> #incl…
http://acdream.info/problem?pid=1726 官方题解:http://acdream.info/topic?tid=4246 求n个数里面能不能选一些数出来让它们的和等于k. 因为k很大,不能用背包,但是n很小,最大为40,所以拆成了2部分,之后最大为2^20次方<1050000;每次枚举前一半的和,然后用数组存储,然后得到一个总和减去后一半的差用二分查找. #include<cstdio> #include<cstring> #include&l…
http://acdream.info/problem?pid=1007 两个 long long 相乘会超long long #include <cstdio> #include <cstring> #include <algorithm> #define ll long long #define maxn 10000 #define mod 10000000007 using namespace std; ll a[maxn]; ll n,k,t; ll fMul(…
http://acdream.info/problem?pid=1017 题意:给n个点,m条边,K个货物,要从从S到T,每天每条边最多只能经过1次,求要几天能运完 思路:拆成分层图,每层向下一层连边,注意i也能连到i,流量为inf,代表这个点的货车这天没动 #include<cstdio> #include<iostream> #include<cmath> #include<algorithm> #include<cstring> #defi…
题目链接 #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <complex> #include <cmath> #include <map> #include <set> #include <string> #include &…
称号:acdream 1222 Quantization Problem 题意:给出一个序列 a ,然后给出一个 n * m 的矩阵,让你从这个矩阵中选出一个序列k,使得sum(abs(ki - ai))尽可能的小,首先第一个数仅仅能在矩阵的第一行选第 x 个.然后以后每一个在第 x%n 行选,依次选出最小就可以. 每一个点能够选多次. 分析:这个题目难度在于题意,题意读懂了就简单了. 非常明显的一个dp题目,我们定义状态:dp [i][j] :选第 i 个数 在第 j 列的最小和 则转移方程:…