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的棋盘,有一些格子不能放棋子.现在把黑白棋子往上放,要求放满且相邻格子的棋子颜色不同.输出 ...
随机推荐
- Sql Server 函数的操作实例!(返回一条Select语句查询后的临时表)
Sql Server 函数的操作实例!(返回一条Select语句查询后的临时表) SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUN ...
- Oracle Patch Bundle Update
一.相关知识介绍 以前只知道有CPU(Critical Patch Update)和PSU(Patch Set Update),不知道还有个Bundle Patch,由于出现了TNS-12531的BU ...
- 机房收费系统总结之4——VB.NET 轻松解决判断文本框、组合框为空问题
纵观机房收费系统,判断文本框.组合框为空问题无非两种情况.第一种:判断窗体中所有文本框.组合框是否为空.第二种:判断一部分文本框.组合框是否为空.下面看看是如何实现这两种情况的. 第一种:判断窗体中所 ...
- JQuery+AJax - 无刷新使用验证码
最终效果: 项目目录: Default.aspx前端代码: <%@ Page Language="C#" AutoEventWireup="true" C ...
- Eclipse + PyDev 无法导入模块
下载后的包,在python IDLE 都可以导入这些模块,但是在Eclipse里面需要我们自己添加路径 需要导入的模块,在那个路径下,就在这里添加路径即可,其他的同理.
- C 语言资源大全中文版
C 语言资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列的资源整理.awesome-c 是 koz.ross 发起维护的 C 语言资源列表,内容包括了: ...
- HDU--杭电--4506--小明系列故事——师兄帮帮忙--快速幂取模
小明系列故事——师兄帮帮忙 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) To ...
- Swift调用Objective-C编写的代码(颜色选择器KKColorListPicker调用)
在Swift项目中,我们可以导入任意用Objective-C写的框架,代码库等.下面以Swift调用Objective-C编写的颜色选择器KKColorListPicker为例. 效果图如下: ...
- “ASP.default_aspx”并不包括“DropDownList1_SelectedIndexChanged”的定义,其解决方法。
"ASP.default_aspx"并不包括"DropDownList1_SelectedIndexChanged"的定义,其解决方法. 在使用DropDown ...
- 14.4.4 Configuring the Memory Allocator for InnoDB InnoDB 配置内存分配器
14.4.4 Configuring the Memory Allocator for InnoDB InnoDB 配置内存分配器 当InnoDB 被开发, 内分配齐 提供了与操作系统和运行库往往缺乏 ...