随笔分类 -  acm训练

摘要:题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4318题目大意:讲的是西电东送。让你输入N代表N个点,然后再输入M代表可以到M个地方去,每个M钟有一个表示节点,一个表示耗电的百分比,。最后输入三个数,一个是起点,一个是重点,一个是总电量。然后算出最后到达终点使得总电量最大可以是多少,不能到达的话输出IMPOSSIBLE!这道题也就转化成了求最大的转化率。相当于最长路的计算。由于N<=50000数目比较大,所以估计邻接矩阵会超事,然后写了个邻接表的代码:#include <stdio.h>#include <string.h 阅读全文
posted @ 2012-08-15 20:10 某某。 阅读(209) 评论(0) 推荐(0)
摘要:求单源最短路的SPFA算法的全称是:Shortest Path Faster Algorithm。SPFA算法是西南交通大学段凡丁于1994年发表的.很多时候,给定的图存在负权边,这时类似Dijkstra等算法便没有了用武之地,而Bellman-Ford算法的复杂度又过高,SPFA算法便派上用场了。 我们用数组d记录每个结点的最短路径估计值,而且用邻接表来存储图G。我们采取的方法是动态逼近法:设立一个先进先出的队列用来保存待优化的结点,优化时每次取出队首结点u,并且用u点当前的最短路径估计值对离开u点所指向的结点v进行松弛操作,如果v点的最短路径估计值有所调整,且v点不在当前的队列中,就将v点 阅读全文
posted @ 2012-08-15 16:09 某某。 阅读(399) 评论(0) 推荐(0)
摘要:pc代码View Code hdu 1147#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<queue>using namespace std;const int N=1002;const double eps=0.0000000001;//注意设置一个精度struct node{ double ux,uy; double lx,ly; int num; bool tab;};queue<node> ss;double j 阅读全文
posted @ 2012-08-15 16:04 某某。 阅读(244) 评论(0) 推荐(0)
摘要:View Code #include <iostream>#include <stdio.h>using namespace std;typedef struct node{ double x; double y;}point;point p[105];point make_e(point x,point y){ point a; a.x = x.x - y.x; a.y = x.y - y.y; return a;}double cha(point x,point y){ return x.x*y.y - y.x*x.y;}int main(){ ... 阅读全文
posted @ 2012-08-15 15:51 某某。 阅读(192) 评论(0) 推荐(0)
摘要:#include <iostream>#include <stdio.h>using namespace std;typedef struct node{ double x; double y;}point;typedef struct ed{ point a; point b; int is_top;}edge;edge e[100005];point make_e(point x,point y){ point a; a.x = x.x - y.x; a.y = x.y - y.y; return a;}double cha(point... 阅读全文
posted @ 2012-08-15 15:47 某某。 阅读(273) 评论(0) 推荐(0)
摘要:题目大意就是 你有足够多的坦克,让你用尽量多的坦克去占领电厂。有N+1各节点,0~n ,0为出发点,1~n为电厂。要想控制摧毁电厂,战胜对方,只需要占领一般的电量即可。但是特克会耗油,所一给你m条路,让你去计算最小耗电量~而且如果坦克不能通过m条路到达任意一个电厂的话就输出'impossible'连接:http://acm.hdu.edu.cn/showproblem.php?pid=3339代码:dijView Code 1 #include <stdio.h> 2 #include <string.h> 3 #define maxn 0x5fffff 阅读全文
posted @ 2012-08-15 10:56 某某。 阅读(172) 评论(0) 推荐(0)
摘要:连接http://acm.hdu.edu.cn/showproblem.php?pid=2546这道题一开始我想错了以为是贪心。。。当时看到这道题的思路就是首先要-5然后用DP最后用看剩下来谁最大就买谁~后来实在不知道应该怎么处理,终不能用VIS来跟踪标记把= =。。。然后觉得思路错了, 应该是吧最大的那个菜留到最后再买~View Code 1 #include <stdio.h> 2 #include <string.h> 3 /*int cmp(const void *a,const void *b) 4 { 5 return a-b; 6 }*/ 7 int ma 阅读全文
posted @ 2012-08-14 21:55 某某。 阅读(126) 评论(0) 推荐(0)
摘要:地址连接:http://acm.hdu.edu.cn/showproblem.php?pid=2955Roy 去抢N个银行,去抢第j个银行时能得到Mj的钱,被抓的概率为Pj。问在被抓的概率不大于P时能抢到的最多的钱是多少。这道题一开始我以为用P去当背包容量,但是P是double型,所以制定不行= =。。然后没大有思路。。。后来看到网上的思路就是逆向思维,将钱的总数当做背包容量~于是转成以所有银行的总资产为背包容量V。。求最大的逃跑概率。。也就是我们一个都不偷的时候我们逃跑的概率为1,每当我们偷了一个我们都要*(1-p[i])我们成功逃跑的概率状态转移方程:dp[j] = max ( dp[j] 阅读全文
posted @ 2012-08-14 21:51 某某。 阅读(213) 评论(0) 推荐(0)
摘要:题目连接:http://poj.org/problem?id=3211大意就是 一个人洗衣服,然后找他媳妇帮忙。有n种颜色的衣服,和m件衣服,每件衣服的颜色和洗出来的时间都会给出来。再洗的时候两个人不能同时洗一件衣服,但是可以洗两件衣服,但是不同种颜色的衣服不能同时洗~让你求所需要的最少时间。这样我们就可以知道,这道题就是对每一种颜色的衣服所需要的时间进行dP就OK了,对每一种颜色的衣服DP就相当于给你几个正数让你把他分的尽量平均,也就是把和加起来然后除以2作为背包容量~代码:#include <stdio.h>#include <string.h>struct nod 阅读全文
posted @ 2012-08-14 00:10 某某。 阅读(429) 评论(0) 推荐(0)
摘要:题目连接http://poj.org/problem?id=3624View Code 1 #include <stdio.h> 2 #include <string.h> 3 int main() 4 { 5 int n,i,j,w[3500],val[3500],v,f[20000]; 6 while(~scanf("%d %d",&n,&v)) 7 { 8 9 for(i = 1;i <= n;i++)10 {11 scanf("%d %d",&w[i],&val[i]);12 }13 阅读全文
posted @ 2012-08-13 21:57 某某。 阅读(187) 评论(0) 推荐(0)
摘要:题目连接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1500大意:输入几个字符串,然后再输入几个字符串,看第一次输入的字符串有多少没有在后面的字符串中出现(后输入的字符串不一定出现在之前的字符串中)代码:View Code 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 struct node 5 { 6 int flag; 7 struct node *next[2 阅读全文
posted @ 2012-08-13 20:44 某某。 阅读(192) 评论(0) 推荐(0)
摘要:题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1075大意:有外星人来了,但是我不懂外星文。然后我有一本字典,然我去翻译,字典由start开始有end结束的相当于map转换,然后是由由start开始有end结束的需要翻译的句子。代码#include <stdio.h>#include <string.h>#include <stdlib.h>#include <ctype.h>typedef struct node{ int flag; char ans[55]; struct node *next 阅读全文
posted @ 2012-08-13 20:41 某某。 阅读(168) 评论(0) 推荐(0)
摘要:这道题我用得静态树,发现静态树不如动态树啊,虽然时间快点,但是空间要求的也太离谱了~题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1247大意:让你输入几个单词,然后看看这有几个是可以有其他的任意两个单词或者一个单词两次,连接组成的,把他们输出就可以了代码View Code 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 const int N=26; 5 const int maxn=1000000; 6 char s[5000 阅读全文
posted @ 2012-08-13 20:35 某某。 阅读(240) 评论(0) 推荐(0)
摘要:disjkstra 算法View Code #include <iostream>#include <stdio.h>#include <string.h>using namespace std;int map[205][205];void inint(int n){ int i,j; for(i = 0;i < n;i++) for(j = 0;j < n;j++) if(i != j) map[i][j] = 0x5fffffff; else map[i][j] = 0;}//初始化~void Dijkstra(int s,int t,int 阅读全文
posted @ 2012-08-12 20:27 某某。 阅读(179) 评论(0) 推荐(0)
摘要:Building a Space Station题目连接:http://poj.org/problem?id=2031没有什么难点,唯一要注意的是重复路径和相交的情况,但是前一点用克鲁斯基本可以无视~今天涨姿势了~PKU上用G++输出时printf不能用lf得用f以前有个好习惯都用f。。。View Code加一个prim的写法View Code #include <stdio.h>#include <string.h>#include <math.h>#define maxn 1000000struct node{ double x,y,z,r;}degre 阅读全文
posted @ 2012-08-12 15:22 某某。 阅读(181) 评论(0) 推荐(0)
摘要:题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1698大意:先输入一个t代表有t个案例,然后输入个数n代表一共有n个数,值为他们的编号1~n。然后输入q,代表q各更新,再输入a,b,c,代表把a_b的值全部改为c;然后求出所有的和。View Code 1 #include <stdio.h> 2 #define maxn 100007*4 3 struct node 4 { 5 int sum; 6 int lazy; 7 }tr[maxn]; 8 void pushup(int rt) 9 {10 tr[rt].sum... 阅读全文
posted @ 2012-08-12 15:11 某某。 阅读(211) 评论(0) 推荐(0)
摘要:题目连接:http://poj.org/problem?id=3468题目大意:输入N,和Q,代表n个数字和q个操作,然后输入n个数字,然后再输入q个操作,Q代表求询问a,b编号之间的和(包含),C代表把a,b,之间的数都加上c。代码:View Code 1 #include <stdio.h> 2 #include <string.h> 3 #define maxn 100000*4+50 4 struct node 5 { 6 __int64 num; 7 __int64 lazy;//lazy标记 8 }tr[maxn]; 9 __int64 count;10 v 阅读全文
posted @ 2012-08-12 15:06 某某。 阅读(170) 评论(0) 推荐(0)
摘要:链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166代码View Code 1 #include <stdio.h> 2 #include <string.h> 3 #define maxn 50000*4+5 4 struct node { 5 int l,r,val; 6 }tr[maxn]; 7 void pushup(int rt) 8 { 9 tr[rt].val = tr[rt*2].val+tr[rt*2+1].val;10 return;11 }12 void build(int l,int r,int r. 阅读全文
posted @ 2012-08-10 21:53 某某。 阅读(161) 评论(0) 推荐(0)
摘要:链接:http://acm.hdu.edu.cn/showproblem.php?pid=4217题意:就是让你输入一个N代表有1`n几个数,然后输入Q代表几次询问,每次询问输入一个K ,代表吧第K大的数删除。最后计算删除的数的大小~代码#include <stdio.h>#include <string.h>#define maxn 262145*4+5//一般开到最大的四倍大小就无压力~__int64 count,sub;struct node{ __int64 sum,count;}tr[maxn];void pushup(__int64 rt){ tr[rt]. 阅读全文
posted @ 2012-08-10 21:07 某某。 阅读(279) 评论(0) 推荐(0)
摘要:作者:Dong|可以转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址:http://dongxicheng.org/structure/segment-tree/1、概述线段树,也叫区间树,是一个完全二叉树,它在各个节点保存一条线段(即“子数组”),因而常用于解决数列维护问题,它基本能保证每个操作的复杂度为O(lgN)。2、线段树基本操作线段树的基本操作主要包括构造线段树,区间查询和区间修改。(1) 线段树构造首先介绍构造线段树的方法:让根节点表示区间[0,N-1],即所有N个数所组成的一个区间,然后,把区间分成两半,分别由左右子树表示。不难证明,这样的线段树的节点数只有2N 阅读全文
posted @ 2012-08-10 20:06 某某。 阅读(1256) 评论(0) 推荐(0)