2021杭电多校4补题记录

2024-03-29 08:58

本文主要是介绍2021杭电多校4补题记录,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

总结

lls不在的第一天,想他
数学我** 你个 **

1001 题意

fx是一个由c,cx,c/x,csinx,ccosx,c/sinx,c/cosx,c^x由加号拼接的函数,对他求前缀和一样的东西得到sx,给你fx,问sx是否收敛

1001 思路

高数下练习题
sx收敛,则fx趋0,由高数知识知这些都不趋0,只有常数C均为0时才成立。

1001 代码
#include<stack>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
#include<deque>
#include<vector>
#include<iostream>
#include<map>
#include<set>
#include<iomanip>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
using namespace std;
ll GCD(ll a,ll b){while(b^=a^=b^=a%=b);return a;}
const int inf=0x3f3f3f3f;
string s;
int T;
bool boo;
signed main() 
{#ifndef ONLINE_JUDGEfreopen("IO\\in.txt","r",stdin);freopen("IO\\out.txt","w",stdout);clock_t start, end;start = clock();#endifIOScin>>T;while (T--){cin>>s;boo=false;for (int i=0;i<s.length();i++)if (s[i]>'0'&&s[i]<='9') boo=true;if (boo) cout<<"NO"<<endl;else cout<<"YES"<<endl;}#ifndef ONLINE_JUDGEend = clock();cout << endl << "Runtime: " << (double)(end - start) / CLOCKS_PER_SEC << "s\n";#endif
}
1002 题意

一颗树,点带权,aij代表i到j路径上不同点权数,需输出所有aij和一个奇怪东西的乘积加和

1002 思路

可以n²跑,暴力就完事了。

