积少成多
文章平均质量分 81
同学少年
没有什么不可能!
展开
-
[ACM] 常用STL
1. stackstackst;//栈st,用于存放int型数据st.push(3);//将3入栈st.push(2);//将2入栈st.pop();//栈顶2出栈int Top = st.top();//获取栈顶元素,即3int Size = st.size();//求栈中的元素个数bool isEmpty = st.empty(); //栈中元素是否为空,1表示空,0表示非空原创 2016-03-01 19:10:18 · 3396 阅读 · 0 评论 -
判断一个数是否为回文数
一:bool pd(int n)//判断是否是回文数 { int k=0; int temp=n; while(temp) { num[++k]=temp%10; temp/=10; } for(int i=1;i<=k/2;i++) { if(n原创 2014-06-18 21:37:05 · 2003 阅读 · 0 评论 -
[ACM] POJ 2409 Let it Bead (Polya计数)
Let it BeadTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4434 Accepted: 2916Description"Let it Bead" company is located upstairs at 700 Cannery Row原创 2014-07-25 09:55:43 · 3492 阅读 · 1 评论 -
[ACM] POJ 3061 Subsequence (尺取法)
SubsequenceTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 8403 Accepted: 3264DescriptionA sequence of N positive integers (10 < N < 100 000), each of原创 2014-07-24 09:50:35 · 2316 阅读 · 0 评论 -
C++中lower_bound函数和upper_bound函数 以及 sort(参数)
STL中关于二分查找的函数有三个lower_bound 、upper_bound 、binary_search 。这三个函数都运用于有序区间(当然这也是运用二分查找的前提),下面记录一下这两个函数。ForwardIter lower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一个非递减序列[first, l转载 2014-07-24 09:59:04 · 3882 阅读 · 0 评论 -
[ACM] 九度OJ 合唱队形 (最长递增子序列改版)
题目1131:合唱队形 时间限制:1 秒内存限制:32 兆特殊判题:否提交:1680解决:520题目描述: N位同学站成一排,音乐老师要请其中的(N-K)位同学出列,使得剩下的K位同学不交换位置就能排成合唱队形。合唱队形是指这样的一种队形:设K位同学从左到右依次编号为1, 2, …, K,他们的身高分别为T1, T2, …, TK,则他们的身高满原创 2014-04-29 20:59:02 · 1902 阅读 · 0 评论 -
[ACM] n个数分为m部分,要求每部分的和乘起来积最大(区间DP)
A - 爱管闲事春希非常爱管闲事,他每天都会抽空帮助一些同学,由于春希非常死板,出于公平性,春希不会先帮助后来找他的同学。现在有n个同学需要他的帮助,虽然他很想一天之类帮助所有人,但毕竟精力有限,于是他决定分m天来帮助他们。根据事情的重要性,春希帮助不同同学会有不同的快乐值,而春希获得的总的快乐值为每天获得的快乐值的乘积。现在给出n和m,以及帮助完各同学时获得的快乐值,原创 2014-05-27 20:56:21 · 3252 阅读 · 7 评论 -
[ACM] POJ 1845 Sumdiv(求A的B次方的所有因子的和,一大堆数学公式...,可做模板)
解题思路:题意是求A的B次方的所有因子的和。学到了一堆数学公式。。下面知识点和思路转载于:http://blog.csdn.net/lyy289065406/article/details/6648539应用定理主要有三个:要求有较强 数学思维 的题应用定理主要有三个:(1) 整数的唯一分解定理: 任意正整数都有且只有一种方式写出其原创 2014-07-21 16:21:59 · 2794 阅读 · 0 评论 -
[ACM] poj 1258 Agri-Net (最小生成树)
Agri-NetTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 37131 Accepted: 14998DescriptionFarmer John has been elected mayor of his town! One of his cam原创 2014-05-26 15:51:32 · 1964 阅读 · 0 评论 -
[ACM] 最短路算法整理(bellman_ford , SPFA , floyed , dijkstra 思想,步骤及模板)
以杭电2544题目为例最短路Problem Description在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt。但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助他们吗? Input输入包括多组数据。每组数据第一行是两个原创 2014-07-15 16:14:33 · 3175 阅读 · 0 评论 -
[ACM] POJ 2513 Colored Sticks (Trie树,欧拉通路,并查集)
Colored SticksTime Limit: 5000MS Memory Limit: 128000KTotal Submissions: 29736 Accepted: 7843DescriptionYou are given a bunch of wooden sticks. Each endpoint of原创 2014-07-18 16:54:24 · 2682 阅读 · 1 评论 -
[ACM] hdu 2049 不容易系列之(4)——考新郎 (组合+错排)
国庆期间,省城HZ刚刚举行了一场盛大的集体婚礼,为了使婚礼进行的丰富一些,司仪临时想出了有一个有意思的节目,叫做"考新郎",具体的操作是这样的:首先,给每位新娘打扮得几乎一模一样,并盖上大大的红盖头随机坐成一排;然后,让各位新郎寻找自己的新娘.每人只准找一个,并且不允许多人找一个.最后,揭开盖头,如果找错了对象就要当众跪搓衣板...看来做新郎也不是容易的事情...原创 2014-07-30 10:01:04 · 1762 阅读 · 0 评论 -
[ACM] POJ 2947 Widget Factory (高斯消元)
Widget FactoryTime Limit: 7000MS Memory Limit: 65536KTotal Submissions: 4436 Accepted: 1502DescriptionThe widget factory produces several different kinds of widge原创 2014-07-29 19:22:13 · 2348 阅读 · 0 评论 -
[ACM] hdu 3037 Saving Beans (Lucas定理,组合数取模)
Saving BeansProblem DescriptionAlthough winter is far away, squirrels have to work day and night to save beans. They need plenty of food to get through those long cold days. After some tim原创 2014-09-04 20:32:43 · 3263 阅读 · 0 评论 -
[数据结构] 表达式求值(转化为后缀表达式再求值或直接求值)
两种情况:1. 根据输入的算数表达式,如(56-20) /(4+2), 先转化为后缀表达式(逆波兰式)56#20#-4#2#+/ 因为输入的数字有多位数的(56),所以数之间用#隔开,然后根据后缀表达式求值。2.根据输入的算数表达式,直接进行求值。对于情况1:转化为后缀表达式时用到了一个符号栈,把后缀表达式存放到数组postExp中,根据后缀表达式求值时用到了一个运算数栈原创 2016-03-05 17:23:04 · 5061 阅读 · 0 评论 -
[剑指offer] 重建二叉树,根据前中,输出后,根据中后,输出前
参考:《剑指offer》纪念版情况1.:给出树的前序序列和中序序列,输出后序序列情况2 :给出树的后序序列和中序序列,输出前序序列解决方法:根据所给出的两个序列,构造出(重建)二叉树,然后按要求再遍历输出。重建二叉树主要利用了递归的思想,最重要的是找出序列的范围(函数传参),这个要非常仔细,很容易出错。一定要在纸上画出图,然后根据图来确定范围。用到的两个函数:以情况原创 2016-03-04 11:20:30 · 1794 阅读 · 0 评论 -
[BestCoder Round #3] hdu 4909 String (状压,计数)
StringProblem DescriptionYou hava a non-empty string which consists of lowercase English letters and may contain at most one '?'. Let's choose non-empty substring G from S (it can be G = S原创 2014-08-05 16:56:34 · 2022 阅读 · 0 评论 -
[ACM] hdu 3549 Flow Problem (最大流模板题)
Flow ProblemProblem DescriptionNetwork flow is a well-known difficult problem for ACMers. Given a graph, your task is to find out the maximum flow for the weighted directed graph.原创 2014-09-24 17:12:56 · 3034 阅读 · 0 评论 -
[ACM] POJ 2186 Popular Cows (强连通分量,Kosaraju算法知识整理)
首先是一些知识整理:来源于网络:以下转载于:http://blog.sina.com.cn/s/blog_4dff87120100r58c.html Kosaraju算法是求解有向图强连通分量(strong connectedcomponent)的三个著名算法之一,能在线性时间求解出一个图的强分量。什么是强连通分量?在这之前先定义一个强连通性(strong connectivi原创 2014-09-25 16:10:47 · 2725 阅读 · 0 评论 -
ACM中的java使用
ACM中java的使用 import java.io.*;import java.math.*;import java.util.*;import java.text.*;class MyMath { public static double add(double d1, double d2){ // 进行加法运算 BigDec转载 2014-09-03 20:03:34 · 2376 阅读 · 0 评论 -
[ACM] hdu 4418 Time travel (高斯消元求期望)
Time travelProblem DescriptionAgent K is one of the greatest agents in a secret organization called Men in Black. Once he needs to finish a mission by traveling through time with the原创 2014-08-31 11:34:50 · 2610 阅读 · 0 评论 -
[数据结构] KMP字符串匹配
采用了next[0]=-1的形式,字符串开始位置都是从0开始代码:#include #include #include using namespace std;const int maxn=110;int next[maxn];int nextval[maxn];string s1;//主串string s2;//模式串int len1;//主串的长度原创 2014-05-14 19:09:16 · 1682 阅读 · 0 评论 -
[ACM] POJ 3070 Fibonacci (矩阵幂运算)
FibonacciTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 9517 Accepted: 6767DescriptionIn the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = F原创 2014-09-18 09:45:21 · 2264 阅读 · 0 评论 -
[ACM] POJ 2677 Tour (动态规划,双调欧几里得旅行商问题)
TourTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 3585 Accepted: 1597DescriptionJohn Doe, a skilled pilot, enjoys traveling. While on vacation, he r原创 2014-08-07 10:05:18 · 3188 阅读 · 0 评论 -
[ACM] hdu 1251 统计难题 (字典树)
统计难题Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submission(s): 17416 Accepted Submission(s): 7528Problem DescriptionIgnatius最近遇到一个难题,老师原创 2014-07-18 17:19:42 · 1565 阅读 · 0 评论 -
[ACM]hdu 1002 A + B Problem II (复习大数相加)
A + B Problem II Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 13 Accepted Submission(s) : 4Font: Times New Roman | Verdana | Georgia原创 2014-03-10 19:10:10 · 1628 阅读 · 2 评论 -
[ACM] hdu 1228 A+B (字符串处理)
A + BTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11543 Accepted Submission(s): 6699Problem Description 读入两个小于100的正整数A和B,计原创 2014-05-03 11:05:42 · 2254 阅读 · 0 评论 -
[蓝桥杯历届题目] 黄金队列
黄金分割数0.618与美学有重要的关系。舞台上报幕员所站的位置大约就是舞台宽度的0.618处,墙上的画像一般也挂在房间高度的0.618处,甚至股票的波动据说也能找到0.618的影子....黄金分割数是个无理数,也就是无法表示为两个整数的比值。0.618只是它的近似值,其真值可以通过对5开方减去1再除以2来获得,我们取它的一个较精确的近似值:0.618034有趣的是,一些简单的数列中也会包含原创 2014-03-20 14:39:46 · 1699 阅读 · 0 评论 -
[ACM] hdu 1003 Max Sum(最大子段和模型)
Max SumTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 135262 Accepted Submission(s): 31311Problem Description Given a sequen原创 2014-04-30 09:33:13 · 1719 阅读 · 0 评论 -
[练习] dfs输出全排列
代码:#include #include using namespace std;int visit[11],num[11];int n;void dfs(int depth){ if(depth>n)//注意是大于号,不是大于等于,因为在等于的时候num[depth]还没有赋值 { for(int j=1;j<=n;j++)原创 2014-03-17 20:59:47 · 4870 阅读 · 0 评论 -
substr(),strstr()函数用法
#include <iostream>#include <string.h>using namespace std;int main(){ string s="abcdefg"; string s1=s.substr(2,6);//s1为字符串s起始位置为2,长度为6的一段字符串,注意s的位置是从0开始的,即‘a'的位置为0 cout&l...原创 2014-03-18 19:21:41 · 7741 阅读 · 1 评论 -
最长递增子序列
#include using namespace std;//int num[8]={0,0,3,1,2,4,1,5};//原始序列int num[8]={0,1,3,4,2,5,6,7};int d[8];//保存最长递增子序列的元素,第二种方法,复杂度低int dp[8];//第一种方法,复杂度高,dp[i]存储从num[1]到num[i]之间最长递增子序列的长度,num[原创 2014-03-19 20:10:57 · 768 阅读 · 0 评论 -
[练习] 求组合数
C(m,n) 从m个中取出n个,问一共有多少种情况。代码: #include using namespace std;int c(int m,int n){ if(n==0) return 1; if(m<n) return 0; return c(m-1,n)+c(m-1,n-1);}原创 2014-03-18 09:53:26 · 1033 阅读 · 0 评论 -
string.find()函数用法
1.返回字符串s1在s中的位置,如果没有找到,则返回-1#include #include using namespace std;int main(){ string s="what are you dong"; string s1="are"; int position; position=s.find(s1); if(posit原创 2014-03-18 19:51:59 · 34730 阅读 · 3 评论 -
筛选求n以内素数并返回个数
#include using namespace std;const int maxn=10000;int prime[maxn];bool is_prime[maxn+1];int sieve(int n)//返回n以内素数的个数{ int p=0; for(int i=0;i<=n;i++) is_prime[i]=true原创 2014-03-19 20:13:29 · 1014 阅读 · 0 评论 -
优先队列
#include #include #include using namespace std;struct node{ friend bool operator<(node n1,node n2) { return n1.priority<n2.priority; } int priority; int val原创 2014-03-19 20:12:08 · 728 阅读 · 0 评论 -
[ACM] hdu 2602 Bone Collector(01背包)
Bone CollectorTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 25042 Accepted Submission(s): 10147Problem Description Many yea原创 2014-03-20 17:30:14 · 1310 阅读 · 0 评论 -
调用函数判断一个数是否为素数(传统+优化)
#include #include using namespace std;bool prime1(int n) //传统的判断素数。{ if(n==1) return 0; if(n==2) return 1; int t=(int)sqrt(n); for(int i=2;i<=t;i++)原创 2014-03-25 12:47:51 · 2104 阅读 · 0 评论 -
[ACM] hdu 1114 Piggy-Bank(完全背包)
Piggy-BankTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9921 Accepted Submission(s): 4997Problem Description Before ACM can原创 2014-03-20 17:45:50 · 1772 阅读 · 0 评论 -
[ACM]最长回文子串
题目:输入一行字符串,包括标点符号,空格和大小写字母,输出其最长回文串,忽略字母的大小写,空格和符号比如字符串 sabc, , Cba 则输出abc, , Cba代码:#include #include #include using namespace std;const int maxn=5010;string s;char buf[maxn];//存原创 2014-03-04 21:00:15 · 1487 阅读 · 0 评论