标题消失好评
by cjh20090318 @ 2024-03-16 14:38:50
标题有特殊符号在首页就会消失(;´д`)ゞ
by cff_0102 @ 2024-03-16 14:45:17
好家伙,差点没能点进来
by Min6700 @ 2024-03-16 14:57:26
把p,w,j,定义到结构体里,不然p位置变了,w,j的位置还是不变。
by Harry2013 @ 2024-03-16 15:00:05
**只给数组p排了序,数组w,j和p对应不上。**
我和你思路差不多,没用结构体,蒟蒻,大佬轻喷。
```cpp
//部分背包问题
#include<bits/stdc++.h>
using namespace std;
double n,t,m[109],v[109],x[109],y[109];
double sum;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>t;
for(int i=0;i<n;i++)
{
cin>>m[i]>>v[i];
x[i]=v[i]/m[i];
y[i]=x[i];
}
double maxx=-1.0;
int p,l=0;
while(t>0)
{
if(l==n)
break;
l++;
maxx=0;
for(int i=0;i<n;i++)
{
if(maxx<x[i])
{
maxx=x[i];
p=i;
}
}
x[p]=-1;
if(t>=m[p])
{
t-=m[p];
sum+=v[p];
}
else
{
sum+=(t*1.0*y[p]);
t=0;
}
}
cout<<fixed<<setprecision(2)<<sum;
return 0;
}
```
by NN1003 @ 2024-03-18 17:09:31
huuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
by wuruohan0101 @ 2024-03-28 21:11:27