【codeforces 761E】Dasha and Puzzle
【题目链接】:http://codeforces.com/contest/761/problem/E
【题意】
给你一棵树,让你在平面上选定n个坐标;
使得这棵树的连接关系以二维坐标的形式展现出来;
【题解】
dfs来搞;
显然如果某个点的度数大于4就无解。
初始坐标为(0,0)然后每一层的边的长度变为上一层长度的1/2
初始层的长度为2 30
这样可以保证每层节点都不会和上一层的相交;
因为2 i >2 1 +2 2 +...+2 i−1
又因为最多只有30个节点,所以这么做肯定是可以的,且不会超过题目的限制10 18
写dfs的时候,控制一下行走的方向就好;
不要走回头路。。
然后第一个点是4个方向都可以走的。不要写错了。
【Number Of WA】
2
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,0,-1,0,-1,-1,1,1};
const int dy[9] = {0,0,-1,0,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 30+5;
struct point{
LL x,y;
};
int n,du[N];
vector <int> G[N];
point ans[N];
void dfs(int v,int fa,LL x0,LL y0,LL len,int fx)
{
ans[v].x = x0,ans[v].y = y0;
int l = G[v].size();
int now = 0;
rep1(i,0,l-1)
{
if (G[v][i]==fa) continue;
now++;
int tnow = now+2;
if (tnow>4) tnow-=4;
if (tnow==fx) now++;
LL x1 = x0+1LL*dx[now]*len;LL y1 = y0+1LL*dy[now]*len;
dfs(G[v][i],v,x1,y1,len>>1,now);
}
}
int main()
{
//freopen("D:\\rush.txt","r",stdin);
rei(n);
rep1(i,1,n-1)
{
int x,y;
rei(x),rei(y);
du[x]++,du[y]++;
G[x].ps(y),G[y].ps(x);
}
rep1(i,1,n)
if (du[i]>4) return puts("NO"),0;
puts("YES");
dfs(1,0,0,0,1<<30,0);
rep1(i,1,n)
cout << ans[i].x<<' '<<ans[i].y<<endl;
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
【codeforces 761E】Dasha and Puzzle的更多相关文章
- 【codeforces 761A】Dasha and Stairs
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 761B】Dasha and friends
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 761C】Dasha and Password(动态规划做法)
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 761C】Dasha and Password(贪心+枚举做法)
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 761D】Dasha and Very Difficult Problem
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【66.47%】【codeforces 556B】Case of Fake Numbers
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
随机推荐
- POJ 3264 Balanced Lineup 区间最值
POJ3264 比较裸的区间最值问题.用线段树或者ST表都可以.此处我们用ST表解决. ST表建表方法采用动态规划的方法, ST[I][J]表示数组从第I位到第 I+2^J-1 位的最值,用二分的思想 ...
- PCB 围绕CAM自动化,打造PCB规则引擎
AutoCAM自动化平台,前端管理订单,而后端执行任务,前端UIl界面有板厚,铜厚,板材,表面处理,层数等信息,而这些信息并不是后端最终所需要的信息后.拿钻孔补偿来说,后端需要的是钻孔补偿值,但前端并 ...
- C语言内存管理总结
更新: 2018/01/09 增加free() 更新: 2018/04/13 修改部分文字与表格背景色与默认颜色相同 //# TODO: malloc, alloc, calloc, realloc ...
- 多物体运动框架案例一:多个Div的宽度运动变化
多物体运动框架,鼠标移入Div,此Div逐渐变宽,鼠标移出后,此Div逐渐缩短恢复原长度. <!doctype html> <html> <head> <ti ...
- Akka源码分析-Router
akak中还有一个比较重要的概念,那就是Router(路由).路由的概念,相信大家都不陌生,在akka中,它就是其他actors的一个代理,会把消息按照路由规则,分发给指定的actor.我一般喜欢把R ...
- hbuilder中的 http://www.w3.org/TR/html4/frameset.dtd
<!-- This is the HTML 4.01 Frameset DTD, which should be used for documents with frames. This DTD ...
- Java系列学习(七)-面向对象
1.成员变量和局部变量的区别 (1)在类中的位置不同 成员变量:类中 方法外 局部变量:方法中 (2)在内存中的位置不同 成员变量:在堆中 局部变量:在栈中 (3)生命周期不同 成员变量:随着对象的创 ...
- css3 画小蜜蜂
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- Android视频截图
本文介绍如何获取视频中某个时间点的数据 调用以下方法即可,特别注意,在获取图片时的参数单位为微秒,不是毫秒 如果错用了毫秒会一直获取第一帧的画面 /** * 获取某个时间点的帧图片 * * @para ...
- JS——轮播图简单版
1.小图标版本 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...