学习笔记17:AtCoder Beginner Contest 340

C

C - Divide and Divide (atcoder.jp)

1e17暴力肯定不行

模拟暴力的过程我们发现很多运算是重复的

记忆化一下

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>using namespace std;
typedef long long LL;
#define int long long
typedef pair<int,int> PII;
const int N=1000010;
int a[N];
map<int,int>mp;
int dfs(int now){if(mp.count(now)) return mp[now];if(now==1) return 0;mp[now]=dfs(now/2)+dfs((now+1)/2)+now;return mp[now];
}
void solve(){int n;cin>>n;cout<<dfs(n)<<endl;
}
signed main(){int t=1;//cin>>t;while(t--){solve();}
}

D

https://atcoder.jp/contests/abc340/tasks/abc340_d

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<array>
using namespace std;
typedef long long LL;
#define int long long
typedef pair<int,int> PII;
const int N=1000010;
int a[N],b[N],c[N];
int dp[N][2];
std::vector<array<int,2>>v[N];
int dist[N];
bool st[N];
void dij(){priority_queue<array<int,2>,vector<array<int,2>>,greater<array<int,2>>>q;q.push({dist[1],1});while(q.size()){auto t=q.top();q.pop();if(st[t[1]]) continue;st[t[1]]=1;for(auto c:v[t[1]]){if(dist[c[0]]>dist[t[1]]+c[1]){dist[c[0]]=dist[t[1]]+c[1];q.push({dist[c[0]],c[0]});}}}
}
void solve(){int n;cin>>n;for(int i=2;i<=n;i++){dist[i]=1e18;}for(int i=1;i<n;i++){cin>>a[i]>>b[i]>>c[i];v[i].push_back({i+1,a[i]});v[i].push_back({c[i],b[i]});}dij();cout<<dist[n]<<endl;
}
signed main(){int t=1;//cin>>t;while(t--){solve();}
}

E

https://atcoder.jp/contests/abc340/tasks/abc340_e

线段树处理

操作:查询在位置上的值sum,然后修改这个该位置的值为y

        然后给整个数组加上sum/n,特殊情况还有剩余的手玩一下模拟即可

        

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<array>
using namespace std;
typedef long long LL;
#define int long long
typedef pair<int,int> PII;
const int N=1000010;
int a[N],b[N],c[N];
struct Node
{int l, r;int sum,tag;
}tr[N * 4];void pushup(int u)
{tr[u].sum=tr[u<<1].sum+tr[u<<1|1].sum;
}void pushdown(int u)
{if(tr[u].tag){tr[u<<1].tag+=tr[u].tag;tr[u<<1|1].tag+=tr[u].tag;tr[u<<1].sum+=tr[u].tag;tr[u<<1|1].sum+=tr[u].tag;tr[u].tag=0;}
}void build(int u, int l, int r)
{if (l == r) tr[u] = {l, r,a[r],0};else{tr[u] = {l, r,0,0};int mid = l + r >> 1;build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);pushup(u);}
}void update(int u, int l, int r, int d)
{if (tr[u].l >= l && tr[u].r <= r){tr[u].sum+=d;tr[u].tag+=d;}else{pushdown(u);int mid = tr[u].l + tr[u].r >> 1;if (l <= mid) update(u << 1, l, r, d);if (r > mid) update(u << 1 | 1, l, r, d);pushup(u);}
}int query(int u, int l, int r)
{if (tr[u].l >= l && tr[u].r <= r){return tr[u].sum;  }else{pushdown(u);int mid = tr[u].l + tr[u].r >> 1;int res = 0;if (l <= mid ) res = query(u << 1, l, r);if (r > mid) res += query(u << 1 | 1, l, r);return res;}
}void solve(){int n,m;cin>>n>>m;for(int i=1;i<=n;i++){cin>>a[i];}build(1,1,n);for(int i=1;i<=m;i++){cin>>b[i];b[i]++;int sum=query(1,b[i],b[i]);update(1,b[i],b[i],-sum);int tmp=sum/n;update(1,1,n,tmp);tmp=sum-tmp*n;if(tmp){if(tmp<=n-b[i]){if(b[i]+1<=n)update(1,b[i]+1,b[i]+tmp,1);}else{if(b[i]+1<=n)update(1,b[i]+1,n,1);tmp-=n-b[i];update(1,1,tmp,1);}}}for(int i=1;i<=n;i++) cout<<query(1,i,i)<<" ";
}
signed main(){int t=1;while(t--){solve();}
}

F

根据叉积求面积公式

S=\frac{1}{2}abs\left ( \left (x2-x1 \right ) \cdot \left (y3-y1 \right )-\left (y2-y1 \right ) \cdot \left (x3-x1 \right )\right )

