4 条题解

  • 0
    @ 2024-4-12 4:03:35
    #include <bits/stdc++.h>
    using namespace std;
    
    struct treasure{   //连锁数据排序
        double m, v, rate;
    };
    
    bool cmp(treasure a, treasure b)
    {
        return a.rate>b.rate;
    }
    
    int main()
    {
        int N, T;
        cin >> N >> T;
        vector<treasure> treasures(N);
        double sum=0;
        for(int i=0; i<N; i++)
        {
            cin >> treasures[i].m >> treasures[i].v;
            treasures[i].rate=treasures[i].v/treasures[i].m;
        }
        sort(treasures.begin(), treasures.end(), cmp);
        for(int i=0; i<N; i++)
        {
            if(T>=treasures[i].m)   //尽量不造成出现负数的情况
            {
                T-=treasures[i].m;
                sum+=treasures[i].v;
            }
            else
            {
                sum+=treasures[i].rate*T;
                T=0;
                break;
            }
        }
        printf("%.2lf", sum);
        return 0;
    }
    
    • 0
      @ 2024-4-11 14:22:52

      #include<iostream> #include<vector> #include<algorithm> #include<iomanip> using namespace std; struct gold { double value; double weight; double rate; }; bool cmp(const gold& t1,const gold& t2) { return t1.rate > t2.rate; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, t; double numt = 0; double numv=0; vector<gold> v; cin >> n >> t; if (n < 0 || t < 0 || n>100 || t>1000)return 0; v.resize(n); for (int i = 0; i < n; i++) { cin >> v[i].weight >> v[i].value; if (v[i].value < 1 || v[i].weight < 1 || v[i].value>120)return 0; v[i].rate = v[i].value / v[i].weight; } sort(v.begin(),v.end(),cmp); int i = 0; while (numt <= t && i < n) { numt += v[i].weight;//可能会大于 numv += v[i].value; i++; } if (numt > t) { numv-=(numt - t)* v[i-1].rate; } cout << fixed<<setprecision(2)<<numv; return 0; }

      • 0
        @ 2024-4-8 14:57:09
        #include<iostream>
        #include<string>
        #include<cmath>
        #include<algorithm>
        #include<cstdio>
        using namespace std;
        const int N=102;
        int n,zhilian;
        struct gold{
        	double weight;
        	double worth;
        	double every;
        }go[N];
        bool compair(gold a,gold b){
        	return a.every>b.every;
        }
        int main(){
        	cin>>n>>zhilian;
        	int i=0;
        	int t=n;
        	while(t--){
        		int x1,x2;
        		scanf("%d%d",&x1,&x2);
        		go[i].weight=x1,go[i].worth=x2;
        		go[i].every=(double)x2/x1;
        		i++;	
        	}
        	sort(go,go+n,compair);
        	double res=0;
        	for(int j=0;j<n;j++){
        		if(zhilian>go[j].weight) res+=go[j].worth,zhilian-=go[j].weight;
        		else {
        			res+=go[j].every*zhilian;
        			break;
        		}
        	}
        	printf("%.2lf",res);
        	return 0;
        	
        }
        
        • 0
          @ 2024-4-8 10:41:33

          /上天啊 难道你看不出我很爱她/ #include<bits/stdc++.h> using namespace std; struct Node{ double m,v; double avg; }a[110]; bool cmp(Node x,Node y) { return x.avg>y.avg; } int main() { int n,t;cin>>n>>t; for(int i = 1;i<=n;i++) { cin>>a[i].m>>a[i].v; a[i].avg = a[i].v/a[i].m; } sort(a+1,a+1+n,cmp); double sum = 0; for(int i = 1;i<=n;i++) { if(t>=a[i].m) { sum = sum+a[i].v; t = t-a[i].m; } else { sum = sum+t1.0a[i].avg; break; } } cout<<fixed<<setprecision(2)<<sum; }

          • 1

          信息

          ID
          77
          时间
          1000ms
          内存
          256MiB
          难度
          7
          标签
          递交数
          342
          已通过
          82
          上传者