E. Dasha and Puzzle 数学题
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 数学题的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- Codeforces 761E Dasha and Puzzle(构造)
题目链接 Dasha and Puzzle 对于无解的情况:若存在一个点入度大于4,那么直接判断无解. 从根结点出发(假设根结点的深度为0), 深度为0的节点到深度为1的节点的这些边长度为2^30, ...
- 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 ...
- Codeforces Round #394 (Div. 2) E. Dasha and Puzzle(dfs)
http://codeforces.com/contest/761/problem/E 题意:给出一棵树,现在要把这棵树上的结点放置在笛卡尔坐标上,使得每一条边与x轴平行或者与y轴平行.输出可行解,即 ...
- 【codeforces 761E】Dasha and Puzzle
[题目链接]:http://codeforces.com/contest/761/problem/E [题意] 给你一棵树,让你在平面上选定n个坐标; 使得这棵树的连接关系以二维坐标的形式展现出来; ...
- CODEFORCES ROUND #761 ANALYSES BY TEAM:RED & BLACK
A. Dasha and Stairs Problems: 一个按照1,2,3……编号的楼梯,给定踩过的编号为奇数奇数和偶数的楼梯数量a和b,问是否可以有区间[l, r]符合奇数编号有a个,偶数编号有 ...
- 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 ...
随机推荐
- 【 D3.js 进阶系列 — 1.0 】 CSV 表格文件的读取
在入门系列的教程中.我们经常使用 d3.json() 函数来读取 json 格式的文件.json 格式非常强大.但对于普通用户可能不太适合,普通用户更喜欢的是用 Microsoft Excel 或 O ...
- android-调用系统的ContentPrivder获取单张图片实现剪切做头像及源代码下载
首先讲述这个小项目的特色: 1.调用系统的相冊应用获取单张图片 2.对单张图片进行剪切方便做成指定大小的头像图片 3.对获取图片的结果进行解析,使用三种方式进行. 首先看看效果图: 打开app,进入注 ...
- android 自己主动拒接后再取消自己主动拒接,该联系人来电界面无图标显示,且点击挂断无反应
1. 设置一个联系人为自己主动拒接 2. 该联系人来电 3. 取消该联系人的自己主动拒接 4. 该联系人来电 Error: 来电界面无头像显示,直接显示黑屏,且点击拒接butt ...
- 算法导论—无向图的遍历(BFS+DFS,MATLAB)
华电北风吹 天津大学认知计算与应用重点实验室 最后改动日期:2015/8/22 无向图的存储方式有邻接矩阵,邻接链表,稀疏矩阵等. 无向图主要包括双方面内容,图的遍历和寻找联通分量. 一.无向图的遍历 ...
- XML转换为HTML
from:http://www.w3school.com.cn/xml/xml_to_html.asp 在上一节中,我们讲解了如何通过 JavaScript 来解析 XML 并访问 DOM. 本例遍历 ...
- JSON with Java
work with json-lib.jar import net.sf.json.JSONArray;import net.sf.json.JSONException;import net.sf.j ...
- JDBC访问数据库查询信息的步骤(硬编码格式)
1 Class.forName()加载驱动 2 DriverManager获取Connect连接 3 创建Statement执行SQL语句 4 返回ResultSet查询结果 5释放资源 packag ...
- Latex 3: 解决LaTeX编译卡顿问题
1.问题: 最近在编译latex时,老是在tulmr.fd处编译很久,但是以前不这样啊,那肯定就是我最近做了什么导致这样的了,是什么呢? 2.解决: 后来google下发现了解决办法,原来是我新安装了 ...
- docker registry的CI规划
目前代码全部署在docker中, 考虑用jenkins打包成docker包再推送到docker registry 打包推送过程中自动按照日期打标签,并且刷新latest
- Java-Runoob-高级教程-实例-字符串:09. Java 实例 - 字符串小写转大写
ylbtech-Java-Runoob-高级教程-实例-字符串:09. Java 实例 - 字符串小写转大写 1.返回顶部 1. Java 实例 - 字符串小写转大写 Java 实例 以下实例使用了 ...