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 UV安装、升级、卸载详细步骤记录

《PythonUV安装、升级、卸载详细步骤记录》:本文主要介绍PythonUV安装、升级、卸载的详细步骤,uv是Astral推出的下一代Python包与项目管理器,主打单一可执行文件、极致性能... 目录安装检查升级设置自动补全卸载UV 命令总结 官方文档详见:https://docs.astral.sh/

统一返回JsonResult踩坑的记录

《统一返回JsonResult踩坑的记录》:本文主要介绍统一返回JsonResult踩坑的记录,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录统一返回jsonResult踩坑定义了一个统一返回类在使用时,JsonResult没有get/set方法时响应总结统一返回

Go学习记录之runtime包深入解析

《Go学习记录之runtime包深入解析》Go语言runtime包管理运行时环境,涵盖goroutine调度、内存分配、垃圾回收、类型信息等核心功能,:本文主要介绍Go学习记录之runtime包的... 目录前言:一、runtime包内容学习1、作用:① Goroutine和并发控制:② 垃圾回收:③ 栈和

java对接海康摄像头的完整步骤记录

《java对接海康摄像头的完整步骤记录》在Java中调用海康威视摄像头通常需要使用海康威视提供的SDK,下面这篇文章主要给大家介绍了关于java对接海康摄像头的完整步骤,文中通过代码介绍的非常详细,需... 目录一、开发环境准备二、实现Java调用设备接口(一)加载动态链接库(二)结构体、接口重定义1.类型

apache的commons-pool2原理与使用实践记录

《apache的commons-pool2原理与使用实践记录》ApacheCommonsPool2是一个高效的对象池化框架,通过复用昂贵资源(如数据库连接、线程、网络连接)优化系统性能,这篇文章主... 目录一、核心原理与组件二、使用步骤详解(以数据库连接池为例)三、高级配置与优化四、典型应用场景五、注意事

SpringBoot实现文件记录日志及日志文件自动归档和压缩

《SpringBoot实现文件记录日志及日志文件自动归档和压缩》Logback是Java日志框架,通过Logger收集日志并经Appender输出至控制台、文件等,SpringBoot配置logbac... 目录1、什么是Logback2、SpringBoot实现文件记录日志,日志文件自动归档和压缩2.1、

qtcreater配置opencv遇到的坑及实践记录

《qtcreater配置opencv遇到的坑及实践记录》我配置opencv不管是按照网上的教程还是deepseek发现都有些问题,下面是我的配置方法以及实践成功的心得,感兴趣的朋友跟随小编一起看看吧... 目录电脑环境下载环境变量配置qmake加入外部库测试配置我配置opencv不管是按照网上的教程还是de

使用nohup和--remove-source-files在后台运行rsync并记录日志方式

《使用nohup和--remove-source-files在后台运行rsync并记录日志方式》:本文主要介绍使用nohup和--remove-source-files在后台运行rsync并记录日... 目录一、什么是 --remove-source-files?二、示例命令三、命令详解1. nohup2.

Java使用SLF4J记录不同级别日志的示例详解

《Java使用SLF4J记录不同级别日志的示例详解》SLF4J是一个简单的日志门面,它允许在运行时选择不同的日志实现,这篇文章主要为大家详细介绍了如何使用SLF4J记录不同级别日志,感兴趣的可以了解下... 目录一、SLF4J简介二、添加依赖三、配置Logback四、记录不同级别的日志五、总结一、SLF4J

在Spring Boot中浅尝内存泄漏的实战记录

《在SpringBoot中浅尝内存泄漏的实战记录》本文给大家分享在SpringBoot中浅尝内存泄漏的实战记录,结合实例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录使用静态集合持有对象引用,阻止GC回收关键点:可执行代码:验证:1,运行程序(启动时添加JVM参数限制堆大小):2,访问 htt