| typedef struct pos |
| { |
| int x; |
| int y; |
| bool operator < (const pos &o) const |
| { |
| |
| if((x==o.x)&&(y==o.y)) |
| return false; |
| return true; |
| } |
| }pos; |
| |
| pair<map<pos,int>::iterator, bool> ret; |
| static map<pos,int>posMap; |
| void fss(vector<vector<int>>& image,int x,int y,int num) |
| { |
| if(x<0) |
| return; |
| if(x>=image.size()) |
| return; |
| if(y<0) |
| return; |
| if(y>=image[0].size()) |
| return; |
| |
| pos p; |
| p.x=x; |
| p.y=y; |
| ret= posMap.insert(pair<pos,int>(p,1)); |
| if(!ret.second) |
| { |
| return; |
| } |
| |
| |
| |
| if(image[x][y]==num) |
| { |
| |
| fss(image,x-1,y,num); |
| fss(image,x+1,y,num); |
| fss(image,x,y-1,num); |
| fss(image,x,y+1,num); |
| |
| } |
| } |
| int main(int argc, char *argv[]) |
| { |
| vector<int>vec; |
| int arr[]={0,0,0}; |
| for(auto i=0;i<sizeof(arr)/sizeof(int);i++) |
| vec.push_back(arr[i]); |
| |
| vector<int>vec2; |
| int arr2[]={0,0,0}; |
| for(auto i=0;i<sizeof(arr2)/sizeof(int);i++) |
| vec2.push_back(arr2[i]); |
| |
| vector<int>vec3; |
| int arr3[]={1,0,1}; |
| for(auto i=0;i<sizeof(arr)/sizeof(int);i++) |
| vec3.push_back(arr3[i]); |
| |
| |
| |
| vector<vector<int>> coordinates; |
| coordinates.push_back(vec); |
| coordinates.push_back(vec2); |
| |
| |
| |
| fss(coordinates,0,0,0); |
| |
| |
| |
| |
| cout<<posMap.size()<<endl; |
| map<pos,int>::iterator it; |
| for(it=posMap.begin();it!=posMap.end();++it) |
| { |
| cout<<it->first.x<<" "<<it->first.y<<endl; |
| } |
| return 0; |
| } |
| |
结果是:
| 12 |
| 1 0 |
| 1 2 |
| 0 0 |
| 1 0 |
| 1 1 |
| 1 2 |
| 0 2 |
| 0 0 |
| 0 1 |
| 1 1 |
| 1 0 |
| 0 0 |
不是说map键具有唯一性么?谁能解释下
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)