链接: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. python列表切片

    Python中符合序列的有序序列都支持切片(slice),例如列表,字符串,元组. 格式:[start:end:step] start:起始索引,从0开始,-1表示结束 end:结束索引 step:步 ...

  2. kvm初体验之二:安装

    Host: CentOS release 6.4 (Final) 1. 开启处理器的虚拟化功能 进入BIOS,使能虚拟化功能: 进入linux, grep -E "vmx|svm" ...

  3. 用python 实现录入学生作业情况的小程序

    写一个录入学生作业情况的一个程序 1.查看学生作业情况 2.录入学生作业情况 3.可以让输入3次,需要为空的情况 homeworks = { ‘张流量’: {‘2018.3.22’:”未交”,’201 ...

  4. Apache-SimpleEmail 简单应用

    比JavaMail使用方法要直接,jar包只需要在JavaMail的基础上添加commons-email-1.4.jar即可. 代码: // QQ邮箱发送邮件 SimpleEmail simpleEm ...

  5. listen and translation exercise 51

    You are supposed to be having fun now. I have to hand in my biology paper tomorrow. Listen, you litt ...

  6. CodeForces - 660F:Bear and Bowling 4(DP+斜率优化)

    Limak is an old brown bear. He often goes bowling with his friends. Today he feels really good and t ...

  7. BZOJ_3935_Rbtree

    https://lydsy.com/JudgeOnline/problem.php?id=3935 分析: 如果知道更改后的状态,那么代价和是否合法都能求出来 对不合法的情况也设一个估价函数. 随机这 ...

  8. BZOJ_3744_Gty的妹子序列

    BZOJ3744: Gty的妹子序列 https://lydsy.com/JudgeOnline/problem.php?id=3744 分析: 预处理出来每一块块首到所有位置的逆序对数. 查询时主席 ...

  9. 洛谷P3252 [JLOI2012]树

    题目描述 在这个问题中,给定一个值S和一棵树.在树的每个节点有一个正整数,问有多少条路径的节点总和达到S.路径中节点的深度必须是升序的.假设节点1是根节点,根的深度是0,它的儿子节点的深度为1.路径不 ...

  10. Ubuntu&nbsp;Navicat&nbsp;for&amp;nbs…

    首先上官网上下载LINUX版本: http://www.navicat.com/download 1. 下载 navicat110_mysql_en.tar.gz 文件 2. 下载后解压tar文件 t ...