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;
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的更多相关文章

  1. Codeforces Round 254 (Div. 2)

    layout: post title: Codeforces Round 254 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  2. Codeforces Round #254 (Div. 1) C. DZY Loves Colors 线段树

    题目链接: http://codeforces.com/problemset/problem/444/C J. DZY Loves Colors time limit per test:2 secon ...

  3. Codeforces Round #254 (Div. 1) D - DZY Loves Strings

    D - DZY Loves Strings 思路:感觉这种把询问按大小分成两类解决的问题都很不好想.. https://codeforces.com/blog/entry/12959 题解说得很清楚啦 ...

  4. Codeforces Round #254 (Div. 1) D. DZY Loves Strings hash 暴力

    D. DZY Loves Strings 题目连接: http://codeforces.com/contest/444/problem/D Description DZY loves strings ...

  5. Codeforces Round #254 (Div. 1) C. DZY Loves Colors 分块

    C. DZY Loves Colors 题目连接: http://codeforces.com/contest/444/problem/C Description DZY loves colors, ...

  6. Codeforces Round #254 (Div. 1) A. DZY Loves Physics 智力题

    A. DZY Loves Physics 题目连接: http://codeforces.com/contest/444/problem/A Description DZY loves Physics ...

  7. Codeforces Round #254 (Div. 2) A. DZY Loves Chessboard —— dfs

    题目链接: http://codeforces.com/problemset/problem/445/A 题解: 这道题是在现场赛的最后一分钟通过的,相当惊险,而且做的过程也很曲折. 先是用递推,结果 ...

  8. Codeforces Round #254 (Div. 1) C DZY Loves Colors

    http://codeforces.com/contest/444/problem/C 题意:给出一个数组,初始时每个值从1--n分别是1--n.  然后两种操作. 1:操作 a.b内的数字是a,b内 ...

  9. [题解]Codeforces Round #254 (Div. 2) B - DZY Loves Chemistry

    链接:http://codeforces.com/contest/445/problem/B 描述:n种药品,m个反应关系,按照一定顺序放进试管中.如果当前放入的药品与试管中的药品要反应,危险系数变为 ...

  10. [题解]Codeforces Round #254 (Div. 2) A - DZY Loves Chessboard

    链接:http://codeforces.com/contest/445/problem/A 描述:一个n*m的棋盘,有一些格子不能放棋子.现在把黑白棋子往上放,要求放满且相邻格子的棋子颜色不同.输出 ...

随机推荐

  1. Matlab图像处理系列2———空间域平滑滤波器

    注:本系列来自于图像处理课程实验,用Matlab实现最主要的图像处理算法 本文章是Matlab图像处理系列的第二篇文章.介绍了空间域图像处理最主要的概念----模版和滤波器,给出了均值滤波起和中值滤波 ...

  2. Delphi线程池

    unit uThreadPool; {   aPool.AddRequest(TMyRequest.Create(RequestParam1, RequestParam2, ...)); } inte ...

  3. metasploit学习之ms03_026

    傻瓜式利用ms03_026_dcom: Matching Modules ================ Name Disclosure Date Rank Description ---- --- ...

  4. Qt制作应用插件

    在Qt下,插件有两种形式,一种是用于QtCreator下,扩展IDE功能.另一种是用于扩展开发者的应用.本文要讲的是后者. 定义一个纯虚类作为插件接口 #include <QtPlugin> ...

  5. LA - 4043 - Ants

    题意:n只蚂蚁,n棵树,每只蚂蚁要连一棵树,连线(直线)不能相交,给出n只蚂蚁和n棵树的坐标,输出n只蚂蚁所配对的树的编号(1 <= n <= 100, -10000 <= 坐标x, ...

  6. drupal进入不了后台时候的解决办法,作者使用drush方案,已验证

    drupal把正在用的主题不小心删了,怎么进后台? 方法一: 去variable表里把默认主题换了 方法二: ?q=user 登录到管理区,开启简洁连接使用user(网站根目录下面) admin/ap ...

  7. Mina2 研究总结

    一.Mina框架. Mina的框架大概是这么个样子: 底层由Java 的NIO 1.0实现 核心架构应该是这样: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZX ...

  8. NSHashTable 和 NSMapTable学习

    今天,在实现play gif时间功能,我看见两个陌生班,只需看看这个纪录: NSSet和NSDictionary是两个经常使用的类,可是他们默认假定了当中对象的内存行为.对于NSSet.object是 ...

  9. 在phpmyadmin后台获取webshell方法汇总整理

    方法一: CREATE TABLE `mysql`.`xiaoma` (`xiaoma1` TEXT NOT NULL ); INSERT INTO `mysql`.`xiaoma` (`xiaoma ...

  10. ADO面板上的控件简介

    ADO面板上的控件简介 一. TADOConnection组件该组件用于建立数据库的连接.ADO的数据源组件和命令组件可以通过该组件运行命令及数据库中提取数据等.该组件用于建立数据库的连接,该连接可被 ...