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& ...
随机推荐
- SpringCloud的应用发布(一)SpringCloud的样例工程
前言 这个综合例子创建了 6个微服务应用 一个服务注册中心 SvcReg(EurekaServer),生产中要考虑高可用 一个配置中心 CfgMgr + git目录存储配置(ConfigServer, ...
- GIT入门笔记(18)- 标签创建和管理
git tag <name>用于新建一个标签,默认为HEAD,也可以指定一个commit id: git tag -a <tagname> -m "blablabla ...
- GIT入门笔记(6)- 向版本库添加文本文件
1.把文本文件添加到版本库? 所有的版本控制系统,其实只能跟踪文本文件的改动,比如TXT文件,网页,所有的程序代码等等,Git也不例外. 版本控制系统可以告诉你每次的改动,比如在第5行加了一个单词&q ...
- 剑指offer-二叉树的下一个节点
题目描述 给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回.注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针. 解题思路 分情况考虑如下: 若该节点为空,则直 ...
- 已操作文件的方式,新建一个用户alex
- flask 操作mysql的两种方式-sql操作
flask 操作mysql的两种方式-sql操作 一.用常规的sql语句操作 # coding=utf-8 # model.py import MySQLdb def get_conn(): conn ...
- 微信小程序:模板消息推送提示{“errcode”:41030,”errmsg”:”invalid page hint: [gP1eXXXXXX]”}
在开发小程序 模板消息定时推送功能时,在开发版测试程序功能运行正常,但提交到线上后提示报错{“errcode”:41030,”errmsg”:”invalid page hint: [gP1eXXXX ...
- JavaScript数据结构与算法(四) 循环队列的实现
实现击鼓传花,需要用到上一章所述队列类Queue TypeScript方式实现源码 let hotPotato = (nameList, num) => { let queue = new Qu ...
- Temple Build~dp(01背包的变形)
The Dwarves of Middle Earth are renowned for their delving and smithy ability, but they are also mas ...
- 【django之modelform】
一.什么是modelform ModelForm顾名思义就Form和Django的Model数据库模型结合体,可以简单.方便得对数据库进行增加.编辑操作和验证标签的生成: 举例说明: 比如我们的数据库 ...