
Algorithm
USTC_YM
A freshman with little capacity now but a great dream forever.
展开
-
qsort与bsearch学习
排序算法有很多,搜索算法也很多。c语言提供了qsort和bsearch这两个库函数,今天学习了一下,感觉很实用。 下面是测试代码:#include<stdio.h>#include<stdlib.h>#include<time.h>int cmp(const void*,const void*); int main(){ int s[]={3,4,5,6,2,1}; /*参原创 2016-06-20 20:51:58 · 353 阅读 · 0 评论 -
Section 1.2 Palsquare
进制转换,num2str问题/*原创 2016-08-28 00:25:21 · 379 阅读 · 0 评论 -
Section 1.2 Dual Palindromes
数制转换,num2str,string方法原创 2016-08-29 22:33:24 · 403 阅读 · 0 评论 -
Section 1.3 Greedy Algorithm
The basic idea behind greedy algorithms is to build large solutions up from smaller ones. Unlike other approaches, however, greedy algorithms keep only the best solution they find as they go along.翻译 2016-08-29 23:21:22 · 567 阅读 · 0 评论 -
Section 1.2 Name That Number
一个匹配搜索的问题,不过是我第一次写从文件中即时读取即时搜索。 开始的思路是通过input把number转为name,再进行搜索,后来发现这样不仅费时而且浪费空间;于是采用了把data.txt中的name转化为number,依次与input匹配的方法。原创 2016-08-20 00:07:01 · 313 阅读 · 0 评论 -
Section 1.3 Mixing Milk
基础greedy algorithm,sort函数调用原创 2016-08-31 00:17:11 · 284 阅读 · 0 评论 -
Section 1.3 Barn Reapir
贪心算法,思路不难但在提交过程中发现很多bug: 1.得到需要“切板”的位置后,应该按num排序 2.当M == 1时要特别处理,否则number为空向量,程序异常退出 3.输入牛的位置是无序的,要先按num升序排序 4.当M > C的时候,number个数应该为min(M,C)/*原创 2016-08-31 14:45:19 · 339 阅读 · 0 评论 -
Section 1.2 Milking Cows
做的第一个模拟时间轴的问题,关键在于search部分的对于t1,t2的不断变化。 也通过这一题学习了algorithm中的sort函数使用。/*ID: alexyua2PROG: milk2LANG: C++*/#include<fstream>#include<algorithm>#include<vector>using namespace std;ifstream fin("原创 2016-08-14 21:54:13 · 265 阅读 · 0 评论 -
Section 1.2 Transformations
这道搜索题没什么绕弯的地方,把transformation用矩阵位置变换表示,然后一一验证即可。对于#5 combination我写得比较啰嗦: )/*ID: alexyua2PROG: transformLANG: C++*/#include<fstream>using namespace std;ifstream fin("transform.in");ofstream fout("原创 2016-08-14 22:43:56 · 234 阅读 · 0 评论