India and China Origins bfs+二分

 

A long time ago there are no himalayas between India and China, the both cultures are frequently exchanged and are kept in sync at that time, but eventually himalayas rise up. With that at first the communation started to reduce and eventually died. 
 



Let's assume from my crude drawing that the only way to reaching from India to China or viceversa is through that grid, blue portion is the ocean and people haven't yet invented the ship. and the yellow portion is desert and has ghosts roaming around so people can't travel that way. and the black portions are the location which have mountains and white portions are plateau which are suitable for travelling. moutains are very big to get to the top, height of these mountains is infinite. So if there is mountain between two white portions you can't travel by climbing the mountain. 
And at each step people can go to 4 adjacent positions. 

Our archeologists have taken sample of each mountain and estimated at which point they rise up at that place. So given the times at which each mountains rised up you have to tell at which time the communication between India and China got completely cut off.

题目大意,每年都会有一座山升起来问几年后中印的交流会断掉

我的ma,居然没有意识到年是单调的,既然意识到了,辣么就可以二分了

对于每一个mid年份 先绘制一下图tgap 然后从第一排的每一个位置开始搜索,如果能搜到n-1的位置,那么就可以交流,继续向上二分,否则向下二分。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

int n,m,year;
char gap[600][600];
char tgap[600][600];
int px[251000],py[251000];
bool visit[550][550];
int dir[4][2]={-1,0,1,0,0,-1,0,1};
struct node
{
	int x,y;
	node(){}
	node(int a,int b)
	{
		x=a,y=b;
	}
};

bool bfs(int x,int y)
{
	memset(visit,0,sizeof(visit));
	visit[x][y]=1;
	queue<node> q;
	q.push(node(x,y));
	while(!q.empty())
	{
		node in,ne;
		in=q.front();
		q.pop();
		if(in.x>=n-1)
		{
			return 1;
		}
		for(int i=0;i<4;i++)
		{
			ne.x=in.x+dir[i][0];
			ne.y=in.y+dir[i][1];
			if(visit[ne.x][ne.y]==0&&tgap[ne.x][ne.y]=='0'&&ne.x>=0&&ne.x<n&&ne.y>=0&&ne.y<m)
			{
				visit[ne.x][ne.y]=1;
				q.push(ne);
			}
		}
	}
	return false;
}

bool judge(int Y)
{
	for(int i=0;i<n;i++) strcpy(tgap[i],gap[i]);
	for(int i=1;i<=Y;i++)
	{
		tgap[px[i]][py[i]]='1';
	}
	for(int i=0;i<m;i++)
	{
		if(tgap[0][i]=='0') 
		{
			bool flag=bfs(0,i);
			if(flag) return true;
		}
	}
	return false;
}

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&n,&m);
		for(int i=0;i<n;i++) scanf("%s",gap[i]);
		scanf("%d",&year);
		for(int i=1;i<=year;i++)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			px[i]=x,py[i]=y;
		}
		int l=0,r=year,mid=0,ans=0;
		while(r>=l)
		{
			mid=(l+r)>>1;
			if(judge(mid))
			{
				ans=mid;
				l=mid+1;
			}
			else r=mid-1;
		}
		printf("%d\n",ans+1);
	}
return 0;
} 

 

 

