qzezoj 1574 Chewbacca

题面传送门
这道题似乎是板子,就是裸的 L C A LCA LCA,然后我就打了个暴力 L C A LCA LCA过掉了。
思路:先把两个点提到同一层,然后一起向上提,直到提到同一个节点停止,计算答案。
因为是满二叉树,所以时间复杂度 O ( k l o g m n ) O(klog^mn) O(klogmn)
代码实现:

#include<cstdio>
#define abs(x) ((x)>0?(x):-(x))
using namespace std;
long long n,m,k,tot,pus,ans,x,y,now,fs,f;
inline void swap(long long &x,long long &y){x^=y,y^=x,x^=y;}
inline void read(long long &x){
	char s=getchar();x=0;
	while(s<'0'||s>'9') s=getchar();
	while(s>='0'&&s<='9') x=(x<<3)+(x<<1)+(s^48),s=getchar();
}
int main(){
	register int i,j;
	scanf("%lld%lld%lld",&n,&m,&k);
	for(i=1;i<=k;i++){
		read(x);read(y);
		//printf("%lld %lld\n",x,y);
		if(x>y) swap(x,y);
		if(k==1){printf("%lld\n",y-x);continue;}
		tot=x;
		pus=0;
		while(tot!=1) pus++,tot=(tot-2)/m+1;
		pus++;
		ans=1;now=1;
		for(j=1;j<=pus;j++) ans+=now,now*=m;
		ans--;
		//printf("%lld\n",pus);
		fs=f=0;
		while(y>ans) y=(y-2)/m+1,f++;
		while(x!=y) y=(y-2)/m+1,x=(x-2)/m+1,f+=2;
		printf("%lld\n",f);
	}
}

似乎可以用倍增做到 O ( m l o g k l o g 2 n ) O(mlog^klog^2n) O(mlogklog2n),还不用担心被卡,但我打不来 q w q qwq qwq

好的,我了解了。首先,您需要创建一个新的 GitHub 仓库来存储您的前端代码。然后,您可以使用 HTML、CSS 和 JavaScript 来编写您的星球大战前端页面。 以下是一个简单的代码示例,用于创建一个基本的星球大战页面: ```html <!DOCTYPE html> <html> <head> <title>Star Wars</title> <link rel="stylesheet" href="style.css"> <script src="script.js"></script> </head> <body> <header> <h1>Star Wars</h1> <nav> <ul> <li><a href="#">Home</a></li> <li><a href="#">Movies</a></li> <li><a href="#">Characters</a></li> <li><a href="#">Planets</a></li> </ul> </nav> </header> <main> <section> <h2>Featured Movie</h2> <div class="movie-container"> <img src="https://images.unsplash.com/photo-1589945381786-1b2a2b6f7a6d?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTZ8fHN0YXIlMjB3YXJzfGVufDB8fDB8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" alt="Star Wars Episode IX: The Rise of Skywalker"> <h3>Star Wars Episode IX: The Rise of Skywalker</h3> <p>The surviving members of the resistance face the First Order once again, and the legendary conflict between the Jedi and the Sith reaches its peak bringing the Skywalker saga to its end.</p> </div> </section> <section> <h2>Featured Character</h2> <div class="character-container"> <img src="https://images.unsplash.com/photo-1617129213797-9c9f13b38f6b?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8Y2hhcmFjdGVyJTIwYmFzdGFyZGVuJTIwcGxhbmV0fGVufDB8fDB8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" alt="Chewbacca"> <h3>Chewbacca</h3> <p>Chewbacca, a legendary Wookiee warrior and co-pilot of the Millennium Falcon, played a vital role in the Galactic Civil War and the Clone Wars.</p> </div> </section> <section> <h2>Featured Planet</h2> <div class="planet-container"> <img src="https://images.unsplash.com/photo-1617129475124-bc4b6d4f08c8?ixid=MnwxMjA3fDB8MHxzZWFyY2h8M3x8cGxhbmV0JTIwZGVzaWdufGVufDB8fDB8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" alt="Tatooine"> <h3>Tatooine</h3> <p>Tatooine is a desert planet located in the Outer Rim of the galaxy. It is known for its many inhabitants, including Jawas, Tusken Raiders, and the Hutts.</p> </div> </section> </main> <footer> <p>© 2021 Star Wars. All rights reserved.</p> </footer> </body> </html> ``` 然后,您可以使用 CSS 样式表来定义您的页面的外观和样式,例如: ```css body { font-family: Arial, sans-serif; background-color: #000; color: #fff; } header { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; background-color: #333; } h1 { font-size: 4rem; margin: 0; } nav ul { display: flex; list-style: none; margin: 0; padding: 0; } nav li { margin: 0 20px; } nav a { color: #fff; text-decoration: none; } main { display: flex; flex-wrap: wrap; justify-content: space-between; padding: 50px; } section { flex-basis: 30%; margin-bottom: 50px; } .movie-container, .character-container, .planet-container { display: flex; flex-direction: column; align-items: center; text-align: center; } img { max-width: 100%; height: auto; margin-bottom: 20px; } h3 { font-size: 2rem; margin: 0; } p { line-height: 1.5; margin: 0; } footer { text-align: center; padding: 20px; background-color: #333; } ``` 最后,您可以使用 JavaScript 来为您的页面添加一些交互性和动态效果,例如: ```js const movieContainer = document.querySelector('.movie-container'); const characterContainer = document.querySelector('.character-container'); const planetContainer = document.querySelector('.planet-container'); movieContainer.addEventListener('click', () => { alert('You clicked on the featured movie!'); }); characterContainer.addEventListener('mouseover', () => { characterContainer.classList.add('highlighted'); }); characterContainer.addEventListener('mouseout', () => { characterContainer.classList.remove('highlighted'); }); planetContainer.addEventListener('click', () => { planetContainer.innerHTML = '<img src="https://images.unsplash.com/photo-1599219391627-23cfd3f8bf44?ixid=MnwxMjA3fDB8MHxzZWFyY2h8OHx8cGxhbmV0JTIwZGVzaWduJTIwYmFzdGFyZGVuJTIwcGxhbmV0fGVufDB8fDB8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" alt="Alderaan"><h3>Alderaan</h3><p>Alderaan was a planet located in the Core Worlds known for its peaceful culture and beautiful landscapes, until it was destroyed by the Death Star.</p>'; }); ``` 当然,这只是一个简单的示例。您可以根据自己喜好和需求进行更改和扩展。祝您好运!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值