k=k&(k-1)可以消除k的二进制数的最后一个1.连续进行这个操作,每次消除一个1,直到全部消除为止。操作次数就是1的个数。 int num=0; cin>>k; while(k>0) { k=k&(k-1); num++; } cout<<num<<endl; ...
分类:
其他好文 时间:
2020-08-03 09:50:59
阅读次数:
87
1、设置所有用户的vim缩进与行号修改/etc/vimrc配置文件修改所有用户vim配置在/etc/vimrc配置文件末尾增加setnu和setcindent如下图[图片]
分类:
系统相关 时间:
2020-07-31 12:33:59
阅读次数:
81
类型:字符串 思路:前n行用getilne(),或者gets() 读取数据。 剩下的用cin,或者scnaf() 读取数据;当读取到空格时表示一个字符串的结束。 getchar():消去回车符。 AC代码: 1 #include<iostream> 2 #include<cstring> 3 #in ...
分类:
编程语言 时间:
2020-07-29 21:47:49
阅读次数:
86
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6797 题意:给你n个数以及一个特殊数k,你可以将任意两个连续的数合并成一个新的数,同时数组的长度-1,问你进行若干次操作后(可以为0次),最多有多少个数是k的倍数。 思路:遍历数组,定义sum记录其和, ...
分类:
其他好文 时间:
2020-07-29 21:28:55
阅读次数:
87
AcWing 827. 双链表 #include <bits/stdc++.h> using namespace std; const int N=1e6+10; int e[N],l[N],r[N],idx; void init(){ //0表示左端点,1表示右端点 r[0]=1; l[1]=0; ...
AcWing 828. 模拟栈 #include <bits/stdc++.h> using namespace std; const int N=1e6+10; int stk[N],tt; void init(){ tt=0; } void add(int x){ stk[++tt]=x; } ...
AcWing 829. 模拟队列 #include <bits/stdc++.h> using namespace std; const int N=1e6+10; int q[N],hh,tt; void init(){ hh=0; tt=-1; } void add(int x){ q[++tt ...
AcWing 830. 单调栈 #include <bits/stdc++.h> using namespace std; const int N=1e6+10; int n; int stk[N],tt; int main(){ cin.tie(0); ios::sync_with_stdio(f ...
Given a string P consisting of only parentheses and asterisk characters (i.e. "(", ")" and ""), you are asked to replace all the asterisk characters i ...
分类:
其他好文 时间:
2020-07-29 12:38:40
阅读次数:
208
使用ios::sync_with_stdio(false)可以让cin读入的更快,它的原理是使本该同步的输入输出流分开,就是让c风格的输入输出流和c++的输入输出流分开。 举一个具体的例子,在正常c++中,当我们用cin输入整数,当我们在键盘上输入的时候,我们输入的东西进到了缓冲区,假设我们输入了 ...
分类:
移动开发 时间:
2020-07-28 22:41:21
阅读次数:
126