poj 3659 Cell Phone Network 贪心
来源:互联网 发布:2017中超守门员数据 编辑:程序博客网 时间:2024/05/19 19:14
这个题目本来应该用简单的树形dp来做的
但是一开始就想错了
先用了统计叶子节点的做法
但是因为中间会出现一些已经亮了但是没有建造灯塔的点
最后就用贪心一贪到底了
具体做法见代码
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;const int maxn=11111;struct{ int next,to,ture;}e[maxn<<2];int head[maxn],lon,text[maxn];void edgemake(int from,int to){ e[++lon].next=head[from]; e[lon].to=to; head[from]=lon;}int cnt[maxn],col[maxn];int ans;int dfs(int t){ for(int k=head[t];k!=-1;k=e[k].next) { if(e[k].ture!=1) continue; int u=e[k].to; dfs(u); } for(int k=head[t];k!=-1;k=e[k].next) { int u=e[k].to; if(e[k].ture!=1) continue; if(col[u]==1) { ans++; col[t]=3; return(0); } } for(int k=head[t];k!=-1;k=e[k].next) { int u=e[k].to; if(e[k].ture!=1) continue; if(col[u]==3) { col[t]=2; return(0); } } col[t]=1;}int dfs1(int t){ text[t]=1; for(int k=head[t];k!=-1;k=e[k].next) { int u=e[k].to; if(!text[u]) { e[k].ture=1; dfs1(u); } }}int main(){// freopen("in.txt","r",stdin); int n; scanf("%d",&n); if(n==1) { printf("1\n"); return(0); } memset(col,0,sizeof(col)); memset(head,-1,sizeof(head)); memset(text,0,sizeof(text)); memset(e,0,sizeof(e)); lon=0; for(int i=1;i<n;i++) { int from,to; scanf("%d %d",&from,&to); edgemake(from,to); edgemake(to,from); } ans=0; dfs1(1); dfs(1); printf("%d\n",ans+(col[1]==1)); return 0;}
- poj 3659 Cell Phone Network 贪心
- POJ 3659 Cell Phone Network(贪心)
- POJ 3659 Cell Phone Network【最小支配集 dp && 贪心】
- POJ 3659 Cell Phone Network
- POJ-3659-Cell Phone Network
- POJ 3659 Cell Phone Network
- POJ 3659 Cell Phone Network
- POJ 3659——Cell Phone Network
- [树形DP] poj 3659 Cell Phone Network
- POJ 3659 Cell Phone Network(树形DP)
- POJ 3659 Cell Phone Network【最小支配集、树型dp】
- poj 3659 Cell Phone Network USACO 树形DP
- poj 3659 Cell Phone Network (树最小支配集)
- POJ 3659 Cell Phone Network 最小支配集
- POJ 3659 Cell Phone Network (树dp)
- POJ3659 Cell Phone Network【最小支配集】【贪心】
- POJ3659 Cell Phone Network
- poj 3659 Cell Phone Network 树型DP也是树的最小支配集
- poj 1850 Code 递推
- poj 1952 BUY LOW, BUY LOWER dp
- poj 2190 isbn 模拟
- poj 3663 Costume Party 二分
- poj 3661 Running dp(动态规划)
- poj 3659 Cell Phone Network 贪心
- poj 2409 Let it Bead
- poj 3662 Telephone Lines 图论
- poj 1944 模拟 枚举
- poj 1945 Power Hungry Cows 启发式搜索
- Scala学习记录(一)
- poj 1948 Triangular Pastures dp
- poj 1949 Chores
- poj 1950 Desser dfs