自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

RonggeRace的专栏

数据结构和算法

  • 博客(94)
  • 收藏
  • 关注

转载 (转载)性能调优--永远超乎想象 (原文最终修订于 2006-08-28 晚上11:48:38)

未经博主同意转载此博客,如此好的博客,后生只是看着心喜,便未经同意转载,希望各位去原博客阅读:http://blog.csdn.net/rmartin/article/details/1132312多年以前,我在开发一个C++的应用程序。我的同伴Jim Newkirk(当时的)过来告诉说,我们的一个公用函数运行得非常的缓慢。这个函数是用来转换二进制的树结构数据为普通文本,并存储到文件中的。

2016-09-30 17:24:22 474

转载 tarjan算法讲解

具体算法介绍 参考 http://www.byvoid.com/blog/scc-tarjan/首先明确几个概念。强连通图。在一个强连通图中,任意两个点都通过一定路径互相连通。比如图一是一个强连通图,而图二不是。因为没有一条路使得点4到达点1、2或3。强连通分量。在一个非强连通图中极大的强连通子图就是该图的强连通分量。比如图三中子图{1,2,3,5}是一个强连通分量,子图{4}是一

2016-09-19 17:04:50 944

原创 UVA 11722

题意:两个人分别在一个时间段内到达这个地方,给你两个区间[a,b]和[c,d] ,他们分别等概率的在区间某个时间到达,先到达的人等w秒后离开,问他们碰面的概率。线性规划的题目AC代码:#include #include #include #include using namespace std;double p_l(int x, int y, int b)

2016-04-11 20:34:43 477

原创 POJ 3744

POJ 3744题意:一条线上有N个雷子,一个人需要经过,p概率往前走一步,1-p概率往前跳2步,从1开始走,问这个人经过的概率,就是不会被任何一个雷子炸到的概率题解:设A=pB=1-p从1开始,走到2的概率为 A走到3的概率为 B+A*A走到4的概率为AB+A*A*A+A*B……因为然后区间太长,需要矩阵快速幂矩阵:A B1 0 

2016-04-11 19:44:51 536

原创 HDU 4283

题解地址:HDU4283 题解AC代码:#include#include#include#includeusing namespace std;const int maxn =105;const int INF =0x4f4f4f4f;int T, kase=0;int n;int a[maxn];int sum[maxn];int dp[maxn][maxn];

2016-04-08 21:09:43 733

原创 POJ 2513 Colored Sticks

POJ 2513 Colored Sticks题意:有一些木棍,两端有颜色,可以两根木棍接起来,拼起来的一端颜色必须相同,问可不可以拼成一个长木棍。这个题的基本思路是,首先将字符串映射到 int 离散化。接下来一个重要的关键是:如果接起来是一根长木棍,中间的接口肯定是两个颜色一样的,这样除了两端,中间的颜色肯定是偶数个。两端如果颜色也一样,就是各种颜色全部为偶数

2016-03-31 22:08:46 492

原创 HDU 5117 Fluorescent

HDU 5117 Fluorescent这个题简单DP可以通过,然而前面需要数学推导一下。题意简单说一下:有n个灯泡,和m个开关,每个开关控制着一些灯的明亮,摁下一个开关,对应这个开关的那些灯泡就会翻转。每个灯有摁下和不摁下供人选择,总共2^m种选择。求所有在2^m种选择下,所有明着的灯三次方总和。定义Xi表示第i盏灯的状态, 亮就是1 ,不亮就是0所以求得解就

2016-03-28 18:47:12 400

原创 POJ 2433 Landscaping

POJ 2433 Landscaping这个题用贪心可以过,当然不排除某些人用了DP过了此题。先说下题意:就是一座山有好多个山峰,最后保留K个山峰,其他的都去掉了,求最少去掉几块泥块。题目给的是每个位置的泥块高度。下面说一下贪心是怎么做的。先把山峰削平,比如* * * ** * * * * * * * ** * * * * * * * * * * *

