NWERC 2018 C. Circuit Board Design 树 + 构造
生活随笔
收集整理的這篇文章主要介紹了
NWERC 2018 C. Circuit Board Design 树 + 构造
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
傳送門
文章目錄
- 題意:
- 思路:
題意:
給你一顆nnn個點的樹,讓你在二維平面中構造一顆樹,保證相鄰點的距離正好為111,并且線段不能有相交,坐標絕對值≤3e3\le3e3≤3e3。
n≤1e3n\le1e3n≤1e3
思路:
其實樣例已經給了提示了,當時光聽隊友說了句是菊花圖,也就沒多看,其實要是把第一個樣例怎么來的搞明白我感覺這個題就有了。
不按照題解的想法,我們考慮以(0,0)(0,0)(0,0)為原點,讓后將第一、二象限分成n?1n-1n?1條直線,我們只需要在dfsdfsdfs的過程中依次從小到大選擇相應斜率的直線即可,這樣保證了線不相交,考慮怎么保證距離為111呢?根據初中知識可知,sin?2a+cos?2b=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; } /**/ 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的NWERC 2018 C. Circuit Board Design 树 + 构造的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《人件(原书第3版)》—— 01 此时
- 下一篇: 高德地图 天气预报查询