• 题意:

    构造题,节点1~n顺时针排列成圆形,告诉你每个点度数奇偶性,让你构造一棵树,树边不相交。
  • 思路:

    因为每条边给总度数贡献2,因此如果度数为1的点有奇数个,直接输出no。显然0个度数为1的,也输出no。

    找到每个1,把1往后的部分分到一组,第二组的最后一个连第一组的最后一个,然后3组往后的最后一个连第一组的第一个(1)。
  • code:
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
char s[N];
int a[N];
int main() {
int T;scanf("%d",&T);
while(T--) {
int n;scanf("%d",&n);
scanf("%s",s+1);
int tot=0;
for(int i=1;i<=n;i++) if(s[i]=='1') {a[++tot]=i;}
if(!tot||(tot&1)) {printf("NO\n");continue;}
printf("YES\n");
int lst1=0;
for(int i=1;i<=tot;i++) {
int nxt=a[(i==tot)?1:i+1];
for(int j=a[i];;) {
int k=(j==n)?1:j+1;
if(k==nxt) {
if(i==1) {lst1=j;}
else if(i==2) {printf("%d %d\n",lst1,j);}
else {printf("%d %d\n",a[1],j);}
break;
}
else {printf("%d %d\n",j,k);}
j=k;
}
}
}
return 0;
}

CF1682D Circular Spanning Tree的更多相关文章

  1. Codeforces 1682 D Circular Spanning Tree

    题意 1-n排列,构成一个圆:1-n每个点有个值0或者1,0代表点的度为偶数,1代表点的度为计数:询问能否构成一棵树,树的连边在圆内不会相交,在圆边上可以相交,可以则输出方案. 提示 1. 首先考虑什 ...

  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. Codeforces Edu3 E. Minimum spanning tree for each edge

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

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

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

随机推荐

  1. python爬取京东评论

    一.分析 1.找到京东商品评论所在位置(记得点击商品评论,否则找不到productPageComments.action)  2.解析文件 打开后发现是json数据,但不是那么规范,所以需要去点前面的 ...

  2. java中Error和Exception用法上有什么区别,Error是怎么回事?

    顺便提一句, 和Exception 相对应的,还有Error,Error(错误)表示系统级的错误和程序不必处理的异常,是JRE(java运行环境)的内部错误或者硬件问题,比如,另外 某一处地方的bug ...

  3. JavaScript实现有农历和节气节假日的日历

    运行效果: 源代码: 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content ...

  4. javascript,如何实现数据绑定

    在三大框架 抢占前端开发技术领域的时代,基本每个框架都是实现了数据绑定, 今天我们来解密一下数据绑定的原理, 原理关乎一个很关键的东西,Object.prototype.__defineSetter和 ...

  5. springboot+springsecurity+mybatis plus之用户认证

    一.权限管理的概念 另一个安全框架shiro:shiro之权限管理的描述 导入常用坐标 <dependency> <groupId>org.springframework.bo ...

  6. float,short类型赋值运算问题

    float f = 3.4; 有错吗? 有错,因为浮点类型默认是double类型,double类型赋值给float类型是大类型赋值给小类型需要进行强转,可在3.4前加(float)进行强转,或者在声明 ...

  7. Pinpoint介绍及docker安装方式

    一.介绍 Pinpoint是用Java编写的大型分布式系统的APM(Application Performance Management应用程序性能管理)工具,受Dapper论文的启发,Pinpoin ...

  8. python中一些列表知识

    列表 序列是 Python 中最基本的数据结构. 序列中的每个值都有对应的位置值,称之为索引,第一个索引是 0,第二个索引是 1,依此类推. Python 有 6 个序列的内置类型,但最常见的是列表和 ...

  9. Dapr 能否取代 Spring Cloud?

    很多人都是使用SpringBoot 和 Spring Cloud来开发微服务.Dapr 也是开发微服务的框架,它和Spring Cloud有什么区别呢,其实这不是一个区别的问题,它是不同的时代需要不同 ...

  10. 论文翻译:2020_TinyLSTMs: Efficient Neural Speech Enhancement for Hearing Aids

    论文地址:TinyLSTMs:助听器的高效神经语音增强 音频地址:https://github.com/Bose/efficient-neural-speech-enhancement 引用格式:Fe ...