2016-03-28 17:12:21 624

原创 UVA - 10825

UVA10825 题意很简单了- -。略题解: 枚举最后一位数字,进行判断。判断:计算出每位数,然后进行全排列,挨个进行判断是否可行。附上AC代码:#include#include#include#includeusing namespace std;const int maxn = 400+10;const int maxm = 10;int ans[maxm];i

2016-01-29 18:32:10 497 1

原创 UVA 1025

紫书有详细的思路,题目挺水的,不再赘述#include#include#includeusing namespace std;const int INF = 0x7f7f7f7f;int n, T;int t[55];bool has_train[300][55][2];int m, x;int dp[300][55];int kase=0;int main(){

2015-10-11 15:57:59 524

原创 UVA 1363

AC代码:很简单,紫书说的很明白#include#include#includeusing namespace std;long long n, k;long long p_cal(long long k, long long p){ if(p==0) return n; return min(k/p, n);}int main(){ while

2015-10-07 21:57:22 461

原创 UVA 1632题解

题意: 给你n个物品  他们的位置和消失时间,要在它们消失之前收集起来,每一秒走1个单位长度。题解:DP动态规划,用dp【2】【maxn】【maxn】的转移方程dp【0】【i】【j】表示收集好 从i到j的物品 所需要的最短时间 最后站在最左端dp【1】【i】【j】表示收集好 从i到j的物品 所需要的最短时间 最后站在最右端、这里需要一个理解一个事情,就是路过这个地方的话物品一定

2015-10-06 21:07:07 485

原创 UVA 1629 - Cake slicing 题解

题意:在一块方形蛋糕上有N个樱桃,只能横,竖切割,切割最小长度使得每一块上蛋糕上有且仅有一个樱桃。思路:基础动态规划转移方程:dp[n][m][h][w]=max(dp[n][m][h][t]+dp[n][m+t][h][w-t]+w, dp[n][m][t][w]+dp[n+t][m][h-t][w]+w);n m 表示矩阵大小, t表示从t出切割,造成的最优解。当然切割后的两块 都

2015-09-24 21:28:32 477

原创 UVA 12545 - Bits Equalizer

水题一枚。AC代码:#include#include#include#include#includeusing namespace std;string s, t;int n, kase=0;int main(){ scanf("%d", &n); while(n--){ cin>>s>>t; int last_0=0,

2015-09-10 18:28:09 477

原创 UVA 1610 - Party Games

题意:给你2k个字符串,然后自己构造一个字符串其中一半要求小于等于这个字符串,另一半大于这个字符串,这个字符串尽量短,这个基础上如果有多个解,再求最小的解。直接从前往后扫,要注意Z字符的情况代码比较简洁,这个题坑比较多AC代码:#include#include#include#include#includeusing namespace std;const int m

2015-09-10 17:41:15 418

原创 HDU 1556

题解: 线段树或者是树状数组 线段树我用了两种方法试了试速度,时间差不多, 内存由于是先开的全局内存,也差不多。线段树 两份代码一个最后做了维护,另外一个没有,时间上倒是差不多,维护为了最后方便输出。树状数组有一个思路,就是 修改某个区间【a, b】 的时候, 把a的值加1, b减1, 这样就成了区间求和,易于用树状数组。线段树A代码, 最后做了个维护:#inclu

2015-08-18 11:24:51 401

原创 POJ - 2532 Stars

VJ的题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=14610题意:给你一个笛卡尔坐标系,存在很多点, 问左下方(左边,下面, 左下边都算)有0到N-1个点的 点有多少个。解决方法线段树,或者树状数组。树状数组AC代码:#include#include#include

2015-08-18 09:16:37 466

原创 UVA 208 - Firetruck

