上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 23 下一页
摘要: 题目大意:现有n个点,每个结点有一个权值v,给出关于这些点的m条信息,每条信息(i j k)指出v[i]-v[j]>=k,最后求的是在满足以上约束条件的情况下,v[1]-v[n]的最大值是多少?(N and M not exceeding 30 000 and 150 000 respectively)分析:可以根据题意直接建立差分约束系统,然后以1为源点用spfa求最短路。问题:用队列TLE了,看了discuss后改为stack就A了View Code #include <stdio.h>#include <string.h>#include <stack 阅读全文
posted @ 2012-07-25 20:57 BeatLJ 阅读(226) 评论(0) 推荐(0) 编辑
摘要: 题目大意:给一个字符文本,每行一个字符串,统计不同的字符串出现的百分比。最后按ASCII排序输出不同字符串和出现的百分比。分析:对输入字符串建立字典树,在叶子结点记录该字符串出现的次数。这样的话,最后就可以查找每个字符串出现的次数。另外用一个数组记录不同的字符串,然后对其排序,输出结果。建字典树时要注意,题中没说出现的字符的范围,那就是所有字符都可能出现。数组应开成next[NODE][130].不知道为什么,用C++提交就AC,用G++提交就WA……,确实不太明白这二者有什么区别。View Code #include <stdio.h>#include <stdlib.h& 阅读全文
posted @ 2012-07-25 20:45 BeatLJ 阅读(819) 评论(0) 推荐(0) 编辑
摘要: 题目大意:已知关于在一条直线上的n个点的m条信息,信息分为两类,1、准确信息:P A B X 表示A在B的北方X光年;2、模糊信息:V A B 表示A在B的北方1光年以北。问所给信息是否自相矛盾?比较裸的差分约束系统。将等式转为2个不等式即可建立差分约束系统,另需添加一个源点。使用memset时尽量计算需要清空的大小,否则容易被多组小数据卡到TLE。View Code #include <stdio.h>#include <string.h>#include <queue>using namespace std;#define N 1010#define M 阅读全文
posted @ 2012-07-24 23:27 BeatLJ 阅读(224) 评论(0) 推荐(0) 编辑
摘要: 题目描述有点复杂,前面讲了一大堆废话。题目大意:对一个含n个整数的序列进行一些约束:1、整数序列中连续的一段的和大于某个整数;2、整数序列中连续的一段的和小于某个整数。问满足以上约束的整数序列是否存在。分析:首先利用前缀和进行转换,然后将>化为>=,将<化为<=,然后就基本是裸的差分约束系统了。需要注意的是,建立的约束图可能并不是无向连通的,所以需要另外加一个结点作为源点,由于加了一个点,所以判断是否有负环时要注意,条件是某个点进队次数大于n+1View Code #include <stdio.h>#include <string.h>#inc 阅读全文
posted @ 2012-07-24 17:34 BeatLJ 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 此题是 POJ 1716的加强版。题意:给定n个整数区间,求一整数集合,使得任意区间中至少有ci个数在集合中,求集合中最少包含的元素个数。建立差分约束系统:d[bi+1]-d[ai]>=ci ,0<=d[i+1]-d[i]<=1,d[k]为在区间[0,k-1]中选取的元素个数。View Code #include <stdio.h>#include <string.h>#include <queue>using namespace std;#define N 50010#define M 200010#define MIN(a,b) ((a 阅读全文
posted @ 2012-07-24 17:24 BeatLJ 阅读(208) 评论(0) 推荐(0) 编辑
摘要: DescriptionAn integer interval [a,b], a < b, is a set of all consecutive integers beginning with a and ending with b. Write a program that: finds the minimal number of elements in a set containing at least two different integers from each interval.InputThe first line of the input contains the num 阅读全文
posted @ 2012-07-24 17:18 BeatLJ 阅读(177) 评论(0) 推荐(0) 编辑
摘要: Description靠各种货币之间的的汇率差不断买入,使自己的财富大于现有财 富的行为叫做套汇。当然,能不能成功,那可不一定。现在,某城市有M家银行,该城市一共流通N种货币,所以这M家银行一共提供N种货币的兑换业务。但是每 家银行只提供两种货币间的兑换业务,且这M家银行之间,没有任何两家银行会提供相同的货币种类间的兑换业务。每次到各个银行兑换的时候,都需要一定的手续 费。比方说,我现在有100美金,我打算将他换成人民币,而他们之间的比例是1:6,手续费按用来兑换的币种收取,比方说是0.5美金,那么,最后我得到的人民币有(100-0.5)*6=597元。现在,某人拥有币种为S的钱,他想套汇,当 阅读全文
posted @ 2012-07-24 17:09 BeatLJ 阅读(175) 评论(0) 推荐(0) 编辑
摘要: Description 上次去超市扫荡回来的东西用完了,Staginner又得跑超市一趟,出发前他列了一张购物清单,打算去买K种不同的商品,每种买一件。到了超市,Staginner发现每种商品有N个品牌,每个品牌此商品的价格为Vi,对Staginner的作用值为Wi,他会从这N个品牌里面挑一个品牌买。这时,Staginner突然想起出门时只带了M元钱,又懒得去取钱了,所以不一定能买完K种商品,只好尽可能地让买的东西对自己的总作用值ans最大。Input多组样例。 第一行两个整数K,M代表Staginner想买的不同种类商品的数目和他带的钱 (0 < K <= 30, 0 < 阅读全文
posted @ 2012-07-23 23:41 BeatLJ 阅读(328) 评论(0) 推荐(0) 编辑
摘要: Calf FlacIt is said that if you give an infinite number of cows an infinite number of heavy-duty laptops (with very large keys), that they will ultimately produce all the world's great palindromes. Your job will be to detect these bovine beauties.Ignore punctuation, whitespace, numbers, and case 阅读全文
posted @ 2012-07-23 21:55 BeatLJ 阅读(228) 评论(0) 推荐(0) 编辑
摘要: DescriptionFarmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course.Farmer John ordered a high speed connection for his farm and is going to share his connectivity with the other farmers. T 阅读全文
posted @ 2012-07-23 17:18 BeatLJ 阅读(340) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 23 下一页