Let the Balloon Rise. 最近开始刷hdoj,想通过写博客做做笔记,记录写过代码. Problem Description Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest i
传送门 题意:求区间[a, b]中二进制位为1的个数最多的那个数,如果存在多解,则输出最小的那个.(0 <= a <= b) 关键: 对一个数a可以利用 a | (a + 1) 来将a的二进制位中最低的0设置为1 附上代码: #include <stdio.h> typedef long long ll; int main(void) { int n; scanf("%d", &n); ) { ll l, r; scanf("%lld %lld
public class Test2 { public static void main(String args[]){ int num; int count[]=new int[21]; for(int i=0;i<10000;i++){ num=(int)(Math.random()*20+0.5); //产生0到20的随机数 count[num]++; //若产生随机数是0,则用count[0]表示它的个数,数组的初始值都为0 System.out.print(num+" "
More is better Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 327680/102400 K (Java/Others)Total Submission(s): 21167 Accepted Submission(s): 7720 Problem Description Mr Wang wants some boys to help him with a project. Because the project
比如a[]={2,4,5,6,7},得出的两组数{2,4,6}和{5,7},abs(sum(a1)-sum(a2))=0: 比如{2,5,6,10},abs(sum(2,10)-sum(5,6))=1,所以得出的两组数分别为{2,10}和{5,6}. vector<int> vct; int last = INT_MAX; int halfOfSum(int* arr, int len) { int sum = 0; for (int i = 0; i < len; ++i) { sum
题目:Power of Two Given an integer, write a function to determine if it is a power of two. 题意:判断一个数是否是2的k次方数. 思路: 2的次方数使用2进制表示则必然只有最高位是1其他都是0: 这样判断一个数最多需要循环32次就能得出结果. 则程序如下: bool isPowerOfTwo(int n){ if (!n)return false; while ((n&0x01) != 0x01){//2的次方