题目链接:http://codeforces.com/contest/872/problem/D

题意:给你一个排列p和对应的位置b也就是说p[b[i]]=i,然后给你最多询问2*n次找出所有的p排列,然后任意输出一个。

题解:其实是一道水题要知道一共n个数询问2*n次也就是说能够询问p[0]^b[i](0<=i<n)和p[i]^b[0](0<=i<n)然后只要给p[0]赋一个值所有的值就都出来了然后就简单了。。

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int ans[][] , p[] , b[] , p_true[] , b_true[];
int main() {
int n;
scanf("%d" , &n);
int x;
for(int i = ; i < n ; i++) {
printf("? %d %d\n" , i , );
fflush(stdout);
scanf("%d" , &x);
ans[i][] = x;
}
for(int i = ; i < n ; i++) {
printf("? %d %d\n" , , i);
fflush(stdout);
scanf("%d" , &x);;
ans[][i] = x;
}
int res = ;
for(int i = ; i < n ; i++) {
memset(p , - , sizeof(p));
memset(b , - , sizeof(b));
p[] = i;
for(int j = ; j < n ; j++) {
b[j] = (ans[][j] ^ p[]);
}
for(int j = ; j < n ; j++) {
p[j] = (ans[j][] ^ b[]);
}
int flag = ;
for(int j = ; j < n ; j++) {
if(p[b[j]] != j || p[j] >= n || b[j] >= n) {
flag = ;
break;
}
}
if(!flag) {
res++;
for(int j = ; j < n ; j++) {
p_true[j] = p[j];
b_true[j] = b[j];
}
}
}
printf("!\n");
printf("%d\n" , res);
for(int i = ; i < n ; i++){
printf("%d " , p_true[i]);
}
printf("\n");
fflush(stdout);
return ;
}

codeforces 872 D. Something with XOR Queries(思维)的更多相关文章

  1. Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) D. Something with XOR Queries

    地址:http://codeforces.com/contest/872/problem/D 题目: D. Something with XOR Queries time limit per test ...

  2. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  3. XOR Queries(莫队+trie)

    题目链接: XOR Queries 给出一个长度为nn的数组CC,回答mm个形式为(L, R, A, B)(L,R,A,B)的询问,含义为存在多少个不同的数组下标k \in [L, R]k∈[L,R] ...

  4. XOR Queries

    XOR Queries 时间限制: 1000ms   内存限制: 256M 描述 给出一个长度为n的数组C,回答m个形式为(L,R,A,B)的询问,含义为存在多少个不同的数组下标k∈[L,R]满足C[ ...

  5. Codeforces 960D Full Binary Tree Queries ( 思维 && 模拟 )

    题意 : 给出一颗无限层的满二叉树,然后每个值为 X (根的 X 等于 1 ) 左孩子的值是 2*X,右孩子的值是 2*X+1 ,现在有两种操作,(1, x,k) 表示将 x 所在层的所有节点整体向右 ...

  6. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

  7. CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries

    https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...

  8. Educational Codeforces Round 5 E. Sum of Remainders (思维题)

    题目链接:http://codeforces.com/problemset/problem/616/E 题意很简单就不说了. 因为n % x = n - n / x * x 所以答案就等于 n * m ...

  9. Codeforces 789A Anastasia and pebbles(数学,思维题)

    A. Anastasia and pebbles time limit per test:1 second memory limit per test:256 megabytes input:stan ...

随机推荐

  1. 章节十五、3-对象仓库、Page Factory实例应用

    一.如何创建对象仓库 package pageclasses; import org.openqa.selenium.WebDriver; import org.openqa.selenium.Web ...

  2. 【iOS】沙盒目录

    有关沙盒目录参考: http://blog.csdn.net/totogo2010/article/details/7669837 获取沙盒路径,参考代码: NSArray *paths = NSSe ...

  3. Java | Map排序,工具类改进

    package util; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; ...

  4. 万万没想到,JVM内存结构的面试题可以问的这么难?

    在我的博客中,之前有很多文章介绍过JVM内存结构,相信很多看多我文章的朋友对这部分知识都有一定的了解了. 那么,请大家尝试着回答一下以下问题: 1.JVM管理的内存结构是怎样的? 2.不同的虚拟机在实 ...

  5. Spring Boot 整合 JPA 使用多个数据源

    介绍 JPA(Java Persistence API)Java 持久化 API,是 Java 持久化的标准规范,Hibernate 是持久化规范的技术实现,而 Spring Data JPA 是在 ...

  6. Spring IoC源码解析之getBean

    一.实例化所有的非懒加载的单实例Bean 从org.springframework.context.support.AbstractApplicationContext#refresh方法开发,进入到 ...

  7. Android OTG之USB转串口模块通讯

    微信公众号:CodingAndroid CSDN:http://blog.csdn.net/xinpengfei521 1.背景简介 我们公司开发了一款室内机平板APP应用,要求平板能去控制智能门锁. ...

  8. 汇总VSCode中比较好用的插件

    使用vscode编辑器两年的时间,总结出前端一些比较方便的插件 1. Auto Close Tag 自动添加HTML / XML关闭标签 2. Auto Complete Tag 自动完成标签 3 A ...

  9. 在linux系统下安装mysql详解,以及远程调用连接不上mysql的解决方法。

    步骤: 1)查看CentOS自带的mysql 输入 rpm -qa | grep mysql 2)将自带的mysql卸载 3)上传Mysql的安装包到linux 4)安装mysql的依赖(不是必须) ...

  10. Unable to load template file 'rj\ThinkPHP/Tpl/dispatch_jump.tpl'----thinkphp3.2.3

    Unable to load template file 'rj\ThinkPHP/Tpl/dispatch_jump.tpl'----thinkphp3.2.3 1.报错原因:将thinkphp默认 ...