磁盘文件最优存储问题
2015-11-22 22:19
351 查看
#include "iostream" #include "fstream" #include "queue" using namespace std; /* 将n个文件按概率排序,排序后有p1<=p2<=p3...<=pn f(n-1)占中心磁道,f(n-2)和f(n-3)分居f(n-1)两侧,f(n-4)和f(n-5)分居最外两侧 */ double p[50]; //返回n个文件的最小期望检索时间 //实际上p[i] = p[i]/(p[1]+p[2]+..+p ) double greedy(int n) { sort(p, p+n); //按概率排序 int i, j; int *x = new int ; int k = (n-1)/2; //中心 x[k] = p[n-1]; for(i=k+1; i<n; i++) x[i] = p[n-2*(i-k)]; for(i=k-1; i>=0; i--) x[i] = p[n-2*(k-i)-1]; int P = 0; double sum = 0; for(i=0; i<n; i++) { P += p[i]; for(j=i+1; j<n; j++) sum += x[i]*x[j]*(j-i); } return sum/P/P; } int main() { ifstream fin("磁盘最优存储.txt"); int n; cout << "输入文件个数:"; fin >> n; cout << n; cout << "\n输入各文件检索概率:\n"; int i; for(i=0; i<n; i++) { fin >> p[i]; cout << p[i] << " "; } cout << "\n最小期望检索时间为:" << greedy(n); cout << endl; fin.close(); return 0; }
相关文章推荐
- ASCII 与 Int
- .tar.gz文件和.rpm文件的区别
- sql中删除数据方法区别
- MD5加密
- UWP开发入门(二)——RelativePanel
- sed for windows 双引号内部内容的替换
- Tiny4412之串口(Uart)驱动编写
- 负载均衡
- 读书笔记--开发环境配置中的坑
- Python_文件对象类型及其读写函数详解
- 王者震荡市如何飞身换马
- iOS 百度定位实现
- zzuli生化危机(dfs)
- contiki 学习记录
- # 欢迎使用Markdown编辑器写博客
- iOS 事件传递流程
- SAML在SSO中的应用
- centos6.4中安装java,编译和运行java的一个例子
- 叠筐
- ASP字符串转换函数用法