当前位置:网站首页>[Educational Codeforces Round 80] 解题报告
[Educational Codeforces Round 80] 解题报告
2022-04-23 06:21:00 【Zimba_】
A. Deadline
题意:
给你一个n和d (1≤n≤109, 1≤d≤109) ,问是否存在自然数x,使得 x + ⌈ d x + 1 ⌉ ⩽ n x+\left \lceil \frac{d}{x+1}\right \rceil\leqslant n x+⌈x+1d⌉⩽n。存在输出YES,不存在输出NO。
题解:
节约推公式的时间,就写了一个o( n \sqrt{n} n)的暴力,从0到 d \sqrt{d} d枚举x,再判断式子是否成立即可。
B. Yet Another Meme Problem:
题意:
有t(1≤t≤100) 组样例,每组样例给出两个整数A and B (1≤A,B≤109),问有多少对(a,b)满足1≤a≤A,1≤b≤B,且ab+a+b=conc(a,b)。其中conc(a,b)表示数字的字符连接,如conc(12,23)=1223。
题解:
设b的数字位数为w,则有ab+a+b=a⋅10w+b。整理得a⋅(10w-b-1)=0。因为a>0,得到b=10w-1,即9,99,999……剩下就不说了。
C. Two Arrays
题意:
给定n和m (1≤n≤1000, 1≤m≤10)。问有多少对数组a和b满足:
1.数组a和b长度均为m。
2.a和b的元素均为1到n的整数。
3.对于i从1到m每一位,有ai ≤ bi成立。
4.数组a为非递减数组。
5.数组b为非递增数组。
答案模1e9+7。
题解:
容易发现,只要两数组的最后一位满足条件3,根据条件4和5,可以得到条件3必定成立。于是乎,我们两层循环枚举两数组最后一位,此时我们还需要知道,为了满足条件2,3,4,且最后一位给定,还有多少情况即可,可以用dp数组预处理,dp[i][j]表示长度为i的数组,上升空间为j的数组有多少种情况。就ok了。代码如下(m为1的特判纯属是因为发现过不了样例):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll dp[15][1005];
int main()
{
ll n,m;
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;i++)dp[1][i]=i;
for(int i=2;i<=10;i++)
{
for(int j=1;j<=1000;j++)
{
for(int k=1;k<=j;k++)
{
dp[i][j]=(dp[i][j]+dp[i-1][k])%mod;
}
}
}
ll ans=0;
if(m!=1)
{
for(int b=1;b<=n;b++)
{
for(int a=1;a<=b;a++)
{
ans=(ans+dp[m-1][a]*dp[m-1][n-b+1])%mod;
}
}
}
else
{
ans=n*(n+1)/2%mod;
}
printf("%lld\n",ans);
return 0;
}
D. Minimax Problem
这题被hack了,很气,就不贴代码了。但思路应该没问题。
题意:
给定n个数组,每个数组长度为m。(1≤n≤3⋅105, 1≤m≤8)
选择其中两个数组ai和aj(可以是同一个),定义数组b为
要求这两个数组的其中一种选法,使得
输出选择的数组的下标。
题解:
首先想到二分这个最小值的最大值,然后考虑如何check。
如果存在两个数组,使得每一位上的最大值大于当前二分值,则check成功。
如果暴力枚举两数组,做法o(n²)显然过不了。
m只有8,考虑转化成二进制。
check当前二分值p的思路:把每个数组转化成二进制数,转化方式为,如果当前位的数大于等于p,则二进制下该位为1,否则为0。然后就会发现当存在两个数的或值为2m-1,则check成功。而m只有8,可能出现的二进制值不过256。所以可以用一个长度为256的数组记录这一个数是否出现,然后暴力两层循环判断是否存在两个数满足条件。
E. Messenger Simulator
题意:
这是一道题目背景比模型化后的题意更好理解的题。就是消息列表里有n个人的消息,编号从1到n,在列表里从上到下的顺序也是1到n的一个排列。
当某个人给你发消息后,他在列表中的位置会瞬间蹦到第一个,而在他之前的人会往后移一格。
初始时列表里从上到下是1到n。
现在给你一个n和m (1≤n,m≤3⋅105)表示n个人, 在初始情况后又收到m条消息。
接下来m个数,表示收到的是谁的消息。
要求输出每个人的消息在列表中最靠前和最靠后的位置。
样例:
题解:
首先,容易处理出最靠前的位置。当这个人发过消息,那他最靠前的位置为1,否则为他初始位置。
现在思考最靠后的位置。当一个人出现后,他的位置变成第一,距离他下次变成第一前,这段时间,他的排名会往后掉发过消息的人种数个位置。
比如:1 3 2 2 1,1在变成第一后,往后掉了两个位置。
所以我们要找的就是,对于a来说,两个a之间相隔的数的种类数。
处理边界情况,神奇地想到在开头加上1到n的倒序表示初始化的情况。如样例变成5 4 3 2 1 3 5 1 4
处理起来会更方便。而像2这样只在初始状态时出现的,则从它记录到结尾的那个数即可。
于是乎问题变成了,n个区间,询问区间数的种类数。
用了莫队o(n n \sqrt{n} n)过了。
代码如下:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
int ans1[300005];
int ans2[300005];
int a[600005];
vector<int>v[300005];
typedef struct
{
int l,r,id,B;
}Query;
Query Q[1000005];
bool cmp(Query a,Query b)
{
if(a.B==b.B)return a.r<b.r;
else return a.B<b.B;
}
int mp[300005];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int N=n+m;
int B=sqrt(N);
for(int i=1;i<=n;i++)a[i]=n-i+1,ans1[i]=i;
for(int i=n+1;i<=n+m;i++)scanf("%d",&a[i]),ans1[a[i]]=1;
for(int i=1;i<=N;i++)v[a[i]].push_back(i);
int qn=0;
for(int i=1;i<=n;i++)
{
for(int j=0;j<v[i].size();j++)
{
if(j==v[i].size()-1)Q[qn++]=Query{
v[i][j],N,i,(v[i][j]-1)/B+1};
else Q[qn++]=Query{
v[i][j],v[i][j+1],i,(v[i][j]-1)/B+1};
}
}
sort(Q,Q+qn,cmp);
int l=1,r=1,ans=1;
mp[a[1]]=1;
for(int i=0;i<qn;i++)
{
while(r<Q[i].r){
r++;mp[a[r]]++;if(mp[a[r]]==1)ans++;}
while(l>Q[i].l){
l--;mp[a[l]]++;if(mp[a[l]]==1)ans++;}
while(r>Q[i].r){
mp[a[r]]--;if(mp[a[r]]==0)ans--;r--;}
while(l<Q[i].l){
mp[a[l]]--;if(mp[a[l]]==0)ans--;l++;}
ans2[Q[i].id]=max(ans2[Q[i].id],ans);
}
for(int i=1;i<=n;i++)printf("%d %d\n",ans1[i],ans2[i]);
return 0;
}
F. Red-Blue Graph
没时间了,不会。
版权声明
本文为[Zimba_]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43785386/article/details/103987677
边栏推荐
- PyTorch 22. Pytorch common code snippet collection
- PC端一次启动多个微信
- Take you to travel in space, and American photography technology provides comprehensive technical support for aerospace creative applet
- 不需要破解markdown编辑工具Typora
- PyTorch 17. GPU concurrency
- 按需引入vant组件
- PyTorch 20. Pytorch tips (continuously updated)
- presto日期函数的使用
- remote: Support for password authentication was removed on August 13, 2021.
- UDP基础学习
猜你喜欢
Lead the industry trend with intelligent production! American camera intelligent video production platform unveiled at 2021 world Ultra HD Video Industry Development Conference
基于可视化结构的身份证号码校验系统-树莓派实现
可视化常见绘图(一)堆叠图
How to improve the service efficiency of the hotel without blind spots and long endurance | public and Private Integrated walkie talkie?
Typora操作技巧说明(一).md
Machine vision series (01) -- Overview
可视化常见问题解决方案(八)数学公式
组合数求解与(扩展)卢卡斯定理
USO technology was invited to share the technical framework and challenges of AI synthetic virtual characters at lvson2020 conference
The people of Beifeng have been taking action
随机推荐
数论之阶与原根讲解
PyTorch 14. Module class
Take you to travel in space, and American photography technology provides comprehensive technical support for aerospace creative applet
quill-editor图片缩放、在一个页面使用多个富文本框、quill-editor上传图片地址为服务器地址
van-uploader上传图片实现过程、使用原生input实现上传图片
SQL练习第一题
H5案例开发
免费开源充电桩物联网云平台
pytorch:关于GradReverseLayer实现的一个坑
[ACM-ICPC 2018 沈阳赛区网络预赛] J.Ka Chang (分块+dfs序)
Dirichlet 前缀和(数论优化式子复杂度利器)
快速下载vscode的方法
[CF 1425D]Danger of Mad Snakes(组合计数+容斥)
Lead the industry trend with intelligent production! American camera intelligent video production platform unveiled at 2021 world Ultra HD Video Industry Development Conference
Patrol inspection intercom communication system in power industry
1D/1D动态规划学习总结
DMR system solution of Kaiyuan MINGTING hotel of Fengqiao University
Metro wireless intercom system
golang实现一个带Web界面的五险一金计算器
hql求一个范围内最大值