我这第二个for循环,为什么进不去呢,一直输出0

P2878 [USACO07JAN] Protecting the Flowers S

@[傻肥狍子](/user/423006) ``` #include<bits/stdc++.h> using namespace std; double t[1000101]; struct lie { int q; int w; double e; }o[1010000]; bool w(lie k,lie h) { return k.e>h.e; } int main() { int a,i,j; double sum=0,num=0; scanf("%d",&a); for(i=1;i<=a;i++) { scanf("%d %d",&o[i].q,&o[i].w); o[i].e=1.0*o[i].w/o[i].q; sum+=o[i].w; } sort(o+1,o+a+1,w); for(i=1;i<=a;i++) { if(o[i].q==0) { continue; } else { sum-=o[i].w; num+=sum*2*o[i].q; } } printf("%.0lf",num); return 0; }
by Clare613 @ 2023-02-21 22:51:41


|