链接:https://ac.nowcoder.com/acm/contest/908/C

题意:

Luffy once saw a particularly delicious food, but he didn't have the money, so he asked Nami for money. But we all know that Nami can't easily give money to Luffy. Therefore, Nami decided to take a test of Luffy. If Luffy was right, Nami would give him money, otherwise Luffy would only be hungry. The problem is as follows: Give you an 32-bit integer n and find the number of 1 in the binary representation of the integer.
You are the most trusted friend of Luffy, and he is now asking for help.

思路:

二进制找1,负数用1<<32 减一下就行。

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
LL n, m, k, t; int main()
{
cin >> t;
while (t--)
{
int sum = 0;
cin >> n;
if (n < 0)
n = (1LL<<32)+n;
while (n)
{
if (n&1)
sum++;
n >>= 1;
}
cout << sum << endl;
} return 0;
}

  

C.One Piece的更多相关文章

  1. Improving the AbiWord's Piece Table

    Improving the AbiWord's Piece Table[转] One of the most critical parts of any word processor is the b ...

  2. A - Piece of Cake Kattis - pieceofcake (数学)

    题目链接: A - Piece of Cake Kattis - pieceofcake 题目大意:给你一个多边形,然后给你这个多边形的每个点的坐标,让你从这个n个点中选出k个点,问这个k个点形成的面 ...

  3. [20171225]RMAN-06808: SECTION SIZE cannot be used when piece limit is in effect.txt

    [20171225]RMAN-06808: SECTION SIZE cannot be used when piece limit is in effect.txt --//朋友拿我的一些例子来测试 ...

  4. TOJ4203: Domino Piece

    4203: Domino Piece  Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByteTotal Submit: 5 ...

  5. SPOJ:One piece(不错的带权括号最大匹配问题)

    One of DB and TN common interests is traveling. One day, they went to Grand Line and found One Piece ...

  6. Want To Become A Web Design Expert? Read This Piece

    Want To Become A Web Design Expert? Read This Piece It can be very expensive to hire a web design fi ...

  7. 重磅来袭 Vue 3.0 One Piece 正式发布

    代号为One Piece 的Vue3.0 在9月19日凌晨正式发布!! 此次vue3.0 为用户提供了全新的 composition-api 以及更小的包大小,和更好的 TypeScript 支持. ...

  8. JELLY技术周刊 Vol.23: Vue3 是伟大航路上的 One Piece 么?

    蒲公英 · JELLY技术周刊 Vol.23 这两天大家应该都被 Vue 发布 3.0 版本的信息刷屏了,背负着很多人的期待, Vue 终于将这个船新版本推到台前,接受大众的检验,那么这个代号为 On ...

  9. RMAN-06172: no AUTOBACKUP found or specified handle is not a valid copy or piece

    问题描述:将备份集从一台主机拷贝到另外一台主机后,在通过RMAN将数据库恢复到同类机异机的时候,restore spfile一直报RMAN-06172: no AUTOBACKUP found or ...

  10. UVALive 5903 Piece it together(二分图匹配)

    给你一个n*m的矩阵,每个点为'B'或'W'或'.'.然后你有一种碎片.碎片可以旋转,问可否用这种碎片精确覆盖矩阵.N,M<=500 WB  <==碎片 W 题目一看,感觉是精确覆盖(最近 ...

随机推荐

  1. MIS系统中的报表测试

    报表功能的基本要求,就是通过查询/统计/分析,提供用户所需的准确的数据.如果无法实现这个基本功能,则报表完全失去意义. 对于用户来说,报表可以直接影响到他们的决策,例如可能因为报表对销售和库存情况反映 ...

  2. not in和not exist的区别(转)

    in和exists in 是把外表和内表作hash 连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询.一直以来认为exists比in效率高的说法是不准确的. 如果查询的两个 ...

  3. 从TS流到PAT和PMT

    转自:https://blog.csdn.net/rongdeguoqian/article/details/18214627 一 从TS流开始 最近开始学习数字电视机顶盒的开发,从MPEG-2到DV ...

  4. C++中的宏和const

    在C语言中使用const来定义一个变量,可以通过变量类型的指针形式来进行修改,而C++中增强了这种表现形式,使得即使通过类型变量指针也不能对变量进行修改. 在C++中const和宏是有区别的. con ...

  5. [acm]HDOJ 2059 龟兔赛跑

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=2059 起点和终点,共n+2个点,n+2个状态,简单DP即可. //11512698 2014-08- ...

  6. kettle结合MySQL生成保留最近6个月月度报告_20161009

    之前计算用户ID各月的金额(各月在列字段),用的是下面代码 ,b.金额,,b.金额,,b.金额,NULL)) AS 9月金额 FROM ( SELECT city AS 城市,DATE_FORMAT( ...

  7. AndyQsmart ACM学习历程——ZOJ3872 Beauty of Array(递推)

    Description Edward has an array A with N integers. He defines the beauty of an array as the summatio ...

  8. 【Lintcode】094.Binary Tree Maximum Path Sum

    题目: Given a binary tree, find the maximum path sum. The path may start and end at any node in the tr ...

  9. HBase键值分片的简单运用

    1.基本原理介绍     HBase的存储是通过行键建立索引进行存储的,而且HBase只支持一级索引,因此只要通过行键才能很快的找到需要的数据.     HBase是一个分布式的系统,HBase通过行 ...

  10. 对于makefile传递参数的一些问题

    makefile变量说明: 1.总控Makefile中使用“-e”参数覆盖下一层Makefile中的变量. 2.父级Makefile向子级Makefile传送变量方式:export <varia ...