随笔分类 - Algorithm
摘要:输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。 分析一下代码: 这段小小的代码,很是巧妙。 如果一个整数不为0,那么这个整数至少有一位是1。如果我们把这个整数减1,那么原来处在整数最右边的1就会变为0,原来在1后面的所有的0都会变成1(如果最右边的1后面还有0的话)。其余所有位将不
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; struct node{ int pos; double t; bool operator()(node a,node b){ return a.t >= b.t; //最小值优先 } }; int main(){ priority_queue< node,vector<node>,node> pq; int
阅读全文
摘要:理解母函数:https://blog.csdn.net/howardemily/article/details/75041523 题目:http://acm.hdu.edu.cn/showproblem.php?pid=2152 Fruit Time Limit: 1000/1000 MS (Jav
阅读全文
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=5616 Jam's balance Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total
阅读全文
摘要:题目:http://poj.org/problem?id=1837 Balance Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16411 Accepted: 10310 Description Gigel has a str
阅读全文
摘要:一、什么是最长公共子序列 例:设有两个字符串str1="nyiihaoo" , str2="niyeyiyang",那么"nyiihaoo"中的子序列:"ny" 长度是2; "niyeyiyang"中的子序列:"ny"长度也为2,这是str1与str2的一个公共子序列,长度为2。那么这两个字符串最长
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3308
阅读全文
摘要:线段树 区间合并模板 --区间更新 题目:http://poj.org/problem?id=3667
阅读全文
摘要:void multi(int a[],int b[],int c[],int an,int bn,int &cn){ //a[]被乘数 b[]乘数 c[] 保存结果 //an表示a数组中所存大数的位数,bn表示b数组中所存大数的位数,cn存c数组的位数 for(int i=maxn-1;i>=maxn-bn;i--){ //乘数 int weight=...
阅读全文
摘要:#include #include #define maxn 1000001 int c[maxn]; int a[maxn]; int lowbit(int x){ return x&(-x); } int ini(){ //初始化 for(int i=1;i=i-lowbit(i);k++){ c[i]+=a[k]; } } } void update(int p...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1394 方法一: 线段树
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1698 模板!
阅读全文
摘要:http://poj.org/problem?id=2484 A Funny Game Description Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <=
阅读全文
摘要:今盒子里有n个小球,A、B两人轮流从盒中取球,每个人都可以看到另一个人取了多少个,也可以看到盒中还剩下多少个,并且两人都很聪明,不会做出错误的判断。 我们约定: 每个人从盒子中取出的球的数目必须是:1,3,7或者8个。 轮到某一方取球时不能弃权! A先取球,然后双方交替取球,直到取完。 被迫拿到最后
阅读全文
摘要:1 #include 2 #include 3 #define max 1000000 4 using namespace std; 5 const int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}}; 6 string origion; 7 string goal; 8 string state[max]; 9 int vis[370000];...
阅读全文
摘要:#include using namespace std; int store[100]; int n; void subset(int cur,int s,int cnt){ //cnt表示子集元素的个数 if(cur==cnt){ for(int i=0;i>n){ for(int i=1;i<=n;i++){ //i代表子集元素...
阅读全文

浙公网安备 33010602011771号