- 博客(26)
- 资源 (2)
- 收藏
- 关注
原创 2013吉林邀请
1001 Tutor加起来除以12 保留2位小数 结尾0不要我先扩大100倍 模拟一下进位看四舍五入后有几个0 在输出#include int main(){ int t,i; double sum,x; scanf("%d",&t); while(t--) { int flag1 = 0;
2013-12-31 13:53:41 1711
原创 UVa 10746 Crime Wave – The Sequel / 最小费用最大流
这题卡精度 eps = 1e-6用起来然后主要还是建图 有多个起点(警察 下标1 到 m)多个终点(银行 下标 m+1到n+m) 所以取源点0 建有向边到警察(m次建边)取终点(n+m+1)从银行到n+m+1建有向边(n次) 然后警察到银行建边(n*m次)最后模版#include #include #include using namespace std;const i
2013-12-19 15:24:55 1081
原创 台州学院第五届大学生程序设计竞赛
扔硬币Solve the Equation视频监控MFA AlgorithmCircle VS Triangle电脑密码The Key Locker of Cell PhoneNumber Maze修路问题浪漫自习最大流EK 可以过取一个源点0 建一条边 0-1 容量为m(情侣的对数)如果最大流等于m 就YES此外我建图比较麻烦对于每一条无向
2013-12-19 14:20:28 2163
原创 UVa 10594 Data Flow / 最小费用最大流
和上一题差不多 注意long long会溢出 取一个源点0保证流出的流量是D 如果最大流是D 说明可行#include #include #include using namespace std;const int MAX = 110;const long long fd = 1;const long long INF = fd << 60;int n,m;struct edg
2013-12-19 13:31:38 1015
原创 UVa 10806 Dijkstra, Dijkstra. / 最小费用最大流
题意是从1到n 在回到1 每条边用一次 可以的话输出最短路最小费用最大流 费用是最短路 此外取点0 和 n+1 , 0 - 1 费用0 cap = 2 n-n+1 也是这样 其他每条边用的次数是1最大流等于2 说明可行无向图 第一次学了拆边一条无向边对应2条有向的 每条还有一条相反的 cap = 0 cost = -w的反向边 总共4条 要用邻接表存储邻接矩阵不支持平行边
2013-12-19 10:38:08 1072
原创 UVa 10801 Lift Hopping / floyd
乘电梯 求到目标层的最短时间 有n个电梯 换一个电梯乘需要额外60秒所以建图时每个电梯自己能到的层数先把时间算好 这是不需要60秒的然后做floyd时 如果松弛 肯定是要换电梯 所以要加60秒#include #include #include #include #include #include using namespace std;int a[110]
2013-12-18 20:09:54 964
原创 UVa 563 Crimewave / 最大流EK
这题有很多第一次第一次用了数组表示的邻接表 以前都是用vector第一次学了拆点 参考大神的 最大流建图是重点题意看图 就是所有点要到边界 不能转弯超过一次 不能重叠第一次不懂什么是拆点 看了下这个就懂了 说的蛮好的http://www.cnblogs.com/scau20110726/archive/2012/12/20/2827177.html#include #in
2013-12-18 18:36:21 1299 2
原创 UVa 10985 Rings'n'Ropes floyd+BFS
n个戒指 和m跳长度为1 的绳子求左右收拿住2个戒指 最多几条绳子被拉直拿住哪2个不知道 所以两两枚举对于2个戒指之间 可以考虑最短路 然后可能有很多条最短路 在路径统计下就行看懂样例怎么出来的就知道怎么回事了#include #include #include #include using namespace std;const int MAX = 130;int
2013-12-16 13:42:42 1092
原创 UVa 10158 War / 并查集
我是百度的 嗯 并查集已经忘了 现在复习下#include const int MAX = 20010;int frien[MAX];int find(int x){ if(x != frien[x]) frien[x] = find(frien[x]); return frien[x];}int main(){ int n; int i; int a,b,c;
2013-12-16 10:50:48 947
原创 UVa 658 It's not a Bug, it's a Feature! / SPFA
隐式图的最短路径 题目看了老久要修复所有的漏洞 每个补丁需要一定条件才能打(第一个字符串 第i个字符是+ 说明当前状态一定要有第i个漏洞才能装 - 就是一定没有 o可有可无) 打了可能会导入 或者去掉漏洞(第二个字符串)从1111(n个1)开始做SPFA 终点是00000(n个0)都用2进制表示然后是否能使用补丁需要判断 用位运算处理使用补丁后的状态用一个2进制表示#inclu
2013-12-15 17:12:00 1027
原创 UVa 11045 My T-shirt suits me / 二分图
二分图建图 判断是否是完全匹配就行最大流也行#include #include const int MAX = 300;int a[MAX][MAX];int Match[MAX];bool vis[MAX];char str[7][10] = {"XXL","XL","L","M","S","XS"};int n,m;int get(char *s)
2013-12-13 10:23:16 1223
原创 UVa 10330 Power Transmission / 最大流EK
最大流 这题有很多起点和终点 在取2个点(0和n+1) 作为唯一的起点和终点此外每个点也有容量限制 建图时每条边上的容量为这条边和2个端的容量的最小值 然后EK就行#include #include #include #include using namespace std;const int MAX = 110;int num[MAX];int a[MAX];
2013-12-13 09:44:22 1131
原创 UVa 515 King / 差分约束
第一次碰到这个转换成最短路 建图 存在负环就说明不存在解判断负环 Bellman-Ford 或者SPFA#include struct node{ int s; int e; int w;}a[2010];int n,m;int dis[1010];bool BF(){ int i,j,k; int x,y,z; for(i =
2013-12-11 18:55:57 966
原创 UVa 558 Wormholes / Bellman-Ford
有个人要回到过去看大爆炸 就判断有没有负环 有负环就possibleBellman-Ford 或者SPFA判断负环#include struct node{ int s; int e; int w;}a[2010];int n,m;int dis[1010];bool BF(){ int i,j,k; int x,y,z; for(i
2013-12-11 10:17:09 993
原创 UVa 10986 Sending email / 优先队列优化dijkstra
dijkstra 求最短路 邻接矩阵存不下 换成链表或者vector 用优先队列优化另外据说spfa也可以 有空写一下#include #include #include using namespace std;const int MAX = 20010;struct node{ int end; int dis; bool friend opera
2013-12-11 09:26:40 1230
原创 UVa 128 Software CRC / 进制转换
给你一个字符串 他是一个256进制的数 求一个数加到它末尾使得 % 34943 等于0不能直接把字符串直接转换成10进制 大数因为只要求余数ans rhou mod - ans 就是所求的数一边转 一边除 最后的余数直接在转成16进制#include #include #include #include using namespace std;char a[2
2013-12-10 14:32:41 998
原创 UVa 103 Stacking Boxes / 记忆化搜索
继续练习记忆化搜索求最大的矩形嵌套 在输出记忆化搜索 和滑雪那题差不多#include #include #include using namespace std;int dp[40];int map[40];bool vis[40];int a[40][12];int n,m;void print(int pos){ if(pos !=
2013-12-10 13:33:16 1077
原创 UVa 10617 Again Palindromes / 记忆化搜索
删除若干个字母后 剩下的是回文串 求有多少个记忆化搜索 dp[i][j]表示i j 之间有多少个 其实递推也可以的 long long#include #include long long dp[70][70];char a[70];long long n;long long dfs(long long l,long long r){ if(l > r)
2013-12-08 20:24:28 1068
原创 LA 3971 Assemble / 二分
有n个物品 属性有明智 价格 名字(没用)种类 每种类型选一个 使总价格不超过b 并且最小品质最大 二分品质#include #include #include #include #include #include #include using namespace std;const int MAXN = 1010;int cnt;int n,m;map id;s
2013-12-08 13:55:24 1181
原创 UVa 208 Firetruck / dfs + floyd
给你一个无向图 和一个点 n 按字典序打印所有的从1到n路径 直接深搜 回溯 会TLE 剪个枝 先做一次floyd 如果途经 i点 判断从i 到 n是否可达 不可达就不用搜下去了#include #include #include #include using namespace std;int a[100][100];int b[100][100];int map[100];
2013-12-06 22:48:05 939
原创 UVa 10905 Children's Game / 贪心
给你n个数字 求一个组合 使n个数字按顺序组成的数最大 贪心 排序输出即可#include #include #include #include using namespace std;string a[100];bool cmp(string a,string b){ string s1,s2; s1 = a+b; s2 = b+a; return s1 > s2;
2013-12-06 20:05:21 990
原创 UVa 125 Numbering Paths / floyd
求i到j有多少条路径 回路输出-1 路径floyd处理 成环的话 判断是否 a[i][i]!= 0是的话在做一次floyd 改成-1#include #include #include using namespace std;int a[110][110];int n;void floyd(){ int i,j,k; for(k = 0; k <= n; k++) {
2013-12-06 14:10:17 944
原创 UVa 138 Street Numbers / 佩尔方程
求 一组解 x y使得 1 + 2 + ... + x-1 = x+1 + x+2 +... + y(x不算)可以写成2*x*x = y*y+y的形式 化成佩尔方程求解懒了 搞了个打表#include int main () { printf (" 6 8\n"); printf (" 35 49\n
2013-12-06 14:09:03 1095
原创 UVa 11121 Base -2 / 进制转换
-2 进制 % -2 结果是 -1 0 1感觉这个会了任意负进制都会了http://www.cnblogs.com/scau20110726/archive/2012/12/21/2828420.html 解释的蛮好的#include int n;int main(){ int cas = 1,n,k,t,i; int a[100]; scanf("%d",&t
2013-12-05 20:27:35 990
转载 UVa 10280 Old Wine Into New Bottles / 完全背包
转自http://blog.csdn.net/yan_____/article/details/86711471、这道题如果直接把每个酒瓶的可用容量来做完全背包的话会超时,但是由最低的容量不低于95%,最高的容量不超过99%,由于容量的连续性有一些规律可循,可藉此优化: 考虑任意一种瓶子能够将酒全装满的情况,最小容量min,最大容量max,只要酒的体积x在[min,max]|[2*mi
2013-12-05 18:00:59 918
原创 UVa 10404 Bachet's Game / 完全背包
一堆石头 取完最后一个的胜利 m种取法 完全背包变形 dp[i] = true表示先守取第i个可达 dp[n] = true先手胜 否则输 #include #include #include #include using namespace std;bool dp[1000001];int n,m,a[11];int main(){ int i,j; while(sca
2013-12-05 10:21:59 934
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人