11_15

news/2025/12/13 14:41:19/文章来源:https://www.cnblogs.com/Nexus-Raphael/p/19226576

11_15做题总结

今天来讲两个题目,一个是昨天的D1,一个是自己找的D4的E

D1

序列一开始从1到1e12

输入x,y,k做x次操作,然后找到每次在数列中删掉下标是y的倍数的数,求操作完之后第k号数

先特判,如果y=-1或者暴力的边更新边删完x次n/y后n<k,那么就输出-1

否则从最后一次反解出第k号元素的初始值

令新元素B是A删完A/y后的第k号数

A=q*y+r

B=A-q

所以B=q*(y-1)+r

这个时候就要对r分情况讨论了

如果r=y-1,即x整除y-1,(因为r不可能=0,否则A不存在)

此时q=B/(y-1)-1,A=B+[B/(y-1)]-1

如果r不等于y-1,即x不整除y-1那么q=B/(y-1),r=A%(y-1),A=B+[B/(y-1)]

综合一下,A=B+[(B-1)/(y-1)],涵盖了两种情况,这里很神

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define vi vector<int> 
#define pb push_back 
#define pii pair<int,int>
#define endl '\n'
const int INF=1e18,N=2e5,MOD=1e9+7;void solve(){int x,y,k;cin>>x>>y>>k;if(y==1){cout<<-1<<endl;return ;}int n=1000000000000;for(int i=0;i<x;i++){n=n-n/y;}if(k>n){ cout<<-1<<endl;return ;}int ans=k;for(int i=0;i<x;i++) ans=ans+(ans-1)/(y-1);cout<<ans<<endl;
}signed main(){ios::sync_with_stdio(false);cin.tie(0);int T=1;cin>>T;while(T--)solve();return 0;
}

E

一棵树,枚举每个点作为根节点时,求任意k个点形成的LCA的种数.输出每个点作为根节点时的和

