http://codeforces.com/contest/761/problem/E

给出一颗树,要求在坐标系中用平行于坐标轴的线描绘出来。

要求边不能相交,而且点的坐标唯一。

注意到2^1 + 2^2 + ..... + 2^n = 2^(n + 1) - 1

那就是说,如果第一条边的边长是2^(n + 1),那么后面的边选2^n 、 2^(n -  1)等等,相加起来也不会越过第一条,所以也就不会相交。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = + ;
struct node {
int u, v, tonext;
} e[maxn * ];
int num;
int first[maxn];
void add(int u, int v) {
++num;
e[num].u = u;
e[num].v = v;
e[num].tonext = first[u];
first[u] = num;
}
struct coor {
LL x, y;
coor(LL xx, LL yy) : x(xx), y(yy) {}
bool operator < (const struct coor & rhs) const {
if (x != rhs.x) return x < rhs.x;
else return y < rhs.y;
}
};
vector<struct coor>ans[maxn];
int tonext[][] = {{, }, {, }, {, -}, { -, }};
bool vis[maxn];
const LL one = ;
int haha[];
void dfs(int cur, LL x, LL y, int son, int pre) {
ans[cur].push_back(coor(x, y));
// aler.insert(coor(x, y));
vis[cur] = true;
int to = ;
for (int i = first[cur]; i; i = e[i].tonext) {
int v = e[i].v;
if (vis[v]) continue;
if (to == pre) to++;
if (to == ) to = ;
dfs(v, x + tonext[to][] * (one << son), y + tonext[to][] * (one << son), son - , haha[to]);
to++;
}
}
void work() {
haha[] = ;
haha[] = ;
haha[] = ;
haha[] = ;
int n;
scanf("%d", &n);
for (int i = ; i <= n - ; ++i) {
int u, v;
scanf("%d%d", &u, &v);
add(u, v);
add(v, u);
}
for (int i = ; i <= n; ++i) {
int t = -;
for (int j = first[i]; j; j = e[j].tonext) {
t++;
}
if (t >= ) {
// cout << t << endl;
cout << "NO" << endl;
return;
}
}
// LL y = 1 << 30;
// y <<= 2;
// cout << y << endl;
dfs(, , , , -);
cout << "YES" << endl;
for (int i = ; i <= n; ++i) {
// if (ans[i].size() == 0) {
// cout << i << "ffff" << endl;
// continue;
// }
cout << ans[i][].x << " " << ans[i][].y << endl;
}
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

E. Dasha and Puzzle 数学题的更多相关文章

  1. Codeforces Round #394 (Div. 2) E. Dasha and Puzzle 构造

    E. Dasha and Puzzle 题目连接: http://codeforces.com/contest/761/problem/E Description Dasha decided to h ...

  2. Codeforces Round #394 (Div. 2) E. Dasha and Puzzle

    E. Dasha and Puzzle time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  3. Codeforces Round #394 (Div. 2) E. Dasha and Puzzle(分形)

    E. Dasha and Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. Codeforces 761E Dasha and Puzzle(构造)

    题目链接 Dasha and Puzzle 对于无解的情况:若存在一个点入度大于4,那么直接判断无解. 从根结点出发(假设根结点的深度为0), 深度为0的节点到深度为1的节点的这些边长度为2^30, ...

  5. Codeforces Round #172 (Div. 2) C. Rectangle Puzzle 数学题几何

    C. Rectangle Puzzle Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/281/p ...

  6. Codeforces Round #394 (Div. 2) E. Dasha and Puzzle(dfs)

    http://codeforces.com/contest/761/problem/E 题意:给出一棵树,现在要把这棵树上的结点放置在笛卡尔坐标上,使得每一条边与x轴平行或者与y轴平行.输出可行解,即 ...

  7. 【codeforces 761E】Dasha and Puzzle

    [题目链接]:http://codeforces.com/contest/761/problem/E [题意] 给你一棵树,让你在平面上选定n个坐标; 使得这棵树的连接关系以二维坐标的形式展现出来; ...

  8. CODEFORCES ROUND #761 ANALYSES BY TEAM:RED & BLACK

    A. Dasha and Stairs Problems: 一个按照1,2,3……编号的楼梯,给定踩过的编号为奇数奇数和偶数的楼梯数量a和b,问是否可以有区间[l, r]符合奇数编号有a个,偶数编号有 ...

  9. Codeforces Round #394 (Div. 2) A,B,C,D,E

    A. Dasha and Stairs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. Deepin-文件目录介绍

    请参见这篇文件:来自一个强大的网站 我主要介绍的就是: 下面所列文件,全部添加进了path目录(Linux查找命令,请参见man.linux,无论是find 或者是 which等) Deepin默认可 ...

  2. 解决cell切割线不是全屏问题

    if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) { [_tableView setSeparatorInset:U ...

  3. 使用python在极坐标中生成一条直线

    在测试雷达时,往往需要测试雷达的数据是否准确,这时就需要在雷达图中显示一条标准的直线作为对比. "create a wall" import numpy as np import ...

  4. A + B Problem II(杭电1002)

    /*A + B Problem II Problem Description I have a very simple problem for you. Given two integers A an ...

  5. PHP中常见的header类型

    <?php // 使用 mime_content_type() 查看 $mimetypes=array( 'ez' => 'application/andrew-inset', 'hqx' ...

  6. 发挥bat的作用

    from 转自:http://blog.csdn.net/hitlion2008/article/details/7467252 1.什么是Windows BATCH BATCH也就是批处理文件,有时 ...

  7. linear map (also called a linear mapping, linear transformation or, in some contexts, linear function

    Linear map - Wikipedia https://en.wikipedia.org/wiki/Linear_map

  8. Synthesizing Images of Humans in Unseen Poses

    Synthesizing Images of Humans in Unseen Poses balakg/posewarp-cvpr2018 https://github.com/balakg/pos ...

  9. mysql连接com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link

    jdbc驱动:mysql-connector-java-5.1.39-bin.jar 这个有问题, 换成:mysql-connector-java-5.1.34.jar 就可以了

  10. [Usaco2013 DEC] Vacation Planning

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=4093 [算法] 对于k个枢纽 , 分别在正向图和反向图上跑dijkstra最短路 , ...