社区讨论

P1223过了样例,全WA,第一个测试点就是样例(但我确实过了样例),求助

P1223排队接水参与者 5已保存回复 6

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
6 条
当前快照
1 份
快照标识符
@lobyjf9v
此快照首次捕获于
2023/10/30 05:02
2 年前
此快照最后确认于
2023/11/04 10:19
2 年前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
struct node{
	int t;
	int num;
}a[1005];
bool cmp(const node &x, const node &y){
	return (x.t == y.t) ? (x.num < y.num ) : (x.t < y.t);
}
int main(){
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++){
    	a[i].num = i;
    	scanf("%d", &a[i].t);
    }
    sort(a + 1, a + 1 + n, cmp);
    int v = 0;
    for (int i = 1; i <= n; i++){
    	printf("%d ", a[i].num);
    	v += a[i].t * (n - i);
    }
    printf("\n%.2llf", v * 1.0 / n);
  	return 0;
}

回复

6 条回复,欢迎继续交流。

正在加载回复...