2013年11月27日

USACO SEC.1.3 No.3 Calf Flac

摘要: 题意:给出一篇文章,求略去其中的空格等各种字符(剩余大小写字母后)文中的最长回文子串,输出长度并打印原文中对应的字符串核心:枚举回文串枚举回文串的中点下标是一个比较好的方法,如果反复枚举回文起始点复杂度太大 枚举中点分为两种情况(长度为奇数和偶数),分别处理即可 本题目输入的方式略麻烦/*ID: lsswxr1PROG: calfflacLANG: C++*/#include #include #include #include #include #include #include #include #include #include #include #include #include #i 阅读全文

posted @ 2013-11-27 15:52 小书包_Ray 阅读(217) 评论(0) 推荐(0) 编辑

2013年11月26日

USACO SEC.1.3 No.2 Barn Repair

摘要: 题意:约翰的牛棚损坏了需要修补,每个牛棚的宽度是一样的,一共有S个牛棚,供应商能够提供任意长度的木板(一个单位木板覆盖一个牛棚),但总共最多有M个木板,现在牛棚里面还有C头牛,下面C行是每头牛的牛棚的位置。寻找一种方案,使得总共的木板长度最短,覆盖所有的牛。核心:理解题意,条件限制:①最多M个木板②寻找最小的总木板长度因为有C头牛,所以总木板长度最小就为C,问题转化为,增加覆盖某些牛棚,那么长度增加对应的长度,同时满足木板块数不超过M贪心的思路:找出空白的牛棚位置和数目 例如 34_6_8_14...那么第一个空白为7,连续空白为1,第三个空白为 [9,13]长度为5原始状态下有X个空白(X+ 阅读全文

posted @ 2013-11-26 16:13 小书包_Ray 阅读(172) 评论(0) 推荐(0) 编辑

USACO SEC.1.3 No.1 Mixing Milk

摘要: 题意:需要收购总数为N的牛奶,现在有M个牛奶供应商(总量足够),给出总数和单价,求最小的花销。核心:基本的贪心解法,按单价排序逐个选取。目的在于熟悉基本的贪心法的基本方法和思路/*ID: lsswxr1PROG: milkLANG: C++*/#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace 阅读全文

posted @ 2013-11-26 14:57 小书包_Ray 阅读(149) 评论(0) 推荐(0) 编辑

2013年11月25日

USACO SEC.1.2 No.5 Dual Palindromes

摘要: 题意:输入一个N和S,在[S + 1, 10000]范围以内找到N个至少在[2,10]两种进制上面都是回文数的数字核心:仍然是转换十进制到任意进制的算法注意G++下要包含才能找到strcpy等相关的函数/*ID: lsswxr1PROG: dualpalLANG: C++*/#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include 阅读全文

posted @ 2013-11-25 11:04 小书包_Ray 阅读(166) 评论(0) 推荐(0) 编辑

USACO SEC.1.2 No.4 Palindromic Squares

摘要: 题意:输入一个进制b([2,20]),确定从[1,300]中哪些数的平方在该进制下是回文数解法:核心部分是将十进制数转换为任意进制数,除x取余,逆序排列/*ID: lsswxr1PROG: palsquareLANG: C++*/#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;///宏定义const 阅读全文

posted @ 2013-11-25 09:53 小书包_Ray 阅读(156) 评论(0) 推荐(0) 编辑

2013年11月19日

USACO SEC.1.2 No.3 Name That Number

摘要: 题意:给定一个数字(最长12),每个数字字符对应3个字母映射,再给定一个字典,求出对应数字所有字典当中存在的单词解法:普通解法:给出数字所有对应的单词,对每个单词查字典好的解法:反查字典,对应字典中的单词映射为数字,与输入进行比较(官方题解)普通枚举法如下/*ID: lsswxr1PROG: namenumLANG: C++*/#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include 阅读全文

posted @ 2013-11-19 21:04 小书包_Ray 阅读(150) 评论(0) 推荐(0) 编辑

2013年11月17日

USACO SEC.1.2 No.2 Transformations

摘要: 题意:给出两个方阵,给出是否能够通过顺时针旋转或者对折使得方阵相同解法:矩阵的旋转写的不是很简洁/*ID: lsswxr1PROG: transformLANG: C++*/#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;///宏定义const int INF = 1000000000;const . 阅读全文

posted @ 2013-11-17 10:33 小书包_Ray 阅读(183) 评论(0) 推荐(0) 编辑

2013年11月16日

USACO SEC.1.2 No.1 Milking Cows

摘要: 题意:给出N个村民,每个村民每天早上起来在闭区间[a, b]挤牛奶,求至少一个村民挤牛奶的最长时间, 和没有村民挤牛奶的最长时间解法:经典的区间合并问题, 将区间的端点作为事件,从左往右用扫描线进行扫描,需要注意的是,如果有结束事件和开始事件相同,先处理开始事件/*ID: lsswxr1PROG: milk2LANG: C++*/#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include 阅读全文

posted @ 2013-11-16 21:20 小书包_Ray 阅读(166) 评论(0) 推荐(0) 编辑

2013年11月15日

USACO SEC.1.1 No.4 broken necklace

摘要: 题意:从一个字符串某个字符断开,分别往两个方向数(环), 如果颜色相同则计入总数, 求最多数多少个珠子解法:简单枚举,每一个结点断开,O(n^2)复杂度,需要一些细节边界处理/*ID: lsswxr1PROG: beadsLANG: C++*/#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;///宏定 阅读全文

posted @ 2013-11-15 20:33 小书包_Ray 阅读(172) 评论(0) 推荐(0) 编辑

USACO SEC.1.1 NO.3 Friday the Thirteenth

摘要: 题意:统计从1900年1月1日(周一)过了n年之后的,每个月13号一共是周几解法:类似统计给定日期之间间隔几天/*ID: lsswxr1PROG: fridayLANG: C++*/#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;///宏定义const int INF = 1000. 阅读全文

posted @ 2013-11-15 19:20 小书包_Ray 阅读(190) 评论(0) 推荐(0) 编辑

导航