【题目链接】: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. cas4.2的安装

    cas4.2使用的是gradle来构建项目的,项目代码在https://github.com/Jasig/cas下载. 然后之后进入项目的根目录,然后执行gradle来编译项目,如下: gradle ...

  2. 如何根据configure.ac和Makefile.am为开源代码产生当前平台的Makefile

    1 2 3 4 5 6 7 8 9 //根据configure.in和Makefile.am生成makefile的步骤,基于UBUNTU 12.04 1.autoscan (可选) 2.aclocal ...

  3. PCB 内层负片散热PAD Symbols尺寸更改方法

    如下图这是我们熟悉的内层负片散热PAD Symbols,我们CAM制作时,为了满足PCB工厂生产制作能力,,会优化散热PAD尺寸,让热PAD的尺寸符合制作规范要求,通常我们只关注散热PAD的3个指标即 ...

  4. PCB 脱离IIS的Web应用

    在用.net Web编程中,我们写好的Web应用首选会挂在IIS上面,因为它足稳定并且功能齐全,但这不是我们唯一的选择,微软给我们提供了Owin组件,Web应该的宿主可以不再是IIS了,有了Owin后 ...

  5. codevs1486愚蠢的矿工(树形dp)

    1486 愚蠢的矿工  时间限制: 1 s  空间限制: 128000 KB     题目描述 Description Stupid 家族得知在HYC家的后花园里的中央花坛处,向北走3步,向西走3步, ...

  6. mysql 数据去重

    update ptop_investrecord set delflag = 1 where cid  = 250 and uid = 92569  and delflag = 0 and progr ...

  7. HDU 1754 Java

    退役后学java... 裸线段树 //By SiriusRen import java.util.*; import java.math.*; public class Main{ public st ...

  8. 【BZOJ3110】[ZJOI2013]K大数查询(整体二分)

    题目: BZOJ3110 分析: 整体二分模板题-- 先明确一下题意:每个位置可以存放多个数,第一种操作是"加入 (insert) "一个数而不是"加上 (add) &q ...

  9. ACM_百度的面试(单调栈)

    百度的面试 Time Limit: 2000/1000ms (Java/Others) Problem Description: 在一个二维平面,从左到右竖立n根高度分别为:a[1],a[2],... ...

  10. NHibernate系列学习(三)-条件查询Criteria

    1.本笔记主要介绍Criteria的使用 2.效果界面 3.代码详情 namespace KimismeDemo { public partial class Form3 : Form { priva ...