题意:在H * W的矩形果园里有苹果.梨.蜜柑三种果树, 相邻(上下左右)的同种果树属于同一个区域,给出果园的果树分布,求总共有多少个区域. 输入:多组数据,每组数据第一行为两个整数H,W(H <= 100, W <= 100), H =0 且 W = 0代表输入结束.以下H行W列表示果园的果树分布, 苹果是@,梨是#, 蜜柑是*. 输出:对于每组数据,输出其区域的个数. #include<cstdio> #include<vector> #include<que…
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=46522 简单DFS,题目翻译参考  http://blog.csdn.net/synapse7/article/details/14453017 #include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <cstring>…
题目链接:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0118 题意:给定一个矩阵,同类字符相连的为一个块,问总共有几个块. 输入:h,w(行和列)0 <= h <= 100,0 <= w <= 100 矩阵 输入包含多组用例,以0,0结束. 输出:块数. 代码: #include <iostream> using namespace std; typedef long long ll; #defin…
タナカ氏が HW アールの果樹園を残して亡くなりました.果樹園は東西南北方向に H × W の区画に分けられ.区画ごとにリンゴ.カキ.ミカンが植えられています.タナカ氏はこんな遺言を残していました. 果樹園は区画単位でできるだけ多くの血縁者に分けること.ただし.ある区画の東西南北どれかの方向にとなりあう区画に同じ種類の果物が植えられていた場合は.区画の境界が分からないのでそれらは 1 つの大きな区画として扱うこと. 例えば次のような 3 × 10 の区画であれば ('リ'はリンゴ.'カ'はカキ.…
-->Property Distribution 原文是日语,算了算了,直接上我大中华母语吧  Descriptions: 在H * W的矩形果园里有苹果.梨.蜜柑三种果树, 相邻(上下左右)的同种果树属于同一个区域,给出果园的果树分布,求总共有多少个区域. Input 多组数据,每组数据第一行为两个整数H.W(H <= 100, W <= 100), H =0 且 W = 0代表输入结束.以下H行W列表示果园的果树分布, 苹果是@,梨是#, 蜜柑是*. Output 对于每组数据,输出…
Property Distribution タナカ氏が HW アールの果樹園を残して亡くなりました.果樹園は東西南北方向に H×W の区画に分けられ.区画ごとにリンゴ.カキ.ミカンが植えられています.タナカ氏はこんな遺言を残していました. 果樹園は区画単位でできるだけ多くの血縁者に分けること.ただし.ある区画の東西南北どれかの方向にとなりあう区画に同じ種類の果物が植えられていた場合は.区画の境界が分からないのでそれらは 1 つの大きな区画として扱うこと. 例えば次のような 3 × 10 の区画で…
Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12519    Accepted Submission(s): 7753 Problem Description There is a rectangular room, covered with square tiles. Each tile is color…
题目: 简单dfs,没什么好说的 代码: #include <iostream> using namespace std; typedef long long ll; #define INF 2147483647 int w,h; ][]; ][] = {-,,,,,-,,}; ; void dfs(int x,int y){ || x >= h || y < || y >= w || a[x][y] == '#') return; ans++; a[x][y] = '#';…
题目在这里 题意 : 问你按照图中所给的提示走,多少步能走出来??? 其实只要根据这个提示走下去就行了.模拟每一步就OK,因为下一步的操作和上一步一样,所以简单dfs.如果出现loop状态,只要记忆每个所到的点的第一次的步数,最后总步数减掉它即可 /************************************************************************* > File Name: poj1573.cpp > Author: YeGuoSheng >…
UWP中的Attached Property即附加属性,在实际开发中是很常见的,比如Grid.Row: <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid.RowDefinitions> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition>…
POJ1979 Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can mo…
LINK 题意:给出n个数,\(a_i\)代表下一步会移动到第\(a_i\)个位置,并继续进行操作,\(b_i\)1代表进行一次翻面操作,要求不管以哪个位置上开始,最后都能满足 1.到达过所有位置 2.对到达的任意位置,都已经进行过奇次和偶次翻面操作 交换任意两个\(a_i\),或修改\(b_i\)的值算做一次操作 问最小操作数. 思路:首先可以知道,要满足条件1,必须使该排列的循环节长度为1(即所有数成一个环),再者要满足条件2,则\(b_i==1\)必须有奇数个. 那么很简单,对所有未标记的…
这道题看上去非常麻烦,什么迷宫啊.门之类的,事实上挺简单的,就是让把与 * 连通的都置为 # 包含 * , 直接dfs就能够了,只是我wa了好多次...最后居然是多读了一个换行.忘了加getchar()了,gets()函数 会把缓冲区里面的换行给读进去的...应该把换行去掉,血的教训啊.. . 代码: #include<stdio.h> #include<string.h> #include<stdlib.h> int dx[4]={-1,0,0,1}; int dy[…
Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18201   Accepted: 9192 Description Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100…
Problem Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can mo…
原题链接:点击!   大致题意:白块表示可以放置炮台的位置——每个炮台可以攻击到上下左右的直线上的炮台(也就是说在它的上下左右直线上不可以再放置炮台,避免引起互相攻击),黑块表示隔离墙的位置——不可放置并且可以阻挡炮火:求对于一个最大4*4的格子来说,最大的放置炮台的个数是多少. 简单分析: 简单的dfs();由于本题地图很小,不用考虑太多,尽情暴力即可.先把DFS枝干画出来,然后枝叶就用函数来具体实现. AC代码:(附注释) #include <iostream> #include<s…
通信网络 201709-4 一看到题目分析了题意之后,我就想到用floyd算法来求解每一对顶点的最短路.如果一个点和任意一个点都有最短路(不为INF),那么这就是符合的一个答案.可是因为题目超时,只能拿60分. 另一种解法就是使用dfs把图简单的遍历一遍就可以了.这里要用到两遍dfs反着也要建图. #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #includ…
就是求图中有多少个水洼.对图进行dfs遍历,并把是水洼的地方全部标记.然后从下一个是水哇的地方再进行dfs. #include <cstdio> #include <iostream> #include <cstring> using namespace std; ][]; int sum; ][]; , -, -, , , , , }; , , , -, , -, ,}; int row, col; bool check(int x, int y) { &&a…
1.POJ 1321  棋盘问题 2.总结: 题意:给定棋盘上放k个棋子,要求同行同列都不重. #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<cstdio> #define max(a,b) a>b?a:b #define F(i,a,b) for (int i=a;i<=b…
http://acm.hdu.edu.cn/showproblem.php?pid=1258 关键点就是一次递归里面一样的数字只能选一次. #include <cstdio> #include <cstring> int n,t; ],c[]; bool flag; void dfs(int k,int sum,int l) { if(sum==t) { ;i<l-;i++) printf("%d+",c[i]); printf(]); flag=; re…
http://poj.org/problem?id=2386 http://acm.hdu.edu.cn/showproblem.php?pid=1241 求有多少个连通子图.复杂度都是O(n*m). #include <cstdio> ][]; int n,m; void dfs(int x,int y) { ;i<=;i++) ;j<=;j++) //循环遍历8个方向 { int xx=x+i,yy=y+j; &&xx<n&&yy>=…
题目链接 题意 : 问一个m×n的矩形中,有多少个pocket,如果两块油田相连(上下左右或者对角连着也算),就算一个pocket . 思路 : 写好8个方向搜就可以了,每次找的时候可以先把那个点直接变为*,这样可以避免重复搜索. //POJ 1562 ZOJ 1709 #include <stdio.h> #include <string.h> #include <iostream> #include <stack> #include <algori…
组合数 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 找出从自然数1.2.... .n(0<n<10)中任取r(0<r<=n)个数的所有组合.   输入 输入n.r. 输出 按特定顺序输出所有组合.特定顺序:每一个组合中的值从大到小排列,组合之间按逆字典序排列. 样例输入 5 3 样例输出 543 542 541 532 531 521 432 431 421 321 #include<stdio.h> #include<str…
Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6795   Accepted: 3622 Description Farmer John's farm was flooded in the most recent storm, a fact only aggravated by the information that his cows are deathly afraid of wate…
日文题... 题意:一个面积为H*W的果园,种了苹果,梨和蜜柑.相邻(上下左右)的果树属于同一个区域,问果园共有多少个区域. 分析:迷宫问题.对于每一个格子,可以用深度优先搜索把相同果树的格子遍历并标记.也就是说,每做一次DFS,消灭掉一个区域.只需要遍历果园,对每一个未被标记的格子做DFS,做DFS的次数就是果园的区域数.这里不需要另外用其他数组标记格子已访问,只需要将格子的元素改为一个不会出现的元素如1即可. C++代码: #include <cstdio> #include <cs…
Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 236    Accepted Submission(s): 107 Problem Description In the ancient three kingdom period, Zhuge Liang was the most famous a…
题目链接: http://poj.org/problem?id=3895 题目意思: 在无向连通图中图中找一个经过边数最多的环. 解题思路: 从任意一点直接DFS,不用回溯,注意构成环的话至少有3条边. 因为任意一个最大环,一定可以搜到. 代码: #include<iostream> #include<cmath> #include<cstdio> #include<cstdlib> #include<string> #include<cs…
题意:没有儿子的节点所结苹果数是节点的编号,有儿子的所结苹果是儿子数量(k+1)/2个,求跟节点的苹果数 直接递归一下,先求出所有儿子的苹果树,在排序,,刚开始以为1就是根节点,根节点不确定,, #include<stdio.h> #include<string.h> #include<stdlib.h> const int N=20010; int w[N],vis[N],head[N],num,p[N]; struct edge { int st,ed,next;…
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem?id=1562 --------------------------------------------------------------------------------------------------------------------------------------…
题目链接:http://poj.org/problem?id=1321 很久没有敲搜索了啊,今天敲了个水题练练手,哈哈.... 题目大意: 就是求在n*n的方格上放置k个棋子的方案数 代码: #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> using namespace std; int n,k; ][]; ]; int sum; int ans; bool Ju…