本文主要是介绍Codeforces Round #254 (Div. 1)-A,B,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
A:选取两点一边就可以了,很明显可以想出来。。。
但是一开始看错题了,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 550
int 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:
如果d<=sqrt(n):
那么我们就用b数组中的每一个1去匹配A数组;
复杂度n*sqrt(n).
否则:
我们就用数字去匹配每一个位置,看这个位置的人是否会存在。
复杂度理论上可行
#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 long
int 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;elseb[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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!