nyoj 71 独木舟上的旅行
来源:互联网 发布:网络黑客的主要行为 编辑:程序博客网 时间:2024/06/05 02:58
#include<stdio.h>
#include<stdlib.h>
int cmp(const void*a,const void*b)
{
return *(int*)b-*(int*)a;
}
int main()
{
int a[300];
int s,i,j;
scanf("%d",&s);
while(s--)
{
int w,n;
int count=0;
scanf("%d%d",&w,&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
qsort(a,n,sizeof(int),cmp);
for(i=0,j=n-1;i<=j;)
{
if(a[i]+a[j]<=w)
{
i++;
j--;
count++;//判断最重的人能否和最轻的人坐同一艘船 不行的话 继续比较
}
else if(i==j)
{
count++;
}
else
{
i++;
count++;
}
}
printf("%d\n",count);
}
return 0;
}
#include<stdlib.h>
int cmp(const void*a,const void*b)
{
return *(int*)b-*(int*)a;
}
int main()
{
int a[300];
int s,i,j;
scanf("%d",&s);
while(s--)
{
int w,n;
int count=0;
scanf("%d%d",&w,&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
qsort(a,n,sizeof(int),cmp);
for(i=0,j=n-1;i<=j;)
{
if(a[i]+a[j]<=w)
{
i++;
j--;
count++;//判断最重的人能否和最轻的人坐同一艘船 不行的话 继续比较
}
else if(i==j)
{
count++;
}
else
{
i++;
count++;
}
}
printf("%d\n",count);
}
return 0;
}
0 0
- nyoj 71 独木舟上的旅行
- NYOJ-71:独木舟上的旅行
- nyoj 71 独木舟上的旅行
- nyoj-71-独木舟上的旅行
- NYOJ 71题 独木舟上的旅行
- NYOJ,71,独木舟上的旅行
- nyoj 71 独木舟上的旅行
- NYOJ 71 独木舟上的旅行
- NYOJ 71 独木舟上的旅行
- NYOJ-71 独木舟上的旅行
- Nyoj 71 独木舟上的旅行
- NYOJ-71 独木舟上的旅行
- NYOJ 71 独木舟上的旅行
- NYOJ题目71 独木舟上的旅行
- NYOJ 71 独木舟上的旅行
- NYOJ独木舟上的旅行71
- NYOJ 71 独木舟上的旅行
- nyoj 71 独木舟上的旅行
- hbase远程调试
- Android下利用SharePreference存储序列化对象的方法
- matlab 路径下存图片list
- Java没有头文件的原因
- Android新的surpport支持库SurpportDesign之TextInputLayout
- nyoj 71 独木舟上的旅行
- Python(1):在Python 中print的新用法
- 亚马逊新手知识必备
- 【Android】App应用崩溃(Crash/Force Close)之后如何让它自动重启?
- python案例1---修改haproxy的配置文件
- post qt.network.ssl: QSslSocket: cannot resolve SSLv2_client_method解决
- QC登录出现Following client components were not downloaded successfully问题解决
- hadoop2.7.2集群hive-1.2.1整合hbase-1.2.1
- exe6.17