⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 040320197_2.cpp

📁 磁盘的最优存储问题! 计算最优存储时间是改进了一下
💻 CPP
字号:
#include"iostream.h"
#include"fstream.h"
#include"stdlib.h"
#include"time.h"
int partion(int a[],int low,int high)
	{
    int key=a[low];
    while(low<high)
	{
		while(low<high&&a[high]>=key)
			--high;
		  a[low]=a[high];
		 while(low<high&&a[low]<=key)
			++low;
		 a[high]=a[low];
	}
	a[low]=key;
   return low;
	}
void qsort(int a[],int low,int high)
{
	if(low<high)
	{
		int p=partion(a,low,high);
		qsort(a,low,p-1);
		qsort(a,p+1,high);
	}
}
void main()
{
	ifstream in("input.txt");
	if(!in)
	{
		cerr<<"can't open input file.\n";
		exit(1);
	}
	int n;
   in>>n;
    int *input=new int[n];
   double sum0=0;
   for(int i=0;i<n;i++)
	  {
	   in>>input[i];
	   sum0+=input[i];
   }
   double sum1=sum0;
   in.close();
   qsort(input,0,n-1);
   int *a=new int[n];
   int k=n-1;
   int j=0;
   int t=0;
    for(k=n-1;j<n;k--)
    {
		a[k]=input[j++];
		if(j!=n)
		a[t++]=input[j++];
	}
    double sum=0,sum2=0;
	for(i=0;i<n;i++)
   {
	   sum2+=a[i];
	   sum0-=a[i];
       sum+=(sum2/sum1)*(sum0/sum1);
	} 
    ofstream out("output.txt");//建立并打开输出文件
	if(!out)
	{
		cerr<<"can't open output file.\n";
		exit(1);
	}
	out<<sum;
	out.close(); 
	cout<<clock();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -