当前位置:网站首页>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);
}
}
边栏推荐
- Unity intelligent NPC production -- pre judgment walking (method 1)
- Download and use of font icons
- 2022/7/2 question summary
- [trans]: spécification osgi
- Bucket sort
- 使用Room数据库报警告: Schema export directory is not provided to the annotation processor so we cannot expor
- Cocos2dx Lua registers the touch event and detects whether the click coordinates are within the specified area
- 发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
- Unity sends messages and blocks indecent words
- When will Wei Lai, who has been watched by public opinion, start to "build high-rise buildings" again?
猜你喜欢

小程序直播+电商,想做新零售电商就用它吧!

支持多模多态 GBase 8c数据库持续创新重磅升级

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

Use of snippets in vscode (code template)

Unity check whether the two objects have obstacles by ray
![[转]MySQL操作实战(三):表联结](/img/70/20bf9b379ce58761bae9955982a158.png)
[转]MySQL操作实战(三):表联结

Stm32cubemx (8): RTC and RTC wake-up interrupt

Optimization scheme of win10 virtual machine cluster
![[speed pointer] 142 circular linked list II](/img/f8/222a360c01d8ef120b61bdd2025044.jpg)
[speed pointer] 142 circular linked list II

Generate filled text and pictures
随机推荐
PR first time
2022年上半年国家教师资格证考试
TF-A中的工具介绍
嵌入式数据库开发编程(五)——DQL
PMP考生,请查收7月PMP考试注意事项
Grail layout and double wing layout
Unity writes timetables (without UI)
2022/7/1学习总结
Page countdown
Optimization scheme of win10 virtual machine cluster
Heap sort summary
Lua GBK and UTF8 turn to each other
Development error notes
C iterator
When will Wei Lai, who has been watched by public opinion, start to "build high-rise buildings" again?
Unity enables mobile phone vibration
Unity check whether the two objects have obstacles by ray
stm32Cubemx(8):RTC和RTC唤醒中断
用 Jmeter 工具做个小型压力测试
UE4/UE5 虚幻引擎,材质篇(三),不同距离的材质优化