日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

NWERC 2018 C. Circuit Board Design 树 + 构造

發布時間:2023/12/4 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NWERC 2018 C. Circuit Board Design 树 + 构造 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

傳送門

文章目錄

  • 題意:
  • 思路:

題意:

給你一顆nnn個點的樹,讓你在二維平面中構造一顆樹,保證相鄰點的距離正好為111,并且線段不能有相交,坐標絕對值≤3e3\le3e33e3

n≤1e3n\le1e3n1e3

思路:

其實樣例已經給了提示了,當時光聽隊友說了句是菊花圖,也就沒多看,其實要是把第一個樣例怎么來的搞明白我感覺這個題就有了。

不按照題解的想法,我們考慮以(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 树 + 构造的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。