1002 代码
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib> 
#include<chrono>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long
//#define double long double
using namespace std;typedef long long ll;const int maxn=2505;const int inf=0x3f3f3f3f;const int mod1=1e9+7;const int mod2=1e9+9;int pow_1[maxn],pow_2[maxn];ll pow_m(ll a,ll k,ll p) {ll ans=1;ll tmp=a%p;while(k) {if(k&1)ans=ans*tmp%p;tmp=tmp*tmp%p;k>>=1;}return ans;}int n,m,k;vector<int>e[maxn];int val[maxn];unordered_map<int,int>mp;int ans1,ans2;void dfs(int x,int fa){mp[val[x]]++;//cout<<"x:"<<x<<"mp:"<<mp.size()<<endl;ans1+=(mp.size()*pow_1[x-1])%mod1;ans1%=mod1;ans2+=(mp.size()*pow_2[x-1])%mod2;ans2%=mod2;for(auto y:e[x]){if(y==fa)	continue;dfs(y,x);}int t=mp[val[x]]-1;mp.erase(val[x]);if(t)mp[val[x]]=t;}void solve(){cin>>n;for(int i=1;i<=n;i++)	e[i].clear();for(int i=2;i<=n;i++){int t;cin>>t;e[t].push_back(i);e[i].push_back(t);}for(int i=1;i<=n;i++){cin>>val[i];}for(int i=1;i<=n;i++){ans1=ans2=0;mp.clear();//cout<<"i:"<<i<<"------------"<<endl;dfs(i,0);//cout<<"------------------"<<endl;cout<<ans1<<' '<<ans2<<endl;}}signed main(){IOS#ifndef ONLINE_JUDGEfreopen("IO\\in.txt","r",stdin);freopen("IO\\out.txt","w",stdout);#endifint tn=1;cin>>tn;for(int i=0;i<2005;i++){pow_1[i]=pow_m(19560929,i,mod1);pow_2[i]=pow_m(19560929,i,mod2);}while(tn--){solve();}} 
1008 题意

11走到nn,只能右走或下走,一些点被挡住了过不去,问有多少点到不了

1008 思路

光球层上的黑子 14:02:49
我们按行看,首先一个性质,一行里能到达的点和不能到达的点是一个交替排列的若干连续段。比如我们用0表示可达,1表示不可达,那么某行的可达情况应当是00001110000这种类型

光球层上的黑子 14:05:40
我们考虑行的转移,在这一行上初始不可达点是输入中的点,对于这样的点,它会阻挡人从左方走过来,对于他右侧的点,只有从上方可达转移下来的点才能到,如果这个点右侧的某个点x上方也是不可达的,那么这个点x一定也不可达。也就是说初始不可达点可以向右“染色”,就是找到右方最远的pos,使得pos上方为1也就是不可达。之后将这一段全部染为1.

光球层上的黑子 14:08:19
染色操作和找操作应当都可以使用数据结构优化成log,至于答案就是每一行1的个数,区间查询就行。空间受限肯定不可能开O(n)棵树,显然当前这一行答案只与上一行答案有关,所以我们开两颗树,类似01背包的空间优化那样滚动着用应该就可以了。

以上为和carry嘴的做法,结果最后嘴完也是我自己写,那没事了…

注意特判一个情况,我们在一开始需要独立找一下上一行最左的0位置,在这个位置左边是到不了的,这也是一直的wa点。

1008 代码
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib> 
#include<chrono>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
//#define int long long
//#define double long double
using namespace std;typedef long long ll;const int maxn=200505;const int inf=0x3f3f3f3f;int n,m,k;vector<int>point[maxn];struct tree{int l,r;ll sum;int add;}t1[maxn<<2],t2[maxn<<2];ll ans;inline void build(int root,int l,int r,tree *t){t[root].l=l,t[root].r=r;t[root].add=-1;if(l==r){t[root].sum=0;return ;}int mid=l+r>>1;build(root<<1,l,mid,t);build(root<<1|1,mid+1,r,t);t[root].sum=0;}inline void pushdown(int root,tree *t){if(~t[root].add){t[root<<1].sum=(t[root<<1].r-t[root<<1].l+1)*t[root].add;t[root<<1|1].sum=(t[root<<1|1].r-t[root<<1|1].l+1)*t[root].add;t[root<<1].add=t[root].add;t[root<<1|1].add=t[root].add;t[root].add=-1;}}void update(int root,int l,int r,int x,tree *t){if(l<=t[root].l&&r>=t[root].r){t[root].sum=x*(t[root].r-t[root].l+1);t[root].add=x;return ;}pushdown(root,t);int mid=t[root].l+t[root].r>>1;if(mid>=l)   update(root<<1,l,r,x,t);if(mid<r)   update(root<<1|1,l,r,x,t);t[root].sum=t[root<<1].sum+t[root<<1|1].sum;}int query(int root,int l,int r,tree *t){if(l<=t[root].l&&r>=t[root].r){return t[root].sum;}pushdown(root,t);int mid=t[root].l+t[root].r>>1;int ans=0;if (l<=mid)	ans+=query(root<<1,l,r,t);if (r>mid)	ans+=query(root<<1|1,l,r,t);return ans;}int q_pos(int root,int x,tree *t){if(x>m) return m+1;if(t[root].sum==t[root].r-t[root].l+1)return inf;if(t[root].l==t[root].r){if(t[root].sum==0)  return t[root].l;return inf;}pushdown(root,t);int mid=t[root].l+t[root].r>>1;int ans=inf;if (x<=mid)	ans=min(ans,q_pos(root<<1,x,t));if(ans==inf)ans=min(ans,q_pos(root<<1|1,x,t));return ans;}inline void change(int last,int now){if(now&1){update(1,1,m,0,t2);if(now>1){int p=q_pos(1,1,t1);p=min(p-1,m);update(1,1,p,1,t2);}for(auto x:point[now]){int pos=q_pos(1,x+1,t1);pos=min(pos-1,m);update(1,x,pos,1,t2);}ans-=query(1,1,m,t2);}else{update(1,1,m,0,t1);int p=q_pos(1,1,t2);p=min(p-1,m);update(1,1,p,1,t1);for(auto x:point[now]){int pos=q_pos(1,x+1,t2);pos=min(pos-1,m);update(1,x,pos,1,t1);}ans-=query(1,1,m,t1);}}void solve(){scanf("%d%d%d",&n,&m,&k);ans=1ll*n*m;for(int i=1;i<=n;i++)   point[i].clear();while(k--){int a,b;scanf("%d%d",&a,&b);point[a].emplace_back(b);}build(1,1,m,t1),build(1,1,m,t2);update(1,1,m,1,t1);for(int i=1;i<=n;i++){change(i-1,i);}printf("%lld\n",ans);/* for(int i=1;i<=m;i++)cout<<query(1,i,i,t1)<<' ';cout<<endl;update(1,5,8,1,t1);update(1,11,12,1,t1);for(int i=1;i<=m;i++)cout<<query(1,i,i,t1)<<' ';cout<<endl;cout<<q_sum(1,1,12,t1)<<endl;for(int i=1;i<=m;i++)cout<<q_pos(1,i,t1)<<' ';cout<<endl;  */}signed main(){#ifndef ONLINE_JUDGEfreopen("IO\\in.txt","r",stdin);freopen("IO\\out.txt","w",stdout);#endifint tn=1;scanf("%d",&tn);while(tn--){solve();}} 
1009 题意

给30*100图,里面6个点阵画,让你输出他们的左右边界。

1009 思路

模拟题,我们二维投影到一维,右侧五个点阵画保证连续,扫一下就行,左侧汉字不一定连续,所以先右扫,再左扫。

1009 代码
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib> 
#include<chrono>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
//#define int long long
//#define double long double
using namespace std;typedef long long ll;const int maxn=400505;const int inf=0x3f3f3f3f;int n,m,k;int a[105];void solve(){memset(a,0,sizeof a);for(int i=1;i<=30;i++){for(int j=1;j<=100;j++){char ch;cin>>ch;if(ch=='#')a[j]++;}}vector<pair<int,int> >v;int l,r;bool bl=0;int p=100;while(p&&v.size()<6){if(a[p]){if(!bl){bl=1;r=p;}}else{if(bl){bl=0;l=p;v.push_back({l+1,r});}bl=0;}p--;}for(int i=1;i<=p;i++){if(a[i]){l=i;break;}}for(int i=p;i;i--){if(a[i]){r=i;break;}}v.push_back({l,r});reverse(v.begin(),v.end());for(auto p:v)cout<<p.first<<' '<<p.second<<endl;}signed main(){IOS#ifndef ONLINE_JUDGEfreopen("IO\\in.txt","r",stdin);freopen("IO\\out.txt","w",stdout);#endifint tn=1;cin>>tn;for(int i=1;i<=tn;i++){cout<<"Case #"<<i<<":"<<endl;solve();}} 

未完待续

E 题意
E 思路
E 代码
在这里插入代码片

这篇关于2021杭电多校4补题记录的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/858166

相关文章

Python获取中国节假日数据记录入JSON文件

《Python获取中国节假日数据记录入JSON文件》项目系统内置的日历应用为了提升用户体验,特别设置了在调休日期显示“休”的UI图标功能,那么问题是这些调休数据从哪里来呢?我尝试一种更为智能的方法:P... 目录节假日数据获取存入jsON文件节假日数据读取封装完整代码项目系统内置的日历应用为了提升用户体验,

Spring Boot 配置文件之类型、加载顺序与最佳实践记录

《SpringBoot配置文件之类型、加载顺序与最佳实践记录》SpringBoot的配置文件是灵活且强大的工具,通过合理的配置管理,可以让应用开发和部署更加高效,无论是简单的属性配置,还是复杂... 目录Spring Boot 配置文件详解一、Spring Boot 配置文件类型1.1 applicatio

MySQL INSERT语句实现当记录不存在时插入的几种方法

《MySQLINSERT语句实现当记录不存在时插入的几种方法》MySQL的INSERT语句是用于向数据库表中插入新记录的关键命令,下面:本文主要介绍MySQLINSERT语句实现当记录不存在时... 目录使用 INSERT IGNORE使用 ON DUPLICATE KEY UPDATE使用 REPLACE

Python 中的异步与同步深度解析(实践记录)

《Python中的异步与同步深度解析(实践记录)》在Python编程世界里,异步和同步的概念是理解程序执行流程和性能优化的关键,这篇文章将带你深入了解它们的差异,以及阻塞和非阻塞的特性,同时通过实际... 目录python中的异步与同步:深度解析与实践异步与同步的定义异步同步阻塞与非阻塞的概念阻塞非阻塞同步

Python Dash框架在数据可视化仪表板中的应用与实践记录

《PythonDash框架在数据可视化仪表板中的应用与实践记录》Python的PlotlyDash库提供了一种简便且强大的方式来构建和展示互动式数据仪表板,本篇文章将深入探讨如何使用Dash设计一... 目录python Dash框架在数据可视化仪表板中的应用与实践1. 什么是Plotly Dash?1.1

Spring Boot中定时任务Cron表达式的终极指南最佳实践记录

《SpringBoot中定时任务Cron表达式的终极指南最佳实践记录》本文详细介绍了SpringBoot中定时任务的实现方法,特别是Cron表达式的使用技巧和高级用法,从基础语法到复杂场景,从快速启... 目录一、Cron表达式基础1.1 Cron表达式结构1.2 核心语法规则二、Spring Boot中定

国内环境搭建私有知识问答库踩坑记录(ollama+deepseek+ragflow)

《国内环境搭建私有知识问答库踩坑记录(ollama+deepseek+ragflow)》本文给大家利用deepseek模型搭建私有知识问答库的详细步骤和遇到的问题及解决办法,感兴趣的朋友一起看看吧... 目录1. 第1步大家在安装完ollama后,需要到系统环境变量中添加两个变量2. 第3步 “在cmd中

Spring Retry 实现乐观锁重试实践记录

《SpringRetry实现乐观锁重试实践记录》本文介绍了在秒杀商品SKU表中使用乐观锁和MybatisPlus配置乐观锁的方法,并分析了测试环境和生产环境的隔离级别对乐观锁的影响,通过简单验证,... 目录一、场景分析 二、简单验证 2.1、可重复读 2.2、读已提交 三、最佳实践 3.1、配置重试模板

在 Spring Boot 中使用异步线程时的 HttpServletRequest 复用问题记录

《在SpringBoot中使用异步线程时的HttpServletRequest复用问题记录》文章讨论了在SpringBoot中使用异步线程时,由于HttpServletRequest复用导致... 目录一、问题描述:异步线程操作导致请求复用时 Cookie 解析失败1. 场景背景2. 问题根源二、问题详细分

关于Spring @Bean 相同加载顺序不同结果不同的问题记录

《关于Spring@Bean相同加载顺序不同结果不同的问题记录》本文主要探讨了在Spring5.1.3.RELEASE版本下,当有两个全注解类定义相同类型的Bean时,由于加载顺序不同,最终生成的... 目录问题说明测试输出1测试输出2@Bean注解的BeanDefiChina编程nition加入时机总结问题说明