CT


私信TA

用户名:1552081127

访问量:594

签 名:

等  级
排  名 60225
经  验 192
参赛次数 0
文章发表 1
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

参考代码:

#include <iostream>


using namespace std;


void quick_sort(int a[],int begin,int end)//数组排序函数 

{

if(begin>end) return ;

int t=a[begin],b=begin,e=end;

while(b<e)

{

while(a[e]>=t&&b<e) e--;

a[b]=a[e];

while(a[b]<=t&&b<e) b++;

  a[e]=a[b];

    }

    a[e]=t;

    quick_sort(a,begin,e-1);

    quick_sort(a,e+1,end);

    return;

}

int main()

{

int w,n,s,i,j; 

cin>>w>>n;

int a[n];

for(i=0;i<n;i++)

{

cin>>a[i];

}

quick_sort(a,0,n-1);

i=0;  j=n-1;  s=0;

while(i<j)

{

if(a[j]+a[i]<=w)

{

--j; ++i;

++s;

}

else

{

--j;

++s; 

}

}

if(i==j) ++s;//如果i=j,那么a[i]还未被分组,则++S,分组+1 

cout<<s;

return 0;

}

 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区