codeforces 872 D. Something with XOR Queries(思维)
题目链接: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(思维)的更多相关文章
- 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 ...
- Codeforces Round #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
- XOR Queries(莫队+trie)
题目链接: XOR Queries 给出一个长度为nn的数组CC,回答mm个形式为(L, R, A, B)(L,R,A,B)的询问,含义为存在多少个不同的数组下标k \in [L, R]k∈[L,R] ...
- XOR Queries
XOR Queries 时间限制: 1000ms 内存限制: 256M 描述 给出一个长度为n的数组C,回答m个形式为(L,R,A,B)的询问,含义为存在多少个不同的数组下标k∈[L,R]满足C[ ...
- Codeforces 960D Full Binary Tree Queries ( 思维 && 模拟 )
题意 : 给出一颗无限层的满二叉树,然后每个值为 X (根的 X 等于 1 ) 左孩子的值是 2*X,右孩子的值是 2*X+1 ,现在有两种操作,(1, x,k) 表示将 x 所在层的所有节点整体向右 ...
- codeforces 349B Color the Fence 贪心,思维
1.codeforces 349B Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...
- 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] 表示第 ...
- Educational Codeforces Round 5 E. Sum of Remainders (思维题)
题目链接:http://codeforces.com/problemset/problem/616/E 题意很简单就不说了. 因为n % x = n - n / x * x 所以答案就等于 n * m ...
- Codeforces 789A Anastasia and pebbles(数学,思维题)
A. Anastasia and pebbles time limit per test:1 second memory limit per test:256 megabytes input:stan ...
随机推荐
- Linux平台 Oracle 19c RAC安装Part2:GI配置
三.GI(Grid Infrastructure)安装 3.1 解压GI的安装包 3.2 安装配置Xmanager软件 3.3 共享存储LUN的赋权 3.4 使用Xmanager图形化界面配置GI 3 ...
- 【iOS】The identity used sign the executable is no longer valid.
之前就遇到过这个问题,如图: 今天又遇到了,证书过期的问题. 需要访问苹果开发者的官网 http://developer.apple.com 来解决. 参考:How to fix “The ident ...
- 使用vsftp与shell实现对进程与服务状态的监控
先说一下需求吧,公司开发了一款新的产品,新产品嘛,有着不得不出问题的理由,四个云机房,总共三百余台机器,需要实时的监控进程状态,虽然有zabbix来实现,但领导需求是脚本和zabbix一起做,zabb ...
- light oj 1159 - Batman LCS
学过简单动态规划的人应该对最长公共子序列的问题很熟悉了,这道题只不过多加了一条字符串变成三条了,还记得,只要把状态变成三维的即可. //http://lightoj.com/volume_showpr ...
- Java学习多线程第一天
内容介绍 Thread 线程创建 线程池 线程状态图 1 多线程 1.1 多线程介绍 学习多线程之前,我们先要了解几个关于多线程有关的概念. 进程:进程指正在运行的程序.确切的来说,当一个程序 ...
- ns3 802.11b PHY model
I use the ubuntu and do not install the chinse input. The Code: c file requires gnu gsl library, it ...
- kafka消息的处理机制(五)
这一篇我们不在是探讨kafka的使用,前面几篇基本讲解了工作中的使用方式,基本api的使用还需要更深入的去钻研,多使用才会有提高.今天主要是探讨一下kafka的消息复制以及消息处理机制. 1. bro ...
- ccf 201903-5 317号子任务(60分)
看到这题,第一印象,用dijkstra算法求n次单源最短路,时间复杂度O(n^3),超时30分妥妥的. 于是用优先队列优化,O(n*mlogm),快很多,但依然30. 那么不妨换一种思路,题目要求的是 ...
- 洛谷 P2158 [SDOI2008]仪仗队
题意简述 给定一个n,求gcd(x, y) = 1(x, y <= n)的(x, y)个数 题解思路 欧拉函数, 则gcd(x, y) = 1(x <= y <= n)的个数 ans ...
- laya 下以光标为中心缩放对象
private MouseWheel(e: Laya.Event) { console.log("event"); let currentSp = e.target as Laya ...