【题目链接】: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的更多相关文章

  1. 【codeforces 761A】Dasha and Stairs

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【codeforces 761B】Dasha and friends

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【codeforces 761C】Dasha and Password(动态规划做法)

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【codeforces 761C】Dasha and Password(贪心+枚举做法)

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 761D】Dasha and Very Difficult Problem

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  7. 【66.47%】【codeforces 556B】Case of Fake Numbers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  9. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

随机推荐

  1. SQL SERVER 语句大全

    ·SQL的简单查询实例教程关键词:SQL语句大全 中文网 整理编辑,经典SQL语句大全(SQL语句大总结),欢迎网友投稿 下列语句部分是Mssql语句,不可以在access中使用.SQL分类:DDL— ...

  2. hdu 6198(矩阵快速幂)

    number number number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  3. Head First 设计模式 —— 单例模式(Singleton)

    单例模式简要定义:单例模式确保一个类只有一个实例,并提供一个全局访问点. 1. 如何保证一个类只有一个实例,且这个实例易于被访问? lazy evaluation:在用到的时候才创建对象. 全局变量: ...

  4. POJ 1273 Drainage Ditches 最大流

    这道题用dinic会超时 用E_K就没问题 注意输入数据有重边.POJ1273 dinic的复杂度为O(N*N*M)E_K的复杂度为O(N*M*M)对于这道题,复杂度是相同的. 然而dinic主要依靠 ...

  5. vue项目打包之后首页白屏的问题

    本地的vue项目在server端浏览没问题,但是执行npm run build 打包之后在本地预览是白屏. 解决方法 1.路径问题 在config文件夹中找到index.js打开把assetsPubl ...

  6. AirtestIDE详解(跨平台的UI自动化编辑器)

    Airtest 是网易出品的一款基于图像识别和poco控件识别的一款UI自动化测试工具. AirtestIDE 是一个跨平台.多端(Windows.web.android.ios.游戏)的UI自动化测 ...

  7. JS判断数组是否包含某元素

    我在学习ES6数组拓展时,发现了新增了不少了有趣的数组方法,突然想好工作中判断数组是否包含某个元素是非常常见的操作,那么这篇文章顺便做个整理. 1.for循环结合break 可能很多人第一会想到for ...

  8. centos源更新

    .备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup .下载新的CentOS-Base.r ...

  9. CF 436D 最小生成树

    设一个开头的虚节点,然后建稠密图,O(n^2).使用prim.O(n^2),保存方案,没什么好说的. #include <string.h> #include <stdio.h> ...

  10. ansible基础知识(二)

    软件相关模块 yum yum和rpm的区别 rpm: (Redhat package manager)RPM管理支持事务机制.增强了程序安装卸载的管理. yum: YUM被称为 Yellow dog ...