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 ...
随机推荐
- stl 之set图解
使用set或multiset之前,必须增加头文件<set> Set.multiset都是集合类,区别在与set中不同意有反复元素,multiset中同意有反复元素. sets和multis ...
- js的几种循环语句
//js种的循环语句 //while与do while的区别是while是满足条件后才执行 //do while是不管满不满足条件都会执行一次 //for 循环与while,do while相比循环结 ...
- getHibernateTemplate()(Spring中常用的hql查询方法)
Spring中常用的hql查询方法(getHibernateTemplate()) --------------------------------- 一.find(String queryStrin ...
- Deep Learning 28:读论文“Multi Column Deep Neural Network for Traffic Sign Classification”-------MCDNN 简单理解
读这篇论文“ Multi Column Deep Neural Network for Traffic Sign Classification”是为了更加理解,论文“Multi-column Deep ...
- LeetCode 1.两数之和(JS)
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- Linux设备驱动--块设备(三)之程序设计
块设备驱动注册与注销 块设备驱动中的第1个工作通常是注册它们自己到内核,完成这个任务的函数是 register_blkdev(),其原型为:int register_blkdev(unsigned i ...
- 使用cloudflare加速你的网站隐藏你的网站IP
前言 cloudflare 是一家国外的 CDN 加速服务商,还是很有名气的.提供免费和付费的加速和网站保护服务.以前推荐过的百度云加速的国外节点就是和 cloudflare 合作使用的 cloudf ...
- org.springframework.web.struts.ContextLoaderPlugIn 和 org.springframework.web.context.ContextLoaderListener
org.springframework.web.struts.ContextLoaderPlugIn 和 org.springframework.web.context.ContextLoaderLi ...
- 【189】◀▶ PowerShell 系统学习
参考网站如下: PowerShell 中文博客 PowerShell 博客——叹为观止 Mater-PowerShell 通过 PowerShell 编写脚本 Power ...
- 【179】IDL 读写 NetCDF 文件
NetCDF(network Common Data Form)由位于科罗拉多州波尔市的 Unidata 程序中心开发,主要应用于大气科学的研究.NetCDF 的数据模式具有简单性和灵活性的特点.Ne ...