题目链接

\(Description\)

一个\(n\times n\)的非负整数矩阵\(A\),保证\(A_{i,i}=0\)。现在你要对每个\(i\)求\(\min_{j\neq i}A_{i,j}\)(每一行除\(A_{i,i}\)的最小值)。你可以进行不超过\(20\)次询问,每次询问你给出下标集合\(\{w_1,w_2,\ldots,w_k\}\),交互库会对每个\(i\)返回\(\min_{j=1}^kA_{i,w_j}\)(每一行给出列的最小值)。

\(n\leq 1000,A_i\leq 10^9\)。

\(Solution\)

常见思路:\(i\neq j\)即\(i,j\)至少有一位不同。

对每一位枚举\(0/1\),求所有下标该位为\(0/1\)的最小值。对于每个\(i\)把与其某位不同的数全部取\(\min\)即可。

#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
const int N=1005; int n,A[N][13][2],tag[N]; inline int read()
{
int now=0;register char c=gc();
for(;!isdigit(c);c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now;
}
int Query(int s,int bit)
{
int t=0;
for(int i=1; i<=n; ++i) if(tag[i]==s) ++t;
printf("%d\n",t);
for(int i=1; i<=n; ++i) if(tag[i]==s) printf("%d ",i);
putchar('\n'); fflush(stdout);
for(int i=1; i<=n; ++i) A[i][bit][s]=read();
} int main()
{
n=read();
for(int i=0; 1<<i<=n; ++i)//从0啊→_→
{
for(int j=1; j<=n; ++j) if(j>>i&1) tag[j]=1;
Query(0,i), Query(1,i);
for(int j=1; j<=n; ++j) tag[j]=0;
}
puts("-1");//看格式→_→先-1,输出到一行
for(int i=1; i<=n; ++i)
{
int ans=1e9;
for(int bit=0; 1<<bit<=n; ++bit)
ans=std::min(ans,A[i][bit][(i>>bit&1)^1]);
printf("%d ",ans);
}
fflush(stdout); return 0;
}

Codeforces.744B.Hongcow's Game(交互 按位统计)的更多相关文章

  1. Codeforces.835E.The penguin's game(交互 按位统计 二分)

    题目链接 \(Description\) 有一个长为\(n\)的序列,其中有两个元素为\(y\),其余全为\(x\).你可以进行\(19\)次询问,每次询问你给出一个下标集合,交互库会返回这些元素的异 ...

  2. 牛客国庆集训派对Day4.B.异或求和(按位统计)

    题目链接 刷牛客一战到底做到的,感觉还挺有趣... \(Description\) 求给定\(n\)及序列\(A_i\),求\[\sum_{i\lt j\lt k}(A_i\oplus A_j)(A_ ...

  3. codeforces766E Mahmoud and a xor trip(按位统计+树形DP)

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  4. poj 3105 Expectation 按位统计

    题意: 给n,求sum(i^j)/(n^2),0<=i,j<n.n<10^9 分析: 暴力n^2算法肯定超时.这是logn按位统计算法:按位先算出0出现的个数x,则1出现的个数为n- ...

  5. Codeforces 242E:XOR on Segment(位上的线段树)

    http://codeforces.com/problemset/problem/242/E 题意:给出初始n个数,还有m个操作,操作一种是区间求和,一种是区间xor x. 思路:昨天比赛出的一道类似 ...

  6. Codeforces Round #626 Div2 D. Present(位掩码,二分)

    题目链接:https://codeforces.com/contest/1323/problem/D 题意:给了大小为4e5的数组a,其中1<=ai<=1e7.求所有点对和的异或和,即: ...

  7. codeforces 744C Hongcow Buys a Deck of Cards

    C. Hongcow Buys a Deck of Cards time limit per test 2 seconds memory limit per test 256 megabytes in ...

  8. codeforces 558/C Amr and Chemistry(数论+位运算)

    题目链接:http://codeforces.com/problemset/problem/558/C 题意:把n个数变成相同所需要走的最小的步数易得到结论,两个奇数不同,一直×2不可能有重叠枚举每个 ...

  9. Codeforces 744C Hongcow Buys a Deck of Cards 状压dp (看题解)

    Hongcow Buys a Deck of Cards 啊啊啊, 为什么我连这种垃圾dp都写不出来.. 不是应该10分钟就该秒掉的题吗.. 从dp想到暴力然后gg, 没有想到把省下的红色开成一维. ...

随机推荐

  1. angularJs实现动态增加输入框

    摘要:首先,有一个这样的需求,就是说,我点击添加,会动态出现需要输入的输入框.我们需要定义一个对象,类似这种, {spc:{},spctions:[]} 意思是spc对应的是一个对象,spctions ...

  2. 阿里云ECS使用cloudfs4oss挂载OSS

    cloudfs4oss可以帮我们将OSS直接挂载到ECS上,就像一个目录一样方便访问.使用方法: 1.安装配置环境: yum install libcurl libcurl-devel openssl ...

  3. JMS学习(二)之ActiveMQ

    1,ActiveMQ是Apache实现的基于JMS的一个消息服务器.下面记录ActiveMQ的一些基本知识. 2,ActiveMQ connectors:ActiveMQ providesconnec ...

  4. ReactJS -- 初学入门

    <!DOCTYPE html> <html> <head> <script src="build/react.js"></sc ...

  5. 第9月第13天 传递lua匿名函数到c/c++

    1. lua函数都在refid_fun refid_fun[refid] = fun TOLUA_API int toluafix_ref_function(lua_State* L, int lo, ...

  6. requests下载文件并重新上传

    import re import requests from io import BytesIO from django.core.files.uploadedfile import InMemory ...

  7. F. Ivan and Burgers(线性基,离线)

    题目链接:http://codeforces.com/contest/1100/problem/F 题目大意:首先输入n,代表当前有n个数,然后再输入m,代表m次询问,每一次询问是询问区间[l,r], ...

  8. Qt 数字和字符处理总结

    1. 四舍五入保留小数几位 QString str="12.3456789"; double d1=str.toDouble(); qDebug()<<"d1 ...

  9. Java8系列之重新认识HashMap

    转自:  http://www.importnew.com/20386.html   简介 Java为数据结构中的映射定义了一个接口java.util.Map,此接口主要有四个常用的实现类,分别是Ha ...

  10. python抓取内涵段子文章

    # coding:utf-8 from urllib.request import urlretrieve import threading import requests from bs4 impo ...