这道题中x1=0,y1=0,S=1

转化成

2=x2 \cdot y3 - y2 \cdot x3

现在x2和y2我们已经知道

通过扩展欧几里得我们可以算出

gcd(a,b)=a \cdot x - b \cdot y

这个公式的x,y的一组解(无解的情况:2%gcd(a,b)!=0)

这时候将x*gcd(a,b),y*gcd(a,b)即可得到答案

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
using namespace std;
typedef long long LL;
#define int long long
typedef pair<int,int> PII;
const int N=1000010;
int a[N];
int exgcd(int a,int b,int &x,int &y){if(!b){x=1,y=0;return a;}int d=exgcd(b,a%b,y,x);y-=a/b*x;return d;
}
void solve(){int x,y,a,b;cin>>x>>y;//S=1/2*((x2-x1)*(y3-y1)-(y2-y1)*(x3-x1))//在本题中x1=0 y1=0,2=(已知)x2*y3-(已知)y2*x3//无解的情况2%gcd(x2,-y2)!=0int g=exgcd(x,-y,a,b);if(2%g){cout<<-1<<endl;}else{a*=2/g;b*=2/g;cout<<b<<" "<<a<<endl;}
}
signed main(){int t=1;//cin>>t;while(t--){solve();}
}

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

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

相关文章

关于npmlink的问题

深入浅出关于Npm linl的问题 关键词&#xff1a; vue3报错 Uncaught TypeError: Cannot read properties of null (reading ‘isCE‘) at renderSlot npm link 无法实现热更新 我的开发环境是 “vue”: “^3.2.13” 今天在使用 rollup搭建组件库的时候我发现我的组件库不能…

第22讲基于springboot+vue权限系统二次开发环境准备

基于springbootvue权限系统二次开发环境准备 基于这个系统二次开发&#xff0c;不重复造轮子&#xff1b; 基于这个系统二次开发&#xff0c;不重复造轮子&#xff1b; 一&#xff0c;权限系统环境准备 二&#xff0c;数据库表整合投票系统数据库 二&#xff0c;修改标题&a…

Vue中@change、@input和@blur、@focus的区别及@keyup介绍

Vue中change、input和blur、focus的区别及keyup介绍 1. change、input、blur、focus事件2. keyup事件3. 补充&#xff1a;el-input的change事件自定义传参 1. change、input、blur、focus事件 change在输入框发生变化且失去焦点后触发&#xff1b; input在输入框内容发生变化后…

QRegExp的学习

【QT学习】QRegExp类正则表达式&#xff08;一文读懂&#xff09;-CSDN博客 [ ]:匹配括号内输入的任意字符 例&#xff1a;[123]:可以是1或2或3 {m&#xff0c;n}表达式至少重复m次&#xff0c;至多重复n次。 例&#xff1a;"ba{1,3}"可以匹配 "ba"或&…

贪心算法练习day1

练习1--翻硬币 1&#xff09;题目及要求 2&#xff09;解题思路 输入的是字符串&#xff0c;要想将两组字符串进行一一对比&#xff0c;需要将字符串转换成字符数组&#xff0c;再使用for循环依次遍历字符数组&#xff0c;进行比对。 输入两行字符串&#xff0c;转换成两个字…

干货 | 实战演练基于加密接口测试测试用例设计

如果接口测试仅仅只是掌握一些requests或者其他一些功能强大的库的用法&#xff0c;是远远不够的&#xff0c;还需要具有根据公司的业务以及需求去定制化一个接口自动化测试框架能力。所以在这个部分&#xff0c;会主要介绍接口测试用例分析以及通用的流程封装是如何完成的。 首…

Java实现课程案例资源库系统 JAVA+Vue+SpringBoot+MySQL

目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块2.1 管理员需求分析2.2 用户需求分析 三、系统设计3.1 业务流程设计3.1.1 管理员业务流程设计3.1.2 用户业务流程设计3.1.3 首页功能模块及业务流程分析3.1.4 案例资源中心功能模块及业务流程分析3.1.5 用户信息中心功能模块…

html从零开始7:文档流、浮动、清除浮动,定位【搬代码】

文档流 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta http-equiv"X-UA-Compatible" content"IEedge"><meta name"viewport" content"widthdevice-width, init…

甲亢和糖尿病有什么关系吗?

甲亢和糖尿病之间的关系是一个备受关注的话题&#xff0c;两者之间确实存在一定的关联。这种关联可以从多个角度进行探讨。 首先&#xff0c;甲亢和糖尿病都是内分泌系统的疾病。甲亢是由于甲状腺激素分泌过多引起的&#xff0c;而糖尿病则是由于胰岛素分泌不足或作用障碍导致…