水题一个。题意:给你一个图,求点1到某个点的所有路径,路径按照字典序输出。方法:DFS暴搜,这里我用了并查集判断是否连接,减少不必要的运行时间,也可以用bfs检查就是麻烦一点。代码还是一样的清晰。#include#include#include#includeusing namespace std;const int maxn=22;int goal, num=0;b

2015-08-13 20:21:11 372

原创 UVA 11134

voj的链接http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34086方法 贪心或者优先队列贪心的题目, 一开始认为是水题 后来想到了这种情况  ******* *****所以按照x1排列就错了,应该按照x2排列,求最左边的值,因为x2越小的越受限制,水题,不多写了贪心AC代码:#inc

2015-08-06 21:03:56 425

原创 POJ_3624

有上一个01背包的题,这个水题不多写了解释:dp当前重量下选最大的价值AC代码:#include#include#include#include#include#include#include#include#include#include#includeusing namespace std;const int maxn = 3500;const int

2015-08-06 20:32:09 466

原创 HDU 2546

简单背包,题目可以这样解释,除去最贵的物品, 然后花掉尽量多的钱,最后再买掉 最贵的那个这个题的意思就是必须买最贵的那个。分析:假设我们这里有一种最优解没有买最贵的那个,这样在买最后一个之前,我们的钱是>=5的,还是买最贵的那个,解会更优。所以买最贵的那个只会让解更优。剩下的就是在买最贵的之前怎么把钱花的最少,当然要剩下5块钱以上。AC代码:#include#in

2015-08-06 19:53:32 385

原创 HDU 1166

题目要求的数据量比较大,查询比较多,循环扫起来需要时间太长。线段树的作用,查询为log并且插入也为log。一开始数组开小了,导致WA一次,这也是第一次写线段树代码比较简单,AC代码:#include#include#include#includeusing namespace std;int T, n, k;int x, y;struct pp{ int

2015-08-01 09:18:47 338

原创 UVA1592-Database

这个题开得有点晚,只是因为读不懂题,这个题也提供了一个好思路来优化代码。首先,把字符串映射到整形,然后相比整形而不是字符串,大大缩短时间。题意:输出表格中存在的 r1,r2 ,c1,c2使得表格的r1行c1列与r2行c1列相同,r1行c1列与r2行c1列相同。AC源码:#include#include#include#includeusing namespace std;

2015-05-14 17:18:46 1369

原创 山东科技大学第二届ACM校赛解题报告

这次校赛的目的,是为了省赛测试各种程序是否有问题

2015-05-01 17:25:30 3017

原创 UVA129 - Krypton Factor

一个回溯的基本题目,简单易理解// UVA 129#include #include #include using namespace std;const int maxn=500;int n,l;int s[maxn];int cnt;void print(int cur){ for(int i=0; i<cur; i++){ if(i%64=

2015-03-22 23:45:03 488

原创 UVA10622

代码比较简单,唯一分解// UVA 10622#include #include using namespace std;typedef long long ll;#define PMAX 50000int a[PMAX];vector prime;void init(){ for(ll i=2 ; i*i<PMAX; i++){ if(a[i]

2015-03-22 16:17:55 543

原创 UVA10539 - Almost Prime Numbers

#include #include using namespace std;const int maxn=1000000+10;typedef long long ll;typedef unsigned long long llu;int num[maxn]={0};vector prime;void init(){ for(llu i=2; i*i<maxn; i++

2015-03-20 17:42:05 435

原创 uva1210

// UVA1210#include #include typedef long long ll;typedef unsigned long long llu;using namespace std;vector prime;const int maxn=10000+10;void init(){ int num[maxn]={0}; for(int i=2;

2015-03-20 17:01:08 734

原创 UVA 10820

//UVA 10820 other#include const int len = 50001;int phi[len];inline void phi_table(){    int i, j;    for (i = 2; i < len; ++i)        if (!phi[i])            for (j = i; j < l

2015-03-20 15:19:15 367

原创 UVA 1636 - Headshot

