• 题意:

    构造题,节点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. Issues with position fixed & scroll(移动端 fixed 和 scroll 问题)

    转载请注明英文原文及译文出处 原文地址:Issues with position fixed & scrolling on iOS 原文作者:Remy Sharp译文地址:移动端 fixed ...

  2. java继承时能包括静态的变量和方法吗?举例说明!

    子类继承了超类定义的所有实例变量和方法包括静态的变量和方法(马克-to-win见下例),并且为它自己增添了独特的元素.子类只能有一个超类.Java不支持多超类的继承. 子类拥有超类的所有成员,但它不能 ...

  3. DB2表数据导出、导入及常用sql使用总结

      一.DB2数据的导出: export to [path(例:D:"TABLE1.ixf)]of ixf select [字段(例: * or col1,col2,col3)] from ...

  4. 实现一个promise.all方法

    思路: 1:首先明白all的用法 2:promise.all可以接受一个由promise数组作为参数,并且返回一个promise实例, 3:promise.all([a,b,c...]).then方法 ...

  5. 关键字static、extern、volatile、详解及举例

    一.预备知识 1. 什么是局部变量?什么是全局变量?          所谓局部变量,就是指在函数内部定义的变量的,只在该函数范围内有效. 全局变量是指,在函数外部定义的变量为外部变量,即全局变量.它 ...

  6. JAVASE for 笔记

    //0到100中奇数偶数的和package com.huang.boke.flowPath;public class Fordeme { public static void main(String[ ...

  7. MFC---典型类和函数

    在MFC中,典型的类有CString.CRect.CDialog等,这些类的使用方法是通用的,下文以CString类的使用为例做一个详细说明.类的使用主要还是使用类的方法,可以查看类的定义,查看这个类 ...

  8. Asynchronous Methods for Deep Reinforcement Learning

    郑重声明:原文参见标题,如有侵权,请联系作者,将会撤销发布! ICML 2016 Abstract 我们提出了一个概念上简单且轻量级的深度强化学习框架,该框架使用异步梯度下降来优化深度神经网络控制器. ...

  9. 介绍关于MSSQL当前行中获取到上一行某列值的函数 Coalesce

    记录一个小知识点,在SQLGrid中,在当前行显示上一行某列值的函数** Coalesce **的使用. 显示上一行是有啥子用? 经常有人百度SQL上一行减下一行的写法,但是没几个文章是用最简单直接的 ...

  10. git 将本地文件推送到远程分支的分支

    1.  新建文件夹复制远程分支 2. 切换到远程分支 3. 推送到远程 添加到暂存区,先运行 " git add . " 查看文件状态                     在运 ...