树莓派4B(Raspberry Pi 4B)使用docker搭建阿里巴巴sentinel服务

树莓派4B&#xff08;Raspberry Pi 4B&#xff09;使用docker搭建阿里巴巴sentinel服务 由于国内访问不了docker hub&#xff0c;而国内镜像仓库又没有适配树莓派ARM架构的sentinel镜像&#xff0c;所以我们只能退而求其次——自己动手构建镜像。本文基于Ubuntu&#xff0c;Jav…

Pycharm配置运行selenium教程

一、下载chrome浏览器和同版本的chromedriver chrome测试版版本120.0.6099.109 链接&#xff1a;https://pan.baidu.com/s/1pvFqL0WN8OkqPmURAs83kg?pwdvtsh 提取码&#xff1a;vtsh chromedriver版本120.0.6099.109 链接&#xff1a;https://pan.baidu.com/s/16fWWkrlD5C3J…

猫头虎分享已解决Bug || TypeError: Cannot read property ‘match‘ of undefined

博主猫头虎的技术世界 &#x1f31f; 欢迎来到猫头虎的博客 — 探索技术的无限可能&#xff01; 专栏链接&#xff1a; &#x1f517; 精选专栏&#xff1a; 《面试题大全》 — 面试准备的宝典&#xff01;《IDEA开发秘籍》 — 提升你的IDEA技能&#xff01;《100天精通鸿蒙》 …

Innodb事务的实现

事务的实现 MySQL在进行事务处理的时候采用了日志先行的方式来保证事务可快速和持久运行&#xff0c;在写数据之前&#xff0c;先写日志&#xff0c;开始事务时&#xff0c;会记录该事务的一个LSN日志序列号&#xff1b;当执行事务时&#xff0c;会往Innodb_log_buffer日志缓冲…

c语言操作符(下)

目录 ​编辑 逗号表达式 下标访问[] 函数调⽤() sizeof 结构成员访问操作符 结构体 结构体声明 直接访问 .成员名 间接访问 结构体指针->成员名 逗号表达式 exp1, exp2, exp3, …expN 运算规则&#xff1a;从左向右依次执⾏。整个表达式的结果是最后⼀个表达…

LInux、源码编译安装

步骤&#xff1a; 步骤1&#xff1a;安装开发工具gcc与make&#xff0c;释放源代码至指定目录 yum -y install gcc make 步骤2&#xff1a;tar解包&#xff0c;释放源代码至指定目录 tar -xf /root/tools.tar.gz -C /usr/local 步骤3&#xff1a;./configure 配置&#xff0c;…

网络编程socket相关操作

Socket socket 打开一个网络连接 int socket (int family , int type ,int protocol)family :协议族 , type : 套接字类型 , protocol :协议类型常值 套接字描述符sockfd famliy : AF_INET(IPv4) AF_INET6(IPv6) AF_LOCAL AF_ROUTE type : SOCK_STREAM(字节流套接字) SOCK_…

第一篇【传奇开心果系列】Python的pyttsx3库技术点案例示例:文本转换语言

传奇开心果短博文系列 系列短博文目录Python的pyttsx3库技术点案例示例系列 短博文目录前言一、pyttsx3主要特点和功能介绍二、pyttsx3文字转语音操作步骤介绍三、多平台支持介绍和示例代码四、多语言支持介绍和示例代码五、自定义语言引擎介绍和示例代码六、调整语速和音量介绍…

Transformer?

Transformer模型是一种深度学习架构&#xff0c;它在2017年由Vaswani等人在论文《Attention is All You Need》中首次提出。这种架构特别适用于处理序列数据&#xff0c;如文本、音频或时间序列数据&#xff0c;因此在自然语言处理(NLP)、语音识别和时序分析等领域有着广泛的应…

姿态传感器MPU6050模块之陀螺仪、加速度计、磁力计

MEMS技术 微机电系统&#xff08;MEMS, Micro-Electro-Mechanical System&#xff09;&#xff0c;也叫做微电子机械系统、微系统、微机械等&#xff0c;指尺寸在几毫米乃至更小的高科技装置。微机电系统其内部结构一般在微米甚至纳米量级&#xff0c;是一个独立的智能系统。 微…

Win11 Android studio 打开新项目提示 Microsoft Defender configuration 问题解决

Microsoft Defender configuration The IDE has detected Microsoft Defender with Real-Time Protection enabled. It might severely degrade IDE performance. It is recommended to make sure the following paths are added to the Defender folder exclusion list 。。…