其实不需要求LCA,每次找一棵根节点是i的子树,找树里面的k-1ge3点和它自己作为集合,这个集合的LCA就是i,如果根节点是子树外面的话,///其实如果根节点在里面也可以这样算,只不过答案加的值要变换一下

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define vi vector<int> 
#define pb push_back 
#define pii pair<int,int>
#define endl '\n'
const int INF=1e18,N=2e5,MOD=1e9+7;
vector<int>g[N+5];
int sz[N+5];
void dfs(int u,int fa){for(int v:g[u]){if(v!=fa){dfs(v,u);sz[u]+=sz[v];}}
}void solve(){int n,k;cin>>n>>k;memset(sz,0,sizeof(sz));for(int i=0;i<=n;i++) g[i].clear();for(int i=0;i<n-1;i++){int u,v;cin>>u>>v;g[u].pb(v);g[v].pb(u);}for(int i=0;i<=n;i++) sz[i]=1;dfs(1,0);int ans=0;for(int i=1;i<=n;i++){if(sz[i]>=k) ans+=n-sz[i];if(n-sz[i]>=k) ans+=sz[i];}cout<<ans+n<<endl;
}signed main(){ios::sync_with_stdio(false);cin.tie(0);int T=1;cin>>T;while(T--)solve();return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/207136.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

四、Agent原理与ReAct 架构详解 ——《动手学Agent应用开发》学习心得

四、Agent原理与ReAct 架构详解 ——《动手学Agent应用开发》学习心得 ================================================================================== 最近参加了Datawhale开源组织举办的组队学习。本篇的学…

三、Agent 应用开发与落地全景 ——《动手学Agent应用开发》学习心得

三、Agent 应用开发与落地全景 ——《动手学Agent应用开发》学习心得 ================================================================================== 最近参加了Datawhale开源组织举办的组队学习。本篇的学习…

业财一体化五步法 - 智慧园区

你有没有在公司遇到过这些情况: 业务部门和财务部门的销售数据和账务数据总是对不上;业务部门卖得飞快,财务部门却发现账户上的钱少了;决策者要靠数据制定策略,结果数据没一个是可用的。 说白了 ,这些问题其实就…

多项式牛顿迭代

【前置知识】泰勒展开。设 \(g\) 是一个光滑的函数,\(g(y)=\sum_{n\ge 0} \frac{g^{n}(y_0)}{n!}(y-y_0)^n\).多项式 exp。 给定多项式 \(a(x)\) 满足 \(a_0=0\),求 \(\exp a(x)\bmod x^n\)。 设 \(\exp a(x)=f(x)\)…

Vibe coding All In One

Vibe coding All In One Vibe coding is an artificial intelligence-assisted software development technique popularized by Andrej Karpathy in February 2025. It was named Collins Dictionarys Word of the Ye…

路径计数与反射容斥

【路径计数模型】 【卡特兰数】 组合意义:从 \((0,0)\) 走到 \((n,n)\),每次向右或者向上,不严格越过对角线的方案数。 它也和长度为 \(2n\) 的合法括号序列个数相等。各种问题都可以转化为卡特兰数。 回忆一下卡特…

Day21浮动

1.浮动的基本使用 <!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-sc…

KEYDIY KD B12-3 3-Button Ford Flip Key Remote - 5pcs/lot (Replacement for Ford Vehicles)

## Problem: Key Replacements for Ford Vehicles – A Costly and Time-Consuming Hassle For European and American automotive repair shops and Ford vehicle owners, replacing lost or damaged keys can feel l…

Spring AI Alibaba 项目源码学习(七)-Agent、BaseAgent、ReactAgent 分析

Agent、BaseAgent、ReactAgent 分析 请关注微信公众号:阿呆-bot 概述 本文档分析 Spring AI Alibaba Agent Framework 中的核心 Agent 类层次结构,包括 Agent 基类、BaseAgent 抽象类和 ReactAgent 具体实现,重点分…

fireworks

fireworks https://github.com/materialsproject/fireworks FireWorks stores, executes, and manages calculation workflows.Website (including documentation): https://materialsproject.github.io/fireworks/ He…

KEYDIY KD ZB28-3 Universal Hyundai Smart Remote Key (5pcs/lot) – Reliable Replacement

## Hyundai Smart Key Woes? Meet the KEYDIY KD ZB28-3 Universal Solution ### Problem: The Frustration of Hyundai Smart Key Replacement When a Hyundai owner’s smart remote key fails, or a mechanic need…

Yanhua Mini ACDP-2 A303 Volvo 2022+ IMMO License for ACDP-2 Module20

**Tackling Modern Volvo IMMO Challenges: The Yanhua Mini ACDP-2 A303 License** Modern Volvo vehicles (2022 and newer) are equipped with advanced Immobilizer (IMMO) systems designed to enhance security.…

西电TIC带鱼杯新生训练赛复盘

传送门 A 最大子树和 P1122 最大子树和 - 洛谷几天前看过一眼,大概知道思路,但是因为忘记ans可能取负而没有一次切掉分析题目要求一个节点带权的树的最大子树和我们用 f [ i ]记录子树以节点 i 为根节点时的最大子树…

C++篇(13)计算器实现 - 指南

C++篇(13)计算器实现 - 指南2025-11-15 22:58 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !importan…

20232306 2025-2026-1 《网络与系统攻防技术》实验五实验报告

1.实验要求 (1)从www.besti.edu.cn、baidu.com、sina.com.cn中选择一个DNS域名进行查询,获取如下信息: DNS注册人及联系方式 该域名对应IP地址 IP地址注册人及联系方式 IP地址所在国家、城市和具体地理位置 PS:使…

完整教程:linux离线环境局域网远程ssh连接vscode

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

第26天(简单题中等题 二分查找、贪心算法)

打卡第二十六天 1道简单题+2道中等题题目:思路: 贪心+二分查找,维护一个"潜在的最优递增序列集合",让每个长度的递增子序列的末尾元素尽可能小,从而为后续元素提供更多的增长可能性。代码: class Solution…

byd秘钥 - MKT

byd秘钥 https://rcorex.github.io/nuttyb-config/

【服务器】服务器被攻击植入了挖矿病毒,CPU一直占用100%,@monthly /root/.cfg/./dealer病毒清除 - 实践

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

牛客101:链表 - 教程

牛客101:链表 - 教程2025-11-15 22:39 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-…