【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; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
随机推荐
- android-----JNI中的log打印【转】
本文转载自:http://blog.csdn.net/zengraoli/article/details/11644815 1. 导入log头文件 在你使用的 .c/ .cpp 文件中 导入 log. ...
- ※归并排序(merge sort)
/** 归并排序:通常以递归的方式来实现,它反复将所处理的数组分成两半,并分别对这两半进行排序, 最后再把经过排序的数组归并在一起. */ 归并排序的伪代码实现: 将数组分为两半 对左半部分排序 对右 ...
- 使用自定义的AlertDialog。
使用自定义的AlertDialog.1.核心的方法是setView(View view):把自己的view放置到dialog中填充.2.setCanceledOnTouchOutside(boolea ...
- 启动Tomcat任何程序都报错
启动Tomcat出现: Cannot publish to the server because it is missing its runtime environment. 可能是servers中不 ...
- java 监听机制模拟(JButton按钮监听机制)
一.概念 1.事件监听器 事件监听器就我个人的理解就是:被外部事件(键盘.鼠标)引发的程序,这段程序是被嵌入到事件源的类里面,它负责监听事件列表.而很多人把事件监听器理解成是实现EventListen ...
- JSP-Runoob:JSP 链接数据库
ylbtech-JSP-Runoob:JSP 链接数据库 1.返回顶部 1. JSP 连接数据库 本教程假定您已经了解了 JDBC 应用程序的工作方式.在您开始学习 JSP 数据库访问之前,请访问 J ...
- FPC报价模块配置 UpdateCommand影响了预期 1 条记录中的 0 条 解决办法
今天在增加P4厂 FPC报价模块配置,增加刚挠信息节点,在保存时报错:UpdateCommand影响了预期 1 条记录中的 0 保存时使用:SqlDataAdapter批量更新DataTable,怎么 ...
- [Swift通天遁地]五、高级扩展-(8)ImageView(图像视图)的各种扩展方法
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 【BZOJ3205_洛谷3638】[APIO2013]机器人(动态规划)
题目: 洛谷3638 分析: 卡了一天的神题--(OrzJumpmelon) 首先预处理出从点\(p\)向\(d\)方向出发最终能到达的点\(nxt[p][d]\).这个可以直接记忆化搜索解决.如果出 ...
- 解决Oracle 本地可以连接,远程不能连接问题
一.问题描述: 1.telnet 2.输入命令 lsnrctl status 远程访问不到的原因为:监听指向的是localhost,而不是你本机的远程访问ip地址,因此需要将监听的指向修改为你本机的远 ...