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. 用angularjs开发下一代web应用(二):angularjs应用骨架(二)

    1.浅谈非入侵式JavaScript <div ng-click="doSomething()">...</div>这些指令和原来的事件处理器有下面不同之处 ...

  2. Android KitKat 4.4 Wifi移植之Wifi driver

    本文讲述在Linux 3.10下Realek RTL8723A Linux Wifi 驱动的移植. Prerequisites 硬件平台:Atmel SAMA5 软件平台:Linux 3.10 + A ...

  3. Java中@Deprecated、@SupressWarning、@Override的作用

    Annotation注解在 Java 中有着很广泛的,他是做为一种标识 为javac所识别.每一个注解 都对应这一个Java类  在java.lang包中 有三个注解  分别是 Deprecated  ...

  4. iot 表索引dump《2》

    iot表测试: 在create table语句后面使用organization index,就指定数据表创建结构是IOT.但是在不指定主键Primary Key的情况下,是不允许建表的. create ...

  5. 【Demo 0001】Android 程序结构

    Android 学习步骤及内容:     1.  Android 程序结构(开发环境搭建,Android第一程序,程序启动过程以及工程介绍):     2.  Android 事件(通用使用规则,通用 ...

  6. Could not find or load main class

    Then add '.' to your $CLASSPATH with CLASSPATH=.:$CLASSPATH or as a paramater with java -classpath . ...

  7. 浅谈mapreduce程序部署

    尽管我们在虚拟机client上能非常快通过shell命令,进行运行一些已经封装好实例程序,可是在应用中还是是自己敲代码,然后部署到server中去,以下,我通过程序进行浅谈一个程序的部署过程. 在启动 ...

  8. UVA 116 Unidirectional TSP(dp + 数塔问题)

     Unidirectional TSP  Background Problems that require minimum paths through some domain appear in ma ...

  9. Spring核心技术

    这是第二次看关于Spring的资料,由于刚開始学习Spring的时候是边看视频边学习的,所以更注重的是实现代码,可是对宏观的掌握还是不够,这次主要从宏观的角度来分析一下Spring. 什么是Sprin ...

  10. USM锐化之openCV实现,附赠调整对比度函数

    源地址:http://www.cnblogs.com/easymind223/archive/2012/07/03/2575277.html 常用Photoshop的玩家都知道Unsharp Mask ...