题意:给定标号从1到n的n个点,链接两个点x,y的代价为x AND y,求最小生成树总代价与满足代价最小的前提下字典序最小的方案

n<=2e5

思路:

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
#define N 4100
#define M 4100000
#define fi first
#define se second
#define MP make_pair
#define pi acos(-1)
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define ls p<<1
#define rs p<<1|1 const ll MOD=,inv2=(MOD+)/;
double eps=1e-;
int INF=1e9; int read()
{
int v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} int check(int x)
{
int t=x&(-x);
if(t==x) return ;
return ;
} int main()
{
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
int cas=read();
int mx=(<<)-;
while(cas--)
{
int n=read();
if(check(n+))
{
printf("1\n");
rep(i,,n-)
{
int t=i^mx;
//printf("t=%d\n",t);
t=lowbit(t);
//printf("lowbit=%d\n",t);
printf("%d ",t);
}
printf("1\n");
}
else
{
printf("0\n");
rep(i,,n)
{
int t=i^mx;
t=lowbit(t);
if(i<n) printf("%d ",t);
else printf("%d",t);
}
printf("\n");
}
}
return ;
}

【HDOJ6614】AND Minimum Spanning Tree(签到)的更多相关文章

  1. hdu多校第四场1001 (hdu6614) AND Minimum Spanning Tree 签到

    题意: 一个完全图,某两点边权为这两点编号之按位与,求最小生成树,输出字典序最小的. 题解: 如果点数不为$2^n-1$,则每一点均可找到一点,两点之间边权为0,只需找到该点二进制下其最左边的0是第几 ...

  2. 【HDU 4408】Minimum Spanning Tree(最小生成树计数)

    Problem Description XXX is very interested in algorithm. After learning the Prim algorithm and Krusk ...

  3. 数据结构与算法分析–Minimum Spanning Tree(最小生成树)

    给定一个无向图,如果他的某个子图中,任意两个顶点都能互相连通并且是一棵树,那么这棵树就叫做生成树(spanning tree). 如果边上有权值,那么使得边权和最小的生成树叫做最小生成树(MST,Mi ...

  4. Educational Codeforces Round 3 E. Minimum spanning tree for each edge LCA/(树链剖分+数据结构) + MST

    E. Minimum spanning tree for each edge   Connected undirected weighted graph without self-loops and ...

  5. CF# Educational Codeforces Round 3 E. Minimum spanning tree for each edge

    E. Minimum spanning tree for each edge time limit per test 2 seconds memory limit per test 256 megab ...

  6. Codeforces Educational Codeforces Round 3 E. Minimum spanning tree for each edge LCA链上最大值

    E. Minimum spanning tree for each edge 题目连接: http://www.codeforces.com/contest/609/problem/E Descrip ...

  7. MST(Kruskal’s Minimum Spanning Tree Algorithm)

    You may refer to the main idea of MST in graph theory. http://en.wikipedia.org/wiki/Minimum_spanning ...

  8. HDU 4408 Minimum Spanning Tree 最小生成树计数

    Minimum Spanning Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  9. [Educational Round 3][Codeforces 609E. Minimum spanning tree for each edge]

    这题本来是想放在educational round 3的题解里的,但觉得很有意思就单独拿出来写了 题目链接:609E - Minimum spanning tree for each edge 题目大 ...

  10. Educational Codeforces Round 3 E. Minimum spanning tree for each edge 最小生成树+树链剖分+线段树

    E. Minimum spanning tree for each edge time limit per test 2 seconds memory limit per test 256 megab ...

随机推荐

  1. 测开之路一百零六:bootstrap布局

    可以在html的head里面加一些说明 <meta http-equiv="X-UA-Compatible" content="IE=edge">& ...

  2. python实现excel转换成pdf

    1.安装 需要安装pywin32包,以实现对Office文件的操作,可以批量转换为pdf文件.支持 doc, docx, ppt, pptx, xls, xlsx 等格式. pip install p ...

  3. 简单DP入门(一) 数字三角形

    数字三角形

  4. mssql中quotename的作用

    quotename是保证字符原样输入到mssql中 eg: select * from '+QUOTENAME(@tbname) 用于所传字符为mssql保留字样

  5. gdi+ 中发生一般性错误

    1.检查文件夹权限 2.保存的文件已存在并因某种原因被锁定. 3.文件夹路径不存在

  6. xmake新增智能代码扫描编译模式

    最近给xmake增加了一个新特性,对于一份工程源码,可以不用编写makefile,也不用编写各种make相关的工程描述文件(例如:xmake.lua,makefile.am, cmakelist.tx ...

  7. Python学习-第三天-面向对象编程基础

    Python学习-第三天-面向对象编程基础 类和对象 简单的说,类是对象的蓝图和模板,而对象是类的实例.这个解释虽然有点像用概念在解释概念,但是从这句话我们至少可以看出,类是抽象的概念,而对象是具体的 ...

  8. D Makoto and a Blackboard

    Makoto and a Blackboard time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  9. char 指针如何判断字符串需要输出长度

    先上代码: #include <stdio.h> #include <string.h> ] = "; int func1(const char *ip) { pri ...

  10. mybatis-plus&springboot

    ** 问题1:mybatis 读取不到 mapper映射文件. 如下: ** 如果引用 mybatis-plus 包 <dependency> <groupId>com.bao ...