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. 性能测试之LoardRunner 检查点

    概述 1.检查点概念 2.实例 以下是详细介绍 检查点:首先来看一下VuGen确定脚本运行成功的判断条件.在录制编写脚本后,通常就会进行回放,如果回放通过没有错误,就认为脚本是正确的.究竟VuGen怎 ...

  2. hdu1087Super Jumping! Jumping! Jumping!(最大递增序列和)

    题意:棋牌游戏如今,一种被称为“超级跳!跳!跳!“HDU是非常流行的.也许你是个好孩子,这个游戏知之甚少,所以我介绍给你吧. 可以玩游戏由两个或两个以上的球员 .它由一个棋盘(棋盘)和一些棋子(棋子) ...

  3. jstorm简介(转)

    Jstorm是参考storm的实时流式计算框架,在网络IO.线程模型.资源调度.可用性及稳定性上做了持续改进,已被越来越多企业使用 作为commiter和user,我还是非常看好它的应用前景,下面是在 ...

  4. 基于visual Studio2013解决面试题之0304镜像二叉树

     题目

  5. CABasicAnimation学习Demo 包含了一些经常使用的动画效果

    个人写的一些样例: // // ViewController.m // CABasicAnimationDemo // // Created by haotian on 14-6-13. // Cop ...

  6. HDOJ 4883 TIANKENG’s restaurant

    称号: TIANKENG's restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Ja ...

  7. 中介者模式 C++ 实现

    #include<iostream> #include<string> #include<vector> #include<cstdlib> using ...

  8. 消息函数一般是私有的,因为不需要程序员显示的调用,但子类如果需要改写这个方法,则改成保护方法Protected

    许多的面向对象程序设计语言都支持对消息的处理.消息处理是一种动态响应客户类发出的请求,它与过程调用不同.过程调用中,客户类必须知道服务类提供了哪些过程,以及每个过程的调用约定,并且在调用时需要明确指出 ...

  9. haproxy配置监控redis主备切换(转)

    环境前提:     redis sentinel配置,三台主机,且配置运行良好        配置文件中添加: frontend ft_redis  bind 0.0.0.0:6379 name re ...

  10. 依据不同的操作系统读取配置文件/java读取属性文件代码

    package cn.com.css.common.util; /**  * @brief OSEnum.java 操作系统的枚举  * @attention  * @author 涂作权  * @d ...