当前位置:网站首页>Haut OJ 1241: League activities of class XXX
Haut OJ 1241: League activities of class XXX
2022-07-05 05:17:00 【hunziHang】
Problem description :
The once-a-month League event has come again , This activity is an outing , But? , The League branch secretary immediately poured cold water , It is said that our destination is on an island across the sea , You need to take a canoe to get to the island , A canoe can only take two people at most , And the total weight of passengers shall not exceed the maximum carrying capacity of the canoe . And the rental of canoes is very expensive , The class fee is limited .. We should try to reduce the cost of this activity , So find out the minimum number of canoes that can accommodate all students ,ykc I really want to go on this outing , Can you write a program to help him find out the minimum number of canoes to rent ?
Input :
First line input s, Number of groups representing test data ;
The first row of each set of data includes two integers w,n,80<=w<=200,1<=n<=300,w It is the maximum carrying capacity of a canoe ,n For the number of people ;
The next set of data is the weight of each person ( Not more than the carrying capacity of the ship );
Output :
The minimum number of canoes to rent per group
The sample input :
3 85 6 5 84 85 80 84 83 90 3 90 45 60 100 5 50 50 90 40 6
Sample output :
5 3 3
Cause analysis :
First, arrange the array from small to large , You can choose a largest and a smallest group of a boat , Notice the last if i=k, There is only one person left +1
Solution :
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[205];
int n,w,i,t,ans,k;
scanf("%d",&t);
while(t--)
{
ans=0;k=1;
scanf("%d%d",&w,&n);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+n+1);
for(i=n;i>=k;i--)
{
if(a[i]>=w)
ans++;
else
{
while(a[i]+a[k]<=w && i>k)
{
ans++;
k++;
i--;
}
if(a[i]+a[k]>w && i>k)
ans++;
if(i==k)
ans++;
}
}
printf("%d\n",ans);
}
}
边栏推荐
- win10虚拟机集群优化方案
- Reverse one-way linked list of interview questions
- Solon 框架如何方便获取每个请求的响应时间?
- [LeetCode] 整数反转【7】
- [allocation problem] 135 Distribute candy
- [转]:Apache Felix Framework配置属性
- FVP和Juno平台的Memory Layout介绍
- A three-dimensional button
- Judge the position of the monster in the role under unity3d
- The present is a gift from heaven -- a film review of the journey of the soul
猜你喜欢
![[paper notes] multi goal reinforcement learning: challenging robotics environments and request for research](/img/17/db8614b177f33ee4f67b7d65a8430f.png)
[paper notes] multi goal reinforcement learning: challenging robotics environments and request for research

Merge sort

Romance of programmers on Valentine's Day

Embedded database development programming (V) -- DQL

BUUCTF MISC

远程升级怕截胡?详解FOTA安全升级

【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research
![[turn]: OSGi specification in simple terms](/img/54/d73a8d3e375dfe430c2eca39617b9c.png)
[turn]: OSGi specification in simple terms

2022/7/2 question summary

The present is a gift from heaven -- a film review of the journey of the soul
随机推荐
xftp7与xshell7下载(官网)
Generate filled text and pictures
[转]:Apache Felix Framework配置属性
Three dimensional dice realize 3D cool rotation effect (with complete source code) (with animation code)
PMP考生,请查收7月PMP考试注意事项
Count sort
Es module and commonjs learning notes -- ESM and CJS used in nodejs
Optimization scheme of win10 virtual machine cluster
Leetcode word search (backtracking method)
2022 / 7 / 1 Résumé de l'étude
FVP和Juno平台的Memory Layout介绍
Unity find the coordinates of a point on the circle
[to be continued] [depth first search] 547 Number of provinces
[LeetCode] 整数反转【7】
[to be continued] [UE4 notes] L1 create and configure items
Judge the position of the monster in the role under unity3d
Under the national teacher qualification certificate in the first half of 2022
[转]MySQL操作实战(一):关键字 & 函数
支持多模多态 GBase 8c数据库持续创新重磅升级
Binary search basis