A: select the 2.1 side. Obviously, you can figure it out...
But at first I read the wrong question: Sad ,,,,
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<queue>#include<math.h>using namespace std;#define eps 1e-6#define zero(x) ((fabs(x)<eps?0:x))#define maxn 550int val[maxn];int main(){ int n,m,u,v,w; while(~scanf("%d%d",&n,&m)) { for(int i=1;i<=n;i++) { scanf("%d",&val[i]); } double ans=0.0; for(int i=1;i<=m;i++) { scanf("%d%d%d",&u,&v,&w); double pp=0; pp=1.0*(val[u]+val[v])/(w); if(pp>ans)ans=pp; } printf("%.10lf\n",ans); } return 0;}
B:
Suppose d <= SQRT (n ):
Then we use each 1 in array B to match array;
Complexity N * SQRT (n ).
Otherwise:
We use numbers to match each location to see if the person in this location exists.
Theoretically feasible complexity
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<queue>#include<math.h>using namespace std;#define eps 1e-6#define zero(x) ((fabs(x)<eps?0:x))#define maxn 110000#define LL long longint val[maxn];int n,d;LL x;int a[maxn];int b[maxn];int getNextX() { x = (x * 37 + 10007) % 1000000007; return x;}int initAB() { int i; for(i = 0; i < n; i = i + 1){ a[i] = i + 1; } for(i = 0; i < n; i = i + 1){ swap(a[i], a[getNextX() % (i + 1)]); } for(i = 0; i < n; i = i + 1){ if (i < d) b[i] = 1; else b[i] = 0; } for(i = 0; i < n; i = i + 1){ swap(b[i], b[getNextX() % (i + 1)]); }}int c[maxn];int ip[maxn];struct list{ int id; int next; int pre;}node[maxn];vector<int>vec;int main(){ while(~scanf("%d%d%lld",&n,&d,&x)) { vec.clear(); initAB(); for(int i=0;i<=n+1;i++) { node[i].id=i; node[i].next=i+1; node[i].pre=i-1; } for(int i=n;i>=1;i--) { a[i]=a[i-1]; b[i]=b[i-1]; } int m=sqrt(n); for(int i=1;i<=n;i++) { ip[a[i]]=i; } if(m<=d) { for(int i=n;i>=1;i--) { int z=ip[i]; for(int j=0;j!=n+1;j=node[j].next) { int y=node[j].id; if(y<z)continue; if(b[y-z+1]) { c[y]=i; node[node[j].next].pre=node[j].pre; node[node[j].pre].next=node[j].next; } } } } else { for(int i=1;i<=n;i++) { if(b[i]) { vec.push_back(i); } } for(int i=0;i<vec.size();i++) { int y=vec[i]; for(int j=1;j<=n-y+1;j++) { c[j+y-1]=max(c[j+y-1],a[j]); } } } for(int i=1;i<=n;i++) { printf("%d\n",c[i]); } } return 0;}
Codeforces round #254 (Div. 1)-a, B