HDU 4707:Pet】的更多相关文章

http://acm.hdu.edu.cn/showproblem.php?pid=4707 [题目大意]: Lin Ji 的宠物鼠丢了,在校园里寻找,已知Lin Ji 在0的位置,输入N D,N表示校园中点的个数,D表示宠物鼠不可能在距离D之内,接下来N-1行,输入x,y,表示x与y相邻,(相邻两点之间的距离为1,不相邻为inf),不存在环结构. [题解]: 用邻接表存储树形结构,然后用DFS遍历图 [code]: #include <iostream> #include <stdio…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4707 题目大意:在一个无环的,从0开始发散状的地图里,找出各个距离0大于d的点的个数 Sample Input 1 10 2 0 1 0 2 0 3 1 4 1 5 2 6 3 7 4 8 6 9   Sample Output 2 分析:从0点开始BFS,给每个点一个距离0点标记,再算出大于距离d一共多少个 代码如下: # include<iostream> # include<cstdi…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4707 解题报告:题目大意是在无向图G中有n个点,分别从0 到n-1编号,然后在这些点之间有n-1条边,可以保证这个图是连通图,并且每条边的长度都是1,然后让你求出从编号为0的点出发,到其它的点的距离大于d的点的个数. 这题的点的个数有500000个,而内存限制为32M,很显然,开邻接矩阵不行,但这题实际上不需要记录边只需要开一位数组就可以了,但是我为了练习一下邻接矩阵的写法,特地用邻接矩阵另外写了一…
Pet                                                          Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)                                                                          Total Submission(s): 1909    Acc…
Pet Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2248    Accepted Submission(s): 1098 Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He sea…
Pet Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 535 Accepted Submission(s): 258 Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He searched in…
Pet Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 181    Accepted Submission(s): 55 Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He searche…
Pet Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1809    Accepted Submission(s): 874 Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He sear…
一道简单的搜索题目,建一个树,根节点是 0 ,连接的两个节点的距离是 1 ,求 到 根节点长度是2的节点的个数. #include<stdio.h> #include<string.h> struct node{ int next,to; int step; }; node edge[]; int tot; ]; int N,D,ans; void Add(int x,int y) { edge[tot].to=y; edge[tot].next=head[x]; head[x]=…
题意:linji的仓鼠丢了,他要找回仓鼠,他在房间0放了一块奶酪,按照抓鼠手册所说,这块奶酪可以吸引距离它D的仓鼠,但是仓鼠还是没有出现,现在给出一张关系图,表示各个房间的关系,相邻房间距离为1,而且图中没有回路,每个房间都是联通的,求仓鼠可能出现的房间的数量. 很容易的dfs,50000个房间数据量比较大,用数组难以保存,于是用vector储存关系表.遍历过去,遍历过几个房间,那剩下的就是仓鼠可能出现的房间数了. 代码: /* * Author: illuz <iilluzen[at]gmai…
http://acm.hdu.edu.cn/showproblem.php?pid=4707 Pet Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He searched in th…
Pet Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2052    Accepted Submission(s): 1007 Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He sear…
#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int maxn = 100000; int T, N, D; int x, y; int f[maxn]; void init() { for(int i = 0; i <= N - 1; i++) f[i] = i; } int Find(int root) { while(root != f[roo…
Problem Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He searched in the room but didn’t find the hamster. He tried to use some cheese to trap the hamster. He put the cheese trap in his room and waited for…
Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He searched in the room but didn’t find the hamster. He tried to use some cheese to trap the hamster. He put the cheese trap in his room and waited for three da…
直接深搜  ,水啊 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define N 100002 int head[N]; //bool vis[N]; int cnt; struct node{ int to,next; }edge[N]; int n,d,ans,dep; void init() { ans=cnt=dep=0; memset(head,-1,…
题意:linji的仓鼠丢了,他要找回仓鼠,他在房间0放了一块奶酪,按照抓鼠手册所说,这块奶酪可以吸引距离它D的仓鼠,但是仓鼠还是没有出现,现在给出一张关系图,表示各个房间的关系,相邻房间距离为1,而且图中没有回路,每个房间都是联通的,求仓鼠可能出现的房间的数量. Sample Input110 20 10 20 31 41 52 63 74 86 9 Sample Output2 #include <cstdio> #include <algorithm> #include <…
最短路的优先队列做法: #include<stdio.h> #include<queue> #include<string.h> #define N  100010 #define inf 0x3fffffff using namespace std; int first[N],next[N],u[N],v[N],w[N],d[N]; int main() { int t,i,e,cnt,dis,n; scanf("%d",&t); whil…
http://acm.hdu.edu.cn/showproblem.php?pid=4707 题意:判断距离大于D的点有多少个. 思路: 邻接表建图,dfs每一个点,记录步数. #include <stdio.h> #include <string.h> ; int vis[N],dis[N],head[N],cnt,step; struct node { int u; int v; int next; } edge[N]; void add(int u,int v) { edge…
  A - QQpet exploratory park HDU - 1493 Today, more and more people begin to raise a QQpet. You can get a lot of pleasure from it, although it does not have a real life and it calls for huge patience to take care of it. There is a place called QQpet…
Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7194    Accepted Submission(s): 3345 Problem Description 话说上回讲到海东集团面临内外交困,公司的元老也只剩下XHD夫妇二人了.显然,作为多年拼搏的商人,XHD不会坐以待毙的.  一天,当他正在苦思冥想解困良策的…
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; int jc[100003]; int p; int ipow(int x, int b) { ll t = 1, w = x;…
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格线满足两侧分别是海洋和陆地 这道题很神 首先考虑一下,什么情况下能够对答案做出贡献 就是相邻的两块不一样的时候 这样我们可以建立最小割模型,可是都说是最小割了 无法求出最大的不相同的东西 所以我们考虑转化,用总的配对数目 - 最小的相同的对数 至于最小的相同的对数怎么算呢? 我们考虑这样的构造方法:…
Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4569 Description Let f(x) = a nx n +...+ a 1x +a 0, in which a i (0 <= i <= n) are all known integers. We call f(x) 0 (mod…
The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4006 Description Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a nu…
How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1796 Description   Now you get a number N, and a M-integers set, you should find out how many integers which are sm…
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pid=4418 读了一遍题后大体明白意思,但有些细节不太确定.就是当它处在i点处,它有1~m步可以走,但他走的方向不确定呢.后来想想这个方向是确定的,就是他走到i点的方向,它会继续朝着这个方向走,直到转向回头. 首先要解决的一个问题是处在i点处,它下一步该到哪个点.为了解决方向不确定的问题,将n个点转…
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/article/details/22569639 这个题目本身简单,我的想法也很easy,但是发生在测试上,我把memset的参数搞错了,第三个是sizeof(a), 比如说int a[10],第三个参数应该是sizeof(10),也就是40,而我传的是10,导致后面的测试,都是答案错误,也就是后面的数据,初始…
problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟  a.     p(r)=   R'/i   rel(r)=(1||0)  R是前n次输入有关URL的个数  R'是后n次已经输入有关URL的个数 b.   另加:输入 istringstream #include<iostream> #include<sstream> //istringstream 必须包含这个头文件 #include<string&g…
http://acm.hdu.edu.cn/showproblem.php?pid=2586 题意:求最近祖先节点的权值和 思路:LCA Tarjan算法 #include <stdio.h> #include <string.h> #define maxn 40005 ],pos,dist[maxn],f[maxn]; bool vis[maxn]; struct Edge{ int to,val,next; }edge[maxn*]; void add(int u,int v,…