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;
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的更多相关文章
- Codeforces Round 254 (Div. 2)
layout: post title: Codeforces Round 254 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- 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 ...
- Codeforces Round #254 (Div. 1) D - DZY Loves Strings
D - DZY Loves Strings 思路:感觉这种把询问按大小分成两类解决的问题都很不好想.. https://codeforces.com/blog/entry/12959 题解说得很清楚啦 ...
- 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 ...
- Codeforces Round #254 (Div. 1) C. DZY Loves Colors 分块
C. DZY Loves Colors 题目连接: http://codeforces.com/contest/444/problem/C Description DZY loves colors, ...
- Codeforces Round #254 (Div. 1) A. DZY Loves Physics 智力题
A. DZY Loves Physics 题目连接: http://codeforces.com/contest/444/problem/A Description DZY loves Physics ...
- Codeforces Round #254 (Div. 2) A. DZY Loves Chessboard —— dfs
题目链接: http://codeforces.com/problemset/problem/445/A 题解: 这道题是在现场赛的最后一分钟通过的,相当惊险,而且做的过程也很曲折. 先是用递推,结果 ...
- 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内 ...
- [题解]Codeforces Round #254 (Div. 2) B - DZY Loves Chemistry
链接:http://codeforces.com/contest/445/problem/B 描述:n种药品,m个反应关系,按照一定顺序放进试管中.如果当前放入的药品与试管中的药品要反应,危险系数变为 ...
- [题解]Codeforces Round #254 (Div. 2) A - DZY Loves Chessboard
链接:http://codeforces.com/contest/445/problem/A 描述:一个n*m的棋盘,有一些格子不能放棋子.现在把黑白棋子往上放,要求放满且相邻格子的棋子颜色不同.输出 ...
随机推荐
- Coreseek:第二步建索引及測试
1,建索引非常easy.一行代码 g:/service/coreseek/bin/indexer -c g:/service/coreseek/etc/csft_mysql.conf person ...
- LeetCode77:Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 - n. For example, ...
- 用asio的定时器实现带超时的connect,备忘
// test.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <boost/asio.hpp> #inclu ...
- android.graphics包中的一些类的使用
游戏编程相关参考 Matrix学习系列: http://www.moandroid.com/?p=1781 Android画图学习总结系列: http://www.moandroid.com/?p=7 ...
- 编写生成彩色验证码的Servlet
利用Ajax实现无刷新的彩色验证码时,也需要编写一个名称为PictureCheckCode.java的Servlet,该类继承HttpServlet,主要通过service()方法生成验证码. 下面将 ...
- android studio下的NDK开发详解(一)
源地址:http://www.voidcn.com/blog/chengkaizone/article/p-5761016.html 好记性不如烂笔头,开始坚持写博客,学一点记一点,只为了生活更好. ...
- MySQL查看连接数
MySQL查看连接数 1.查看部分连接数(数目较多时) show processlist; 2.查看所有连接数(数目较多时) show full processlist;
- The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar
出现 The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the j ...
- Android中canvas.save()和canvas.restore()的使用
自己定义控件时经常遇到重写View的Ondraw()方法,Ondraw()方法经常设计到save()和restore()这两个方法.这两个相互匹配出现的,作用是用来保存画布的状态和取出保存的状态的. ...
- HttpGet协议与正则表达
使用HttpGet协议与正则表达实现桌面版的糗事百科 写在前面 最近在重温asp.net,找了一本相关的书籍.本书在第一章就讲了,在不使用浏览器的情况下生成一个web请求,获取服务器返回的内容.于 ...