南阳71----独木舟上的旅行

Posted Jeson

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了南阳71----独木舟上的旅行相关的知识,希望对你有一定的参考价值。

 1 #include <cstdio>
 2 #include <cstring>
 3 int a[205];//a[i]表示体重为i的人的个数
 4 int main(){
 5     int s,w,n,x;
 6     scanf("%d",&s);
 7     while(s--){
 8         scanf("%d%d",&w,&n);
 9         for(int i = 0; i < n; ++i){
10             scanf("%d",&x);
11             ++a[x];
12         }
13         int t = w, ans = 0, count = 0;//t表示船剩余可承载量,ans记录船只数,count记录船上人数
14         while(n){
15             int i;
16             for(i = t; i; --i)
17                 if(a[i]){
18                     if(t < i) continue;//可承载量不足,找更轻的人
19                     if(t == w) ++ans;
20                     --n; --a[i];
21                     ++count;
22                     t -= i;
23                     break;
24                 }
25             if(!i || !t || count == 2) { t = w; count = 0; }
26             //在满足条件内找不到人,或者刚好装满,或者装够两个人,使用新船只,更新相关变量
27         }
28         printf("%d\n",ans);
29         memset(a,0,sizeof(a));
30     }
31     return 0;
32 }

 

以上是关于南阳71----独木舟上的旅行的主要内容,如果未能解决你的问题,请参考以下文章

独木舟上的旅行

独木舟上的旅行

独木舟上的旅行

独木舟培训10月24-25日,Paddle Canada湖泊双人独木舟初级培训

71岁的亿万富翁坐自家飞船成功游览太空!此前已为太空旅行砸了超10亿美元

使用 U 盘上的 GIT 获取“旅行代码”