<think>嗯,用户问的是关于Vue2和SpringBoot项目二次打包的介绍。首先,我需要明确“二次打包”在这里的具体含义。通常,这可能指的是将已经打包好的前端和后端代码再次整合或重新打包,可能是为了部署或者分发给其他环境使用。 首先,我应该回顾一下Vue2和SpringBoot的标准打包流程。Vue2项目通常使用npm run build生成静态文件,放在dist目录里。而SpringBoot使用Maven或Gradle打包成可执行的JAR或WAR文件,内嵌Tomcat或其他Servlet容器。 二次打包可能的情况包括:将前端静态文件整合到SpringBoot的resources中,这样后端服务可以直接提供前端资源;或者将两者分开部署,但需要确保路径和API对接正确。另外,可能涉及到配置不同的环境变量,比如生产环境和测试环境的API地址不同,这时候二次打包可能需要替换配置文件。 接下来需要考虑用户可能的实际需求。他们可能已经有一个Vue2前端和SpringBoot后端,现在需要重新打包,可能因为环境变化,或者需要优化部署流程。也有可能是分发给客户,需要将两者打包在一起,方便部署。 然后,我需要分步骤解释如何操作。首先是前端打包,Vue的build过程需要注意静态资源的路径,比如publicPath是否正确,避免前端资源加载404。然后是后端打包,确保SpringBoot的配置正确,尤其是如果前端文件被嵌入到后端项目中,需要配置资源处理器,让SpringBoot能正确访问到index.html和静态资源。 另外,可能涉及到跨域问题,如果在二次打包后部署在同一域名下,可以避免跨域,否则可能需要配置后端CORS。还有前端路由的问题,如果使用Vue Router的history模式,后端需要配置捕获所有前端路由的入口,返回index.html,避免404错误。 可能还需要考虑打包后的优化,比如前端代码压缩、缓存策略,后端打包排除不必要的依赖,或者使用Docker容器化部署,这样二次打包可能指的是构建Docker镜像,将前后端都包含进去。 用户可能遇到的常见问题包括静态资源路径错误,后端无法找到前端文件,或者API请求路径不正确。这时候需要检查SpringBoot的静态资源目录配置,以及Vue中axios的baseURL设置是否正确。 此外,二次打包可能涉及自动化脚本,比如使用shell脚本或CI/CD工具(如Jenkins、GitHub Actions)来自动化整个过程,提高效率。 总结来说,回答需要涵盖二次打包的定义、常见场景、具体步骤(前后端分开打包、整合打包)、配置注意事项、常见问题及解决方案,以及可能的自动化部署方法。需要以清晰的结构逐步解释,确保用户能够理解并实施。</think>在 Vue2 + Spring Boot 项目中,“二次打包”通常指将前端(Vue2)和后端(Spring Boot)代码整合后重新构建和打包,以便部署到生产环境。以下是关键步骤和注意事项: --- ### **一、二次打包的典型场景** 1. **前后端分离部署**:前端打包静态文件单独部署,后端打包为 JAR/WAR。 2. **前后端合并部署**:将前端静态文件嵌入 Spring Boot 项目中,后端统一提供服务。 3. **多环境适配**:针对测试、生产等不同环境调整配置后重新打包。 --- ### **二、具体实现步骤** #### **1. 前端(Vue2)打包** - **构建静态文件**: ```bash npm run build # 生成 dist 目录(含 HTML/CSS/JS) ``` - **关键配置**: - 修改 `vue.config.js`,确保 `publicPath` 正确(如 `/` 或子路径 `/app/`)。 - 配置 API 代理或直接指向后端地址(生产环境需关闭开发代理)。 #### **2. 后端(Spring Boot)打包** - **方案一:前后端分离部署** - 前端部署到 Nginx/CDN,后端独立运行。 - 后端打包命令: ```bash mvn clean package # 生成 target/*.jar ``` - 配置 `application.properties`: ```properties server.port=8080 # 允许跨域(若前端独立部署) spring.mvc.cors.allowed-origins=* ``` - **方案二:前后端合并部署** - **将 `dist` 文件复制到 Spring Boot 的 `src/main/resources/static` 目录**。 - 后端配置路由重定向(避免前端路由 404): ```java @Configuration public class WebMvcConfig implements WebMvcConfigurer { @Override public void addViewControllers(ViewControllerRegistry registry) { // 所有未匹配的路径返回 index.html registry.addViewController("/").setViewName("forward:/index.html"); registry.addViewController("/{path:[^\\.]*}").setViewName("forward:/index.html"); } } ``` - 重新打包 Spring Boot,此时 JAR 包包含前端资源。 #### **3. 多环境配置** - **前端**:通过 `.env.production` 等文件配置环境变量(如 API 地址)。 - **后端**:使用 Spring Profile(`application-dev.yml`/`application-prod.yml`)切换配置。 --- ### **三、二次打包的注意事项** 1. **路径问题**: - 前端静态资源路径需与后端路由匹配。 - 避免绝对路径引用(如 `<img src="/images/logo.png">` 需改为相对路径)。 2. **跨域问题**: - 分离部署时,后端需配置 CORS。 - 合并部署时无跨域问题。 3. **缓存问题**: - 前端文件添加哈希指纹(Vue 默认支持),避免浏览器缓存旧版本。 4. **性能优化**: - 前端启用 Gzip 压缩(通过 Nginx 或 `compression-webpack-plugin`)。 - 后端 JAR 包排除无用依赖,减少体积。 --- ### **四、自动化脚本示例** 编写 Shell 脚本实现一键打包: ```bash #!/bin/bash # 打包前端 cd vue-project npm install npm run build rm -rf ../spring-boot-project/src/main/resources/static/* cp -r dist/* ../spring-boot-project/src/main/resources/static/ # 打包后端 cd ../spring-boot-project mvn clean package -DskipTests echo "Build completed! JAR path: target/*.jar" ``` --- ### **五、常见问题** 1. **前端页面空白**:检查 `dist` 文件是否复制到正确位置,或 `publicPath` 配置错误。 2. **接口 404**:确保后端 API 路径与前端请求路径一致(生产环境需关闭 Vue 的代理配置)。 3. **路由跳转失败**:Spring Boot 需配置路由重定向到 `index.html`。 通过以上步骤,可实现 Vue2 + Spring Boot 项目的二次打包与灵活部署。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值