传送门
文章目录
- 题意:
- 思路:
题意:
给你一颗nnn个点的树,让你在二维平面中构造一颗树,保证相邻点的距离正好为111,并且线段不能有相交,坐标绝对值≤3e3\le3e3≤3e3。
n≤1e3n\le1e3n≤1e3
思路:
其实样例已经给了提示了,当时光听队友说了句是菊花图,也就没多看,其实要是把第一个样例怎么来的搞明白我感觉这个题就有了。
不按照题解的想法,我们考虑以(0,0)(0,0)(0,0)为原点,让后将第一、二象限分成n−1n-1n−1条直线,我们只需要在dfsdfsdfs的过程中依次从小到大选择相应斜率的直线即可,这样保证了线不相交,考虑怎么保证距离为111呢?根据初中知识可知,sin2a+cos2b=1\sin^2 a+\cos^2 b=1sin2a+cos2b=1,所以对于uuu的下一个点vvv,对应的(x,y)(x,y)(x,y)应该是(xu+cos(ang),yu+sin(ang))(x_u+\cos(ang),y_u+\sin(ang))(xu+cos(ang),yu+sin(ang)),其中angangang是对应的角度。
所以这个题就完事啦。
// Problem: C - Circuit Board Design
// Contest: Virtual Judge - Namomo Summer Camp Day 4
// URL: https://vjudge.net/contest/455214#problem/C
// Memory Limit: 262 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define pb push_back
using namespace std;typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=1010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6,PI=acos(-1);int n;
vector<int>v[N];
double x[N],y[N];
int cnt;void dfs(int u,int fa) {for(auto xx:v[u]) {if(xx==fa) continue;double reg=cnt/(n-1.0)*PI;x[xx]=x[u]+cos(reg);y[xx]=y[u]+sin(reg);cnt++;dfs(xx,u);}
}int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);scanf("%d",&n);for(int i=1;i<=n-1;i++) {int a,b; scanf("%d%d",&a,&b);v[a].pb(b); v[b].pb(a);}dfs(1,0);for(int i=1;i<=n;i++) printf("%.10lf %.10lf\n",x[i],y[i]);return 0;
}
/**/