IOI2016Day2. Messy
题目链接:http://uoj.ac/problem/239
题目大意:
这是一道交互题,交互库维护了一个数据结构,可以存储n为二进制串,一开始你可以向空的数据结构中插入若干二进制串,
接下来这个数据结构会将其中存储的二进制串进行改变。
改变的方法是生成一个0到n-1的排列pi,将原来的二进制串a0a1a2..an-1变成ap0ap1..apn-1。
接着你可以进行询问,每次询问一个串是否在这个数据结构当中,要求你在不超过w次插入和r次询问中求出排列p
分析:读完题后看看数据范围,w=r=896=128*7=nlog^2(n),提示我们用分治算法
加数:
我们需要在开始一次性把所有数加完。
考虑加哪些数?结合分治,我们把l,r分为(l,mid)(mid+1,r)如果我们把左边的数加入库中,分治时如果我们找到一个数在出现
就说明他是在(l,mid)范围内,否则在(mid+1,r)中,可以完成分治。
对于这个操作我们具体讲讲:根据上面所说,我们只对(l,mid)进行操作,枚举i(l<=i<=mid)我们使(l,i-1)(i+1,mid)为0,其他位置
都为1,把他们都加入库中,这样我们每一层1的个数都不同,所以所有数加入过后不会影响最后分治。
查找 :
我们对(0,n-1)进行分治,每次可以判断一个位置上的数在哪个区间,一直递归到底层可得最后答案。
附上交互代码 :
#include<bits/stdc++.h>
#include "messy.h"
using namespace std;
const int N=;
int ans[N],used[N],len;
inline void add(int l,int r)
{
if(l>=r) return ;
string str="";
for(int i=;i<len;i++) str+='';
for(int i=;i<l;i++) str[i]='';
for(int i=r+;i<len;i++) str[i]=''; int mid=(l+r)>>;
for(int i=l;i<=mid;i++)
{
str[i]='';
add_element(str);
str[i]='';
}
add(l,mid);add(mid+,r);
} int temp[N]; inline void solve(int l,int r)
{
if(l>=r) return ;
string str="";
for(int i=;i<len;i++) str+='';
for(int i=;i<l;i++) str[ans[i]]='';
for(int i=r+;i<len;i++) str[ans[i]]='';
int cnt1=,cnt2=,mid=(l+r)>>;
for(int i=l;i<=r;i++)
{
int o=ans[i];
str[o]='';
if(check_element(str))
{
cnt1++;
temp[l+cnt1-]=ans[i];
}
else
{
cnt2++;
temp[mid+cnt2]=ans[i];
}
str[o]='';
}
for(int i=l;i<=r;i++) ans[i]=temp[i];
solve(l,mid);solve(mid+,r);
} vector<int> cnt;
vector<int> restore_permutation(int n, int w, int r)
{
len=n; memset(used,,sizeof(used));
add(,len-);
compile_set();
for(int i=;i<len;i++) ans[i]=i; solve(,len-);
for(int i=;i<len;i++) temp[ans[i]]=i;
for(int i=;i<len;i++) cnt.push_back(temp[i]);
return cnt;
}
转载请声明!!!
IOI2016Day2. Messy的更多相关文章
- Messy Code in Windows Server 2008 R2 English Edition
We always use Windows Server 2008 R2 English operation system. And it doesn't have any problem ...
- the solution about "messy code" in elicpse
I use the Elicpse IDE to develope the ansdroid app.Sometime encounter the messy code in the Elicpse ...
- Chinese Messy Code of String
It's very strange that I found the messy code.I 've never seen this before. this is the java code: / ...
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C. Messy 构造
C. Messy You are fed up with your messy room, so you decided to clean it up. Your room is a bracket ...
- .net 中文显示乱码问题(Chinese display with messy code)
Case:同样的代码,本地开发环境(local is Chinese Simplify)可以成功运行,但是放到Windows Server 2008 R2(Local is United State) ...
- BNU OJ 50998 BQG's Messy Code
#include <cstdio> #define _(l) int l #define ___(l,L) for (_(o)=0,x=l o*2;o<x;o++)O= L o; # ...
- IOI2016Day2. paint
题目链接:http://uoj.ac/problem/238 题目大意: 有一个长度为n的黑白序列,告诉你所以k个极长连续黑段长度和顺序.有一些位置的颜色已知,需要判断剩下未知的位置哪些颜色 一定是白 ...
- IS Kali: installed chiess messy code problem
apt-get install ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy init 6
- CF1227C Messy
思路: 构造题.首先把字符串变成“(((((...)))))”的样子,再根据k的取值变成“()()()...((...))”的样子即可. 实现: #include <bits/stdc++.h& ...
随机推荐
- GIT入门笔记(13)- GUI GIT
- 用UIWebView加载本地图片和gif图
加载gif图: NSData *gif = [NSData dataWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@" ...
- git初试
在gitLab上新建一个项目,creat项目文件之后,进入到项目的路径之后,复制命令git clone ‘git@gitlab.touzila.com:xiacaixiang/gitgitTest1. ...
- Spring学习(1)——快速入门
认识 Spring 框架 Spring 框架是 Java 应用最广的框架,它的成功来源于理念,而不是技术本身,它的理念包括 IoC (Inversion of Control,控制反转) 和 AOP( ...
- webpack全局安装
具体项目中才能使用webpack命令: npm install webpack -g npm install webpack-dev-server -g
- NLog日志管理工具(转)
一.通过VS建立一个控制台应用程序. 二.打开程序包管理器控制台.具体操作如下:[工具]>[库程序包管理器]>[程序包管理器控制台]. 三.在程序包管理器控制台下输入命令:Install- ...
- Docker配置加速器
我们国内使用官方Docker Hub仓库实在是太慢了,很影响效率 使用命令编辑文件: vim /etc/docker/daemon.json 加入下面的数据: docker-cn镜像: { " ...
- [LeetCode] Maximum Average Subarray I 子数组的最大平均值
Given an array consisting of n integers, find the contiguous subarray of given length k that has the ...
- [NOI 2016]区间
Description 在数轴上有 $n$ 个闭区间 $[l_1,r_1],[l_2,r_2],...,[l_n,r_n]$.现在要从中选出 $m$ 个区间,使得这 $m$ 个区间共同包含至少一个位置 ...
- [SCOI2010]幸运数字
题目描述 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的“幸运号码”是十进制表示中只包含数字6和8的那些号码,比如68,666,888都是“幸运号码”!但是这种“幸运 ...