CF745 D 交互题 思维 二进制分解

现有一矩阵
你可以做出不超过20个询问 每个询问 要求输入列号,可以询问矩阵上每行上你给的列之中的最小值
让你最后输出该矩阵每行的不包括对角线位置上的最小值
考虑询问如何分组,考虑二分,以二进制位来分组 那么最多不超过2log(n)次询问就能通过比较得到每行的最小值
注意这里的最重要的问题是如何排除对角线,在比较最小值时,如果当前的行号是对角线上且被包括在当前组中 则抛弃该组结果

#include <bits/stdc++.h>
using namespace std;

int n;
int a[1010];
int mi[1010];
int main()
{
	memset(mi, 0x3f, sizeof(mi));
	scanf("%d", &n);
	int f = 0;
	int x = 0;
	while((1 << x) <= n)
	{
		int cnt = 0;
		for(int i = 1; i <= n; i++)
			if( ((i >> x) & 1) == f)
				cnt++;
		if(!cnt)
			continue;
		printf("%d\n", cnt);
		for(int i = 1; i <= n; i++)
			if(((i >> x) & 1) == f)
				printf("%d ", i);
		printf("\n");
		fflush(stdout);
		for(int i = 1; i <= n; i++)
		{
			int t;
			scanf("%d", &t);
			if(((i >> x) & 1) != f)
				mi[i] = min(mi[i], t);
		}
		f^=1;
		if(f == 0)
			x++;
	}
	printf("-1\n");
	for(int i = 1; i <= n; i++)
		printf("%d%s", mi[i], i==n?"\n":" ");
	fflush(stdout);

}
时间: 2024-08-09 19:47:13

CF745 D 交互题 思维 二进制分解的相关文章

Codeforces 1137D - Cooperative Game - [交互题+思维题]

题目链接:https://codeforces.com/contest/1137/problem/D 题意: 交互题. 给定如下一个有向图: 现在十个人各有一枚棋子(编号 $0 \sim 9$),在不知道 $t,c$ 的值的情况下,他们同时从home出发,要最终到达flag处. 你只能选择移动哪几个人的棋子,但棋子移动到哪里由程序确定并给出. 题解: 看网上大佬一个神仙解法……看得我一愣一愣的…… 选定两颗棋子,第一颗每次都移动,第二颗隔一次移动一次.所以,进行了 $2t$ 次之后第二颗棋子刚好

hdoj 2191 悼念512。。 【多重背包】+【二进制分解】

话说题目真长... 题意: 中文题,你懂得.. 策略:多重背包问题.多重背包转换成 01 背包问题就是多了个初始化,把它的件数C 用2的次幂分解成若干个件数的集合,这里面数字可以组合成任意小于等于C的件数,而且不会重复,之所以叫二进制分解,是因为这样分解可 以用数字的二进制形式来解释     比如:7的二进制 7 = 111 它可以分解成 001 010 100 这三个数可以 组合成任意小于等于7 的数,而且每种组合都会得到不同的数.     15 = 1111 可分解成 0001  0010 

POJ 1014 / HDU 1059 Dividing 多重背包+二进制分解

Problem Description Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they could

CF 714D Searching Rectangles 交互题 二分

题意:交互题,已知一个n*n的地图,电脑藏了两个不相交的矩形(矩形的边和坐标轴平行).每次向电脑询问左下[x1,y1]右上[x2,y2]的矩形内完全包含多少个藏着的矩形.n<=2^16.请在200次内猜出两个矩形左下,右上坐标. 先二分出两个不相交矩形的分界线,要么横着要么竖着.接在在每一快中二分出矩形的四条边即可(最左,右,上,下边界) #include <bits/stdc++.h> using namespace std; int n,ans[20],cnt=0; inline i

Moscow Subregional 2010 Problem K. KMC Attacks 交互题、队列优化、枚举

ACM ICPC 2010-2011 NEERC Moscow Subregional Contest Moscow, October 24, 2010 Problem K. KMC Attacks Time limit: 2 seconds Memory limit: 256 megabytes Warrant VI is a remote planet located in the Koprulu Sector. Warrant VI features a strange huge fiel

Gym - 101375H MaratonIME gets candies 交互题

交互题介绍:https://loj.ac/problem/6 题意:输出Q X ,读入><= 来猜数,小于50步猜出就算过样例 题解:根本不需要每次输出要打cout.flush()... ac: #include<iostream> #include<string> using namespace std; int main() { int l = 1, r = 1e9; while (l <= r) { int mid = (l + r) / 2; cout &

Codeforces Round #504 E - Down or Right 交互题

1023E 题意: 交互题.在一个有障碍地图中,问如何走才能从(1,1)走到(n,n),只能向右或者向左走.每次询问两个点,回复你这两个点能不能走通. 思路: 只用最多2*n-2次询问.从(1,1),能向右走就向右走,不能就向下走,直到走到斜对角线上.从(n,n)出发,能向上走就向上走,不能就向左走,直到走到斜对角线上. 因为保证有路,所以最后输出(1,1)出发的正向路径,加上从(n,n)出发的反向路径. #include <algorithm> #include <iterator&g

codeforces679A_Bear and Prime 100 交互题

传送门 第一道交互题 题意: 电脑事先想好了一个数[2,100] 你会每次问电脑一个数是否是它想的那个数的因数 电脑会告诉你yes或no 至多询问20次 最后要输出它想的数是质数还是合数 思路: 枚举<50的质数和4,9,25,49即可判断 4,9, 25,49单独看作质数是这样方便判断2^2,3^2,...,9^2 解释: 在使用多个输出函数连续进行多次输出时,有可能发现输出错误. 因为下一个数据再上一个数据还没输出完毕,还在输出缓冲区中时,下一个printf就把另一个数据加入输出缓冲区, 结

2019雅礼集训 D10T2 硬币翻转 [交互题]

题目描述: coin.h: #include<string> void guess(); int ask(std::string coin); grader.cpp: #include "coin.h" #include <iostream> #include <assert.h> using namespace std; namespace U { using u64 = unsigned long long; using i64 = long l