摘要: hdu-1896 问题描述:路上有一些石头(位置,所抛出的距离),如果遇到的是奇数块石头,则向前抛,偶数块石头就让它放在原地不管。如果遇到位置相同的两块石头,就假设抛出距离近的石头先遇到。 思路:遇到奇数块石头,(位置=位置+距离,距离)入栈,偶数则不管,直至栈空为止 #include <cstdi 阅读全文
posted @ 2017-11-16 20:44 unknownname 阅读(167) 评论(0) 推荐(0) 编辑
摘要: reverse函数的作用是:反转一个容器内元素的顺序。函数参数:reverse(first,last);//first为容器的首迭代器,last为容器的末迭代器。它没有任何返回值。 这个函数比较简单,看一个例题:输入一个字符串,输出反转后的字符串。 直接调用函数。 代码: #include <ios 阅读全文
posted @ 2017-11-06 20:15 unknownname 阅读(288) 评论(0) 推荐(0) 编辑
摘要: 本文主要介绍解决动态连通性一类问题的一种算法,使用到了一种叫做并查集的数据结构,称为Union-Find。 更多的信息可以参考Algorithms 一书的Section 1.5,实际上本文也就是基于它的一篇读后感吧。 原文中更多的是给出一些结论,我尝试给出一些思路上的过程,即为什么要使用这个方法,而 阅读全文
posted @ 2017-11-06 13:35 unknownname 阅读(243) 评论(0) 推荐(0) 编辑
摘要: /* O(E*logV) */ #include"cstdio"#include"queue"#include"algorithm"#define INF 1<<28#define MAX 300using namespace std;int v,e,s;int graph[MAX][MAX];// 阅读全文
posted @ 2017-11-06 13:31 unknownname 阅读(375) 评论(0) 推荐(0) 编辑
摘要: /* num = q.top(); 其余同队列 定义: //priority_queue<int,vector<int>,less<int> > pque;//less<int> greater<int>后面不加括号 priority_queue<int,vector<int>,cmp> pque; 阅读全文
posted @ 2017-11-06 13:25 unknownname 阅读(76) 评论(0) 推荐(0) 编辑
摘要: /*num = q.front() 取队顶元素 q.pop() 出队 q.push(num) 入队 q.empty() 判空 size = q.size() 大小 */ #include<iostream>#include<cstdio>#include<queue>using namespace 阅读全文
posted @ 2017-11-06 13:22 unknownname 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 栈: /*num = s.top() 取栈顶元素 s.pop() 出栈 s.push(num) 入栈 s.empty() 判空 size = s.size() 大小 */ #include<iostream>#include<cstdio>#include<stack>using namespace 阅读全文
posted @ 2017-11-06 13:20 unknownname 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 重写排序方法 #include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<iostream>using namespace std; const int N=1e6+5;const int INF=0x7f 阅读全文
posted @ 2017-11-06 13:11 unknownname 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 方法1: #include<cstring>#include<cstdio>using namespace std; struct Ball{ char color[20]; int num;}ball[1005]; int cnt=1; void count_num(char ch[]){ int 阅读全文
posted @ 2017-11-06 13:09 unknownname 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 对应于每一个输入,请输出相应层数的杨辉三角,每一层的整数之间用一个空格隔开,每一个杨辉三角后面加一个空行。 #inlude <stdio.h>#define N 100int main(){ int n,i,j,a[N][N]; a[0][0]=1; a[1][0]=1; a[1][1]=1; fo 阅读全文
posted @ 2017-11-06 12:59 unknownname 阅读(145) 评论(0) 推荐(0) 编辑