#3#10 sort排序WA了,求调

P1223 排队接水

@[LingerLi](/user/840044) 排序时如果 time 相等,i 越小越靠前
by Night_sea_64 @ 2022-12-13 13:24:06


@[Netherite_sword_666](/user/554145) 谢谢,那我改一下cmp函数
by Sergei_Rachmaninoff @ 2022-12-13 13:26:11


@[Netherite_sword_666](/user/554145) 似乎还是不行,cmp已经改成`return (a.time != b.time) ? (a.time < b.time) : (a.i < b.i);`
by Sergei_Rachmaninoff @ 2022-12-13 13:30:58


看样例应该是平均值的问题
by Sergei_Rachmaninoff @ 2022-12-13 13:34:31


@[LingerLi](/user/840044) 那我看看还有没有问题
by Night_sea_64 @ 2022-12-13 13:36:01


@[LingerLi](/user/840044) 样例有错吗
by Night_sea_64 @ 2022-12-13 13:36:49


@[Netherite_sword_666](/user/554145) 样例没问题,就WA了两个点
by Sergei_Rachmaninoff @ 2022-12-13 13:39:27


@[LingerLi](/user/840044) 我调不出来,给您看看我很久之前写的代码 ```cpp #include<iostream> #include<algorithm> #include<cstdio> using namespace std; struct p { int id,t; void read(int i) { cin >> t; id=i; } }a[1000010]; int ti[1000010]; bool cmp(p x,p y) { if(x.t!=y.t)return x.t<y.t; return x.id<y.id; } int main() { int n; cin >>n; for(int i=1;i<=n;i++) a[i].read(i); sort(a+1,a+n+1,cmp); for(int i=1;i<=n;i++) { cout << a[i].id <<" "; ti[i]=ti[i-1]+a[i-1].t; } cout<<endl; double sum=0; for(int i=1;i<=n;i++) sum+=ti[i]; printf("%.2f",sum/n); return 0; } ```
by Night_sea_64 @ 2022-12-13 13:44:23


别复制就行
by Night_sea_64 @ 2022-12-13 13:45:06


@[Netherite_sword_666](/user/554145) 好的,谢谢
by Sergei_Rachmaninoff @ 2022-12-13 13:45:46


| 下一页