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. 是男人就下100层【第四层】——Crazy贪吃蛇(2)

    在上一篇<是男人就下100层[第四层]--Crazy贪吃蛇(1)>中我们让贪吃蛇移动了起来,接下来我们来实现让贪吃蛇能够绕着手机屏幕边线移动而且能够改变方向 一.加入状态并改动代码 首先我 ...

  2. Qt移动应用开发(四):应用粒子特效

    Qt移动应用开发(四):应用粒子特效 上一篇文章介绍了Qt Quick是如何对帧动画进行支持的.帧动画的实现离不开状态机.而状态机.动画和状态切换(transitions)则是Qt框架的核心内容.也就 ...

  3. cocos2d-x CCSrollView 源代码,可循环的SrollView代码

    项目须要.写一个类似于iPhone上面时钟选择的可拉动式循环选择列表,通过集成CCScrollView并更改部分代码.实现了该功能. 假设想充分了解代码,请先阅读源码分析http://blog.csd ...

  4. C++手稿:std::string

    字符串在非常多编程语言中已经成为基本数据类型,C语言中我们使用char*来手动申请和维护字符串, 在C++中,能够使用std::string来方便地创建和操作字符串. string是一个模板类.它有b ...

  5. my-small.cnf my-medium.cnf my-large.cnf my-huge.cnf

    my-small.cnf my-medium.cnf my-large.cnf my-huge.cnf 是 MySQL 默认的几个配置文件.针对不同配置的服务器可以使用不同的配置文件,将你需要的那一个 ...

  6. e3 cpu

    英特尔® 至强® E3 处理器 https://www.intel.cn/content/www/cn/zh/products/processors/xeon/e3-processors.html?p ...

  7. h5ai目录列表优化

    h5ai是HTTP Web服务器的现代文件索引器,专注于您的文件.目录以有吸引力的方式显示,浏览它们通过不同的视图,面包屑和树状概述增强.最初,h5ai是HTML5 Apache Index的缩写,但 ...

  8. 谈谈对redux的认识

    redux是从flux演变而来,但又独立于react.简言之就是,redux是一种单纯的状态管理器.可以和react搭配,也可以和其它框架搭配. redux有三个重要的部分组成: store, act ...

  9. bootstrap3.0学习笔记记录1

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. HAProxy+Keepalived构建高可用负载均衡

    http://www.linuxidc.com/Linux/2012-03/55880.htm web1 IP 192.168.0.47 web2 IP 192.168.0.48 haproxy_ma ...