设字串00个数为a,0的个数为b, 则两个概率分别是 a/b和 b/n ,为题就是比较他俩大小,左边大就是 SHOOT ,右边大就是 ROTATE#include #include using namespace std;int main(){ string s; while(cin>>s){ int a=0,b=0,n=s.length();

2015-03-19 18:21:29 435

原创 UVA 10791 - Minimum Sum LCM

两种方式,第一种比较复杂,是利用了上一个题写的筛选素数模板#include #include #include #include using namespace std;const int maxn= 46341+10;typedef long long ll;ll a[maxn], pri[maxn],num[maxn];int cnt=0;void get_maxn(

2015-03-19 06:35:54 345

原创 UVA - 10375 Choose and divide

分子分母分别分解成素数的乘积,先约分,后计算#include #include #include using namespace std;const int maxn= 10000+10;int a[maxn], pri[maxn],num[maxn];int cnt=0;void get_maxn(){ for(int i =2,temp;i<maxn;i

2015-03-18 22:35:27 398

原创 杭电1016 同时也是 UVA524

简单的DFS代码 ,读者自己理解吧#include #include #include int pri[40] = {0 ,0 ,1 ,1 ,0 ,1 ,0 ,1 ,0 ,0 ,\0 ,1 ,0 ,1 ,0 ,0 ,0 ,1 ,0 ,1 ,\0 ,0 ,0 ,1 ,0 ,0 ,0 ,0 ,0 ,1 ,\0 ,1 ,0 ,0 ,0 ,0 ,0 ,1 ,0 ,0 };int n

2015-03-17 23:23:02 378

原创 UVA11971 - Polygon

这个题 比较水,读者自己看吧#include using namespace std;typedef unsigned long long llu;llu gcd(llu a,llu b){ return a%b==0? b: gcd(b,a%b);}int main(){ int T,kase=0; cin>>T; while(T--){

2015-03-17 19:15:13 425

原创 UVA11346 - Probability

概率问题,题目不是很难。题意:在给定的【-a,a】 * 【-b,b】内随机取一个点  面积ab > s的概率#include #include int main() { int T; double a, b, s; scanf("%d", &T); while (T--) { scanf("%lf%lf%lf", &a, &b, &s);

2015-03-17 18:53:17 370

原创 UVA10129 - Play on Words

题目类型:欧拉回路题目要求 数据像如网 一样 串成一串 ,只有一个头一个尾除了检查 偶数头和尾 还要检查是否 不是多个串#include #include #include #include using namespace std;string s1="Ordering is possible.\n";string s2="The door cannot be opene

2015-03-13 20:07:34 375

原创 UVA10305 - Ordering Tasks

分类:拓扑排序题意: 题目 输入 前后两个 数字 ,按照 前面的数字在前,后面的数字在后的原则 进行排序#include #include #include using namespace std;const int maxn= 100+10;vector vec[maxn];int have[maxn],out[maxn];int dig=0;void dfs(int

2015-03-13 19:21:43 457

原创 UVA712 - S-Trees

此题 有规律,本来打算 重新建树的,但是后来还是放弃了,用下标法。#include#include#include#define N 1000#define M 10int main(){ int t = 1, n, m; while (scanf("%d", &n), n){ char str[N], tem[M], q[M]; i

2015-03-12 23:28:46 405

原创 UVA1600 - Patrol Robot

一个数组存 0 和1一个数组存 走到  某位置 和 经过某门槛时 的 步数,步数 只能少不能多#include #include using namespace std;int outed=0,best;const int N=25;int a[N][N];int m,n,k;int state[21][21][21];int dir[4][2]={-1,0,1,0,0,

2015-03-12 20:15:32 539

原创 UVA12230 - Crossing Rivers

#include #include #include using namespace std;int main () { int cas = 1; int N; double D, p, l, v; while (scanf("%d%lf", &N, &D) == 2 && (N || D)) { for (int i = 0; i <

2015-03-11 21:22:10 462

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除