codeforces822F Madness -- 贪心
来源:互联网 发布:eclipse java 贪吃蛇 编辑:程序博客网 时间:2024/06/10 00:55
显然一条路径只包含一条边是最优的。
令
考虑点
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define N 110struct Edge{ int f,t,nx; double s;}e[N<<1];int i,j,k,n,m,p,h[N],Num,s[N],x,y;bool b[N<<1];inline void Add(int x,int y){ e[++Num].t=y;e[Num].f=x;e[Num].nx=h[x];h[x]=Num;}inline void Dfs1(int x,int y){ if(y)s[x]=1; for(int i=h[x];i;i=e[i].nx) if(e[i].t!=y)b[i]=1,Dfs1(e[i].t,x),s[x]++;}inline void Dfs2(int x,double z){ double S=2.0/s[x]; double Cur=z+S+1; while(Cur>2)Cur-=2; for(int i=h[x];i;i=e[i].nx) if(b[i]){ e[i].s=Cur; Dfs2(e[i].t,Cur); Cur+=S; if(Cur>2)Cur-=2; }}int main(){ scanf("%d",&n); for(i=1;i<n;i++)scanf("%d%d",&x,&y),Add(x,y),Add(y,x); Dfs1(1,0);Dfs2(1,0); printf("%d\n",n-1); for(i=1;i<=Num;i++) if(b[i]) if(e[i].s<1) printf("1 %d %d %d %.7lf\n",i+1>>1,e[i].f,e[i].t,1-e[i].s); else printf("1 %d %d %d %.7lf\n",i+1>>1,e[i].t,e[i].f,2-e[i].s); return 0;}
阅读全文
0 0
- codeforces822F Madness -- 贪心
- F. Madness Codeforces 822F 贪心 构造
- 【bzoj4065】Graphic Madness
- BZOJ3958: [WF2011]Mummy Madness
- JavaScript Madness: Dynamic Script Loading
- JavaScript Madness: Dynamic Script Loading
- BZOJ 3958: [WF2011]Mummy Madness
- 对话#26:A Midsummer Night’s Madness
- Configure/Build System Madness under *nix
- Four Methods to the Madness(1)
- SFX:property caching madness in JIT
- Review of Debugging the development process 5. Schedule Madness
- Alices.Tea.Cup.Madness.v1.0.1.80.Cracked-F4CG\
- UVALive 6265 Graphic Madness 搜索 Regionals 2012 :: Europe - Central
- [BZOJ3958][WF2011]Mummy Madness(二分+扫描线+线段树)
- bzoj 3958: [WF2011]Mummy Madness (扫描线+线段树)
- 贪心!
- 贪心~
- next_permutation函数
- list.addAll()是浅拷贝,如…
- Fusion 360 API: JavaScript API进入维护模式
- 本人博客声明
- spring之aop方法内部调用问题
- codeforces822F Madness -- 贪心
- E
- vue动态图片
- main的参数
- Shader Forge入门笔记
- 深入敏捷测试之测试象限
- IntelliJ IDEA 下的svn配置及使用的非常详细的图文总结
- opengl坐标变换 整个流程的计算
- UE4球体根据镜头方向前进