C.One Piece
链接: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的更多相关文章
- 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 ...
- A - Piece of Cake Kattis - pieceofcake (数学)
题目链接: A - Piece of Cake Kattis - pieceofcake 题目大意:给你一个多边形,然后给你这个多边形的每个点的坐标,让你从这个n个点中选出k个点,问这个k个点形成的面 ...
- [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 --//朋友拿我的一些例子来测试 ...
- TOJ4203: Domino Piece
4203: Domino Piece Time Limit(Common/Java):1000MS/3000MS Memory Limit:65536KByteTotal Submit: 5 ...
- SPOJ:One piece(不错的带权括号最大匹配问题)
One of DB and TN common interests is traveling. One day, they went to Grand Line and found One Piece ...
- 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 ...
- 重磅来袭 Vue 3.0 One Piece 正式发布
代号为One Piece 的Vue3.0 在9月19日凌晨正式发布!! 此次vue3.0 为用户提供了全新的 composition-api 以及更小的包大小,和更好的 TypeScript 支持. ...
- JELLY技术周刊 Vol.23: Vue3 是伟大航路上的 One Piece 么?
蒲公英 · JELLY技术周刊 Vol.23 这两天大家应该都被 Vue 发布 3.0 版本的信息刷屏了,背负着很多人的期待, Vue 终于将这个船新版本推到台前,接受大众的检验,那么这个代号为 On ...
- RMAN-06172: no AUTOBACKUP found or specified handle is not a valid copy or piece
问题描述:将备份集从一台主机拷贝到另外一台主机后,在通过RMAN将数据库恢复到同类机异机的时候,restore spfile一直报RMAN-06172: no AUTOBACKUP found or ...
- UVALive 5903 Piece it together(二分图匹配)
给你一个n*m的矩阵,每个点为'B'或'W'或'.'.然后你有一种碎片.碎片可以旋转,问可否用这种碎片精确覆盖矩阵.N,M<=500 WB <==碎片 W 题目一看,感觉是精确覆盖(最近 ...
随机推荐
- BZOJ 3016 [Usaco2012 Nov]Clumsy Cows:贪心
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3016 题意: 给你一个括号序列,问你至少修改多少个括号,才能使这个括号序列合法. 题解: ...
- linux应用之yum命令
yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能够从指定的服务器自动下载RP ...
- SpringMVC框架<mvc:default-servlet-handler/>的作用
1.创建一个新工程 Eclipse下新建一个web项目,File>New>Dynamic Web Project 2.添加Jar包 3.配置Web.xml 4.配置 ...
- 【Lintcode】077.Longest Common Subsequence
题目: Given two strings, find the longest common subsequence (LCS). Your code should return the length ...
- Jquery通过ajax请求NodeJS返回json数据
最近看了NodeJS相关的,在网上查了下结合AJAX的应用,感觉应用前景还是不错的.为什么用这个组合呢? 1.NodeJS不需要安装,拷贝过去就可以使用,而环境变量可以只配置在当前cmd窗口,运行方便 ...
- BZOJ3648:寝室管理
浅谈树分治:https://www.cnblogs.com/AKMer/p/10014803.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem. ...
- wpf datagrid row的命中测试
1. 添加鼠标左键处理 AddHandler(DataGrid.MouseLeftButtonDownEvent, new RoutedEventHandler(grdStudyList_MouseL ...
- UML统一建模语UML2和EnterpriseArchitect
其实前面的UML统一建模语言(一)所描述的都是UML1的内容,现在咱们聊一聊UML2. UML2.x完全建立在UML1.x基础之上,大多数的UML1.x模型在UML2.x中都可用.但UML2.x在结构 ...
- Vijos:P1117数的划分
描述 将整数n分成k份,且每份不能为空,任意两份不能相同(不考虑顺序). 例如:n=7,k=3,下面三种分法被认为是相同的. 1,1,5; 1,5,1; 5,1,1;问有多少种不同的分法. 格式 输入 ...
- python3+selenium使用浏览器IE的时候,无法打开IE浏览器,老是报错: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones
python3+selenium使用浏览器IE的时候,老是报错: Unexpected error launching Internet Explorer. Protected Mode settin ...