当前位置:网站首页>P1223 排队接水/1319:【例6.1】排队接水
P1223 排队接水/1319:【例6.1】排队接水
2022-07-07 08:14:00 【暴揍键盘的程序猿】
P1223 排队接水/1319:【例6.1】排队接水
# 排队接水
## 题目描述
有 $n$ 个人在一个水龙头前排队接水,假如每个人接水的时间为 $T_i$,请编程找出这 $n$ 个人排队的一种顺序,使得 $n$ 个人的平均等待时间最小。
## 输入格式
第一行为一个整数 $n$。
第二行 $n$ 个整数,第 $i$ 个整数 $T_i$ 表示第 $i$ 个人的等待时间 $T_i$。
## 输出格式
输出文件有两行,第一行为一种平均时间最短的排队顺序;第二行为这种排列方案下的平均等待时间(输出结果精确到小数点后两位)。
## 样例 #1
### 样例输入 #1
```
10
56 12 1 99 1000 234 33 55 99 812
```
### 样例输出 #1
```
3 2 7 8 1 4 9 6 10 5
291.90
```
## 提示
$n \leq 1000,t_i \leq 10^6$,不保证 $t_i$ 不重复。
当 $t_i$ 重复时,按照输入顺序即可(sort 是可以的)
【俩81分代码】
#include<stdio.h>
#include<iostream>
using namespace std;
const int N=1e3;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int n,a[N],t[N];
double cnt,sum;
void sort()
{
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if(t[i]>t[j])swap(t[i],t[j]),swap(a[i],a[j]);
}
signed main()
{
n=fread();
for(int i=1;i<=n;i++)t[i]=fread(),a[i]=i;
sort();
for(int i=1;i<=n;i++)cnt+=t[i]*(n-(i-1)),sum+=t[i];
for(int i=1;i<=n;i++)printf("%d ",a[i]);
printf("\n%.2lf",(cnt-sum)/n);
return 0;
}
数组开小了。
#include<stdio.h>
#include<iostream>
using namespace std;
#define int long long
const int N=1e3;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int n,a[N],t[N];
double cnt,sum;
void sort()
{
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if(t[i]>t[j])swap(t[i],t[j]),swap(a[i],a[j]);
}
signed main()
{
n=fread();
for(int i=1;i<=n;i++)t[i]=fread(),a[i]=i;
sort();
for(int i=1;i<=n;i++)cnt+=t[i]*(n-(i-1)),sum+=t[i];
for(int i=1;i<=n;i++)printf("%d ",a[i]);
printf("\n%.2lf",(cnt-sum)/n);
return 0;
}
【AC代码】
#include<stdio.h>
#include<iostream>
using namespace std;
const int N=1e4;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int n,a[N],t[N];
double cnt,sum;
void sort()
{
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if(t[i]>t[j])swap(t[i],t[j]),swap(a[i],a[j]);
}
signed main()
{
n=fread();
for(int i=1;i<=n;i++)t[i]=fread(),a[i]=i;
sort();
for(int i=1;i<=n;i++)cnt+=t[i]*(n-(i-1)),sum+=t[i];
for(int i=1;i<=n;i++)printf("%d ",a[i]);
printf("\n%.2lf",(cnt-sum)/n);
return 0;
}
【一堆运行超时代码】
#include<stdio.h>
#include<iostream>
using namespace std;
const int N=1e4;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int n,a[N],t[N];
double cnt,sum;
void sort()
{
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if(t[i]>t[j])swap(t[i],t[j]),swap(a[i],a[j]);
}
signed main()
{
n=fread();
for(int i=1;i<=n;i++)t[i]=fread(),a[i]=i;
sort();
for(int i=1;i<=n;i++)cnt+=t[i]*(n-(i-1)),sum+=t[i];
for(int i=1;i<=n;i++)printf("%d ",a[i]);
printf("\n%.2lf",(cnt-sum)/n);
return 0;
}
#include<stdio.h>
#include<iostream>
using namespace std;
const int N=1e4;
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int n,a[N],t[N];
double cnt,sum;
void sort()
{
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if(t[i]>t[j])swap(t[i],t[j]),swap(a[i],a[j]);
}
signed main()
{
n=fread();
for(int i=1;i<=n;i++)t[i]=fread(),a[i]=i;
sort();
for(int i=1;i<=n;i++)cnt+=t[i]*(n-(i-1)),sum+=t[i];
for(int i=1;i<=n;i++)printf("%d ",a[i]);
printf("\n%.2lf",(cnt-sum)/n);
return 0;
}
#include<stdio.h>
#include<iostream>
using namespace std;
const int N=1e4;
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int n,a[N],t[N];
double cnt,sum;
inline void sort()
{
for(register int i=1;i<=n;i++)
for(register int j=i+1;j<=n;j++)
if(t[i]>t[j])swap(t[i],t[j]),swap(a[i],a[j]);
}
signed main()
{
n=fread();
for(register int i=1;i<=n;i++)t[i]=fread(),a[i]=i;
sort();
for(register int i=1;i<=n;i++)cnt+=t[i]*(n-(i-1)),sum+=t[i];
for(register int i=1;i<=n;i++)printf("%d ",a[i]);
printf("\n%.2lf",(cnt-sum)/n);
return 0;
}
#include<stdio.h>
#include<iostream>
using namespace std;
const int N=1e4;
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int n,a[N],t[N];
double cnt,sum;
inline void sort()
{
for(register int i=1;i<=n;i++)
for(register int j=n;j>0;j--)
if(t[j]<t[j-1])swap(t[j],t[j-1]),swap(a[j],a[j-1]);
}
signed main()
{
n=fread();
for(register int i=1;i<=n;i++)t[i]=fread(),a[i]=i;
sort();
for(register int i=1;i<=n;i++)cnt+=t[i]*(n-(i-1)),sum+=t[i];
for(register int i=1;i<=n;i++)printf("%d ",a[i]);
printf("\n%.2lf",(cnt-sum)/n);
return 0;
}
#include<stdio.h>
#include<iostream>
using namespace std;
const int N=1e4;
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int n,a[N],t[N];
double cnt,sum;
inline void sort()
{
for(register int i=1;i<=n;i++)
for(register int j=i+1;j<=n;j++)
if(t[i]>t[j])swap(t[i],t[j]),swap(a[i],a[j]);
}
signed main()
{
n=fread();
for(register int i=1;i<=n;i++)t[i]=fread(),a[i]=i;
sort();
for(register int i=1;i<=n;i++)
{
cnt+=t[i]*(n-i+1),sum+=t[i];
printf("%d ",a[i]);
}
printf("\n%.2lf",(cnt-sum)/n);
return 0;
}
#include<stdio.h>
#include<iostream>
using namespace std;
const int N=1e4;
#define ing long long
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int n,a[N],t[N];
double cnt,sum;
inline void sort()
{
for(register int i=1;i<=n;i++)
for(register int j=i+1;j<=n;j++)
if(t[i]>t[j])swap(t[i],t[j]),swap(a[i],a[j]);
}
signed main()
{
n=fread();
for(register int i=1;i<=n;i++)t[i]=fread(),a[i]=i;
sort();
for(register int i=1;i<=n;i++)cnt+=t[i]*(n-i+1),sum+=t[i];
for(register int i=1;i<=n;i++)printf("%d ",a[i]);
printf("\n%.2lf",(cnt-sum)/n);
return 0;
}
#include<stdio.h>
#include<iostream>
using namespace std;
const int N=1e4;
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int n,a[N],t[N];
double cnt,sum;
inline void sort()
{
for(register int i=1;i<=n;i++)
for(register int j=i+1;j<=n;j++)
if(t[i]>t[j])swap(t[i],t[j]),swap(a[i],a[j]);
}
signed main()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
n=fread();
for(register int i=1;i<=n;i++)t[i]=fread(),a[i]=i;
sort();
for(register int i=1;i<=n;i++)cnt+=t[i]*(n-i+1),sum+=t[i];
for(register int i=1;i<=n;i++)printf("%d ",a[i]);
printf("\n%.2lf",(cnt-sum)/n);
return 0;
}
#include<algorithm>
#include<stdio.h>
#include<iostream>
using namespace std;
#define int long long
const int N=1e4;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int n,sum,m;
double ans;
struct node
{
int x,y;
}t[N];
bool cmp(node n,node m)
{
return n.y<m.y;
}
signed main()
{
n=fread(),m=n-1;
for(int i=1;i<=n;i++)t[i].y=fread(),t[i].x=i;
sort(t+1,t+1+n,cmp);
for(int i=1;i<=n;i++)printf("%lld ",t[i].x);
for(int i=1;i<n;i++)sum+=t[i].y*m,m--;
ans=sum*1.0/n;
printf("\n%.2lf",ans);
return 0;
}
【AC代码】
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct water
{
int time,id;
}a[1010];
bool cmp(struct water a,struct water b) {return a.time<b.time;}
int main()
{
int n;
double alltime=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].time;
a[i].id=i;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++)
{
cout<<a[i].id<<" ";
alltime=alltime+a[i-1].time*(n-i+1);
}
printf("\n%.2f",alltime/n);
return 0;
}
抄的。
【听取T声亿片】
#include<algorithm>
#include<stdio.h>
#include<iostream>
using namespace std;
const int N=1e4;
inline int fread()
{
char ch=getchar();
int n=0,m=1;
while(ch<'0' or ch>'9')
{
if(ch=='-')m=-1;
ch=getchar();
}
while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-48,ch=getchar();
return n*m;
}
int n;
double ans;
struct node
{
int x,y;
}t[N];
bool cmp(node n,node m)
{
return n.y<m.y;
}
signed main()
{
n=fread();
for(int i=1;i<=n;i++)t[i].y=fread(),t[i].x=i;
sort(t+1,t+1+n,cmp);
for(int i=1;i<=n;i++)
{
printf("%d ",t[i].x);
ans+=t[i-1].y*(n-i+1);
}
printf("\n%.2lf",ans/n);
return 0;
}
妈的这题有毒老子不做了。
边栏推荐
- Download Text, pictures and ab packages used by unitywebrequest Foundation
- 2022.7.6DAY598
- ORM -- grouping query, aggregation query, query set queryset object properties
- . Net configuration system
- The story of Plato and his three disciples: how to find happiness? How to find the ideal partner?
- 【STM32】STM32烧录程序后SWD无法识别器件的问题解决方法
- [sword finger offer] 42 Stack push in and pop-up sequence
- 【acwing】789. 数的范围(二分基础)
- fiddler-AutoResponder
- 高数_第1章空间解析几何与向量代数_向量的数量积
猜你喜欢
STM32中AHB总线_APB2总线_APB1总线这些是什么
Postman interface test II
Video based full link Intelligent Cloud? This article explains in detail what Alibaba cloud video cloud "intelligent media production" is
0x0fa23729 (vcruntime140d.dll) (in classes and objects - encapsulation.Exe) exception thrown (resolved)
Postman interface test I
Deconvolution popular detailed analysis and nn Convtranspose2d important parameter interpretation
【HigherHRNet】 HigherHRNet 详解之 HigherHRNet的热图回归代码
Appx代碼簽名指南
LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
Several schemes of building hardware communication technology of Internet of things
随机推荐
JMeter about setting thread group and time
【acwing】786. Number k
嵌入式背景知识-芯片
ES6中的函数进阶学习
Appx代碼簽名指南
ORM model -- associated fields, abstract model classes
对存储过程进行加密和解密(SQL 2008/SQL 2012)
Pdf document signature Guide
Memory ==c language 1
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
ArcGIS operation: batch modify attribute table
ORM model -- creation and query of data records
IPv4套接字地址结构
Learning records - high precision addition and multiplication
IO模型复习
关于hzero-resource报错(groovy.lang.MissingPropertyException: No such property: weight for class)
Methods of adding centerlines and centerlines in SolidWorks drawings
Use the fetch statement to obtain the repetition of the last row of cursor data
Postman interface test VII
C logging method