Solution Set -「CF 1490」
「CF 1490A」Dense Array
Link.
显然不满足的 adjacent elements 之间一直加 \(\min\times2,\min\times4,\cdots,\min\times2^{k}\),满足 \(\min\times2^{k}\le\max\) 即可。
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
int t,n,a[60],ans;
bool judge(double one,double ano)
{
return max(one,ano)/min(one,ano)<=2.0;
}
int jump(int one,int ano)
{
int cone=min(one,ano),cano=max(one,ano),res=0;
while(cone<=cano)
{
if((cone<<1)>=cano) break;
else
{
cone<<=1;
res++;
}
}
return res;
}
int main()
{
scanf("%d",&t);
while(t--)
{
ans=0;
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d",&a[i]);
for(int i=2;i<=n;++i) ans+=judge(a[i],a[i-1])?0:jump(a[i],a[i-1]);
printf("%d\n",ans);
}
return 0;
}
「CF 1490B」Balanced Remainders
Link.
把原序列的 \(c_{0\sim2}\) 统计出来然后贪心(具体怎么贪看代码,不好描述)模拟。
#include<cstdio>
#include<algorithm>
using namespace std;
int t,n,a[30010],c[3],ans;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
scanf("%d",&a[i]);
++c[a[i]%3];
}
while((c[0]^c[1])||(c[0]^c[2]))
{
ans++;
if(c[0]==*max_element(c,c+3))
{
--c[0];
++c[1];
}
else if(c[1]==*max_element(c,c+3))
{
--c[1];
++c[2];
}
else
{
--c[2];
++c[0];
}
}
printf("%d\n",ans);
for(int i=0;i<3;++i) c[i]=0;
ans=0;
}
return 0;
}
「CF 1490C」Sum of Cubes
Link.
枚举一个 \(a\),然后判断 \(n-a^{3}\) 是否为完全立方数即可,这个可以二分,注意二分的范围不要乱搞,容易溢出。
#include<cmath>
#include<cstdio>
using namespace std;
int t,flag;
long long n;
long long cud(long long x)
{
return x*x*x;
}
bool check(long long x)
{
long long l=1,r=pow(x,1.0/3.0)+5;
while(l<=r)
{
long long mid=(l+r)>>1;
if(cud(mid)>x) r=mid-1;
else if(cud(mid)<x) l=mid+1;
else return true;
}
return false;
}
int main()
{
scanf("%d",&t);
while(t--)
{
flag=0;
scanf("%lld",&n);
for(int i=1;cud(i)<n;++i)
{
if(check(n-cud(i)))
{
flag=1;
break;
}
}
if(flag) printf("YES\n");
else printf("NO\n");
}
return 0;
}
「CF 1490D」Permutation Transformation
Link.
递归建树,照题意模拟即可。
#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;
vector<int> e[110];
int t,n,a[110],dep[110];
int build(int l,int r)
{
if(l>r) return -1;
int root=0,pos=0;
for(int i=l;i<=r;++i)
{
if(a[i]>root)
{
root=a[i];
pos=i;
}
}
if(l^r)
{
int one=build(l,pos-1),ano=build(pos+1,r);
if(~one) e[root].push_back(one);
if(~ano) e[root].push_back(ano);
return root;
}
else return root;
}
void dfs(int x)
{
for(int i=0;i<e[x].size();++i)
{
int y=e[x][i];
dep[y]=dep[x]+1;
dfs(y);
}
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d",&a[i]);
dfs(build(1,n));
for(int i=1;i<=n;++i) printf("%d ",dep[a[i]]);
printf("\n");
for(int i=1;i<=n;++i)
{
dep[i]=0;
e[i].clear();
}
}
return 0;
}
「CF 1490E」Accidental Victory
Link.
贪心,记录个 id 后排序(看代码吧)。
#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;
vector<int> ans;
pair<long long,int> a[200010];
int t,n;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
scanf("%lld",&a[i].first);
a[i].second=i;
}
sort(a+1,a+n+1);
for(int i=1;i<=n;++i) a[i].first+=a[i-1].first;
ans.push_back(a[n].second);
for(int i=n-1;i>=1;--i)
{
if(a[i].first>=a[i+1].first-a[i].first) ans.push_back(a[i].second);
else break;
}
sort(ans.begin(),ans.end());
printf("%d\n",(int)ans.size());
for(int i=0;i<ans.size();++i) printf("%d ",ans[i]);
printf("\n");
ans.clear();
for(int i=1;i<=n;++i) a[i]=make_pair(0,0);
}
return 0;
}
「CF 1490F」Equalize the Array
Link.
统计出现次数和出现次数的出现次数,然后根号模拟取 \(\min\)。
#include<map>
#include<cstdio>
#include<algorithm>
using namespace std;
const int INF=1e9;
map<int,int> one,ano;
int t,n,a[200010],ans;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
scanf("%d",&a[i]);
++one[a[i]];
}
for(map<int,int>::iterator now=one.begin();now!=one.end();++now) ++ano[now->second];
ans=INF;
int l=0,r=n,c=one.size();
for(map<int,int>::iterator now=ano.begin();now!=ano.end();++now)
{
ans=min(ans,l+r-c*now->first);
l+=now->first*now->second;
r-=now->first*now->second;
c-=now->second;
}
printf("%d\n",ans);
one.clear();
ano.clear();
}
return 0;
}
「CF 1490G」Old Floppy Drive
Link.
denote for \(S\) of the sum of all elements,for \(pre\) of the prefix sum of the origin sequence。
首先判断原 \(pre\) 里面有没有 \(x\),这个搞个 std::map 就有了。
when \(S\le0\and\max\{pre_{i}\}<x\) the answer doesn't exist.
if \(S\ge0\and\not\exists i,s.t.pre_{i}=x\):此时先把 \(x:=x\bmod S\),然后就查 std::map。
但是你会发现这样做写起来非常麻烦,可能需要手写平衡树。
于是你发现读错了题,是 \(\ge x\) 不是 \(=x\) (日你 horse)。
然后负数直接不存进 \(pre\) 然后开两个 std::vector 二分就好了。
#include<vector>
#include<cstdio>
#include<algorithm>
using namespace std;
const long long INF=1e18;
vector<long long> onepre;
vector<int> anopre;
long long x,S,mx,len;
int t,n,m;
int main()
{
scanf("%d",&t);
while(t--)
{
mx=-INF;
S=0;
scanf("%d %d",&n,&m);
for(int i=1;i<=n;++i)
{
scanf("%lld",&x);
S+=x;
if(onepre.empty()||S>*(prev(onepre.end())))
{
onepre.push_back(S);
anopre.push_back(i-1);
}
mx=max(S,mx);
}
// printf("-------------------------\n");
// printf("onemp area:\n");
// for(auto now:onemp)
// {
// printf(" preval=%lld ; preval appearing position=",now.first);
// for(auto won:now.second) printf("%d ",won);
// printf("\n");
// }
// printf("\nanomp area:\n");
// for(auto now:anomp)
// {
// printf("[preval=%lld boolean=%d]\n",now.first,now.second);
// }
// printf("-------------------------\n");
while(m--)
{
// int minuser=0;
scanf("%lld",&x);
if(lower_bound(onepre.begin(),onepre.end(),x)!=onepre.end()) printf("%d ",anopre[lower_bound(onepre.begin(),onepre.end(),x)-onepre.begin()]);
else if(S<=0) printf("-1 ");
else
{
// minuser=((x%S)==0);
len=(mx<x)?((x-mx+S-1)/S):0;
// printf("(%lld %lld %lld %lld)",x,S,x%S,x/S);
printf("%lld ",(lower_bound(onepre.begin(),onepre.end(),x%S)==onepre.end())?(-1):(len*n+anopre[lower_bound(onepre.begin(),onepre.end(),x-len*S)-onepre.begin()])/*((((x%S)==0)?(0):(anopre[lower_bound(onepre.begin(),onepre.end(),x%S)-onepre.begin()]))+(int)(x/S)*len-minuser)*/);
}
}
printf("\n");
onepre.clear();
anopre.clear();
}
return 0;
}
Solution Set -「CF 1490」的更多相关文章
- Diary / Solution Set -「WC 2022」线上冬眠做噩梦
大概只有比较有意思又不过分超出能力范围的题叭. 可是兔子的"能力范围" \(=\varnothing\) qwq. 「CF 1267G」Game Relics 任意一个 ...
- Solution Set -「ARC 107」
「ARC 107A」Simple Math Link. 答案为: \[\frac{a(a+1)\cdot b(b+1)\cdot c(c+1)}{8} \] 「ARC 107B」Quadrup ...
- Solution -「CF 1342E」Placing Rooks
\(\mathcal{Description}\) Link. 在一个 \(n\times n\) 的国际象棋棋盘上摆 \(n\) 个车,求满足: 所有格子都可以被攻击到. 恰好存在 \(k\ ...
- Solution -「CF 1622F」Quadratic Set
\(\mathscr{Description}\) Link. 求 \(S\subseteq\{1,2,\dots,n\}\),使得 \(\prod_{i\in S}i\) 是完全平方数,并最 ...
- Solution -「CF 923F」Public Service
\(\mathscr{Description}\) Link. 给定两棵含 \(n\) 个结点的树 \(T_1=(V_1,E_1),T_2=(V_2,E_2)\),求一个双射 \(\varph ...
- Solution -「CF 923E」Perpetual Subtraction
\(\mathcal{Description}\) Link. 有一个整数 \(x\in[0,n]\),初始时以 \(p_i\) 的概率取值 \(i\).进行 \(m\) 轮变换,每次均匀随机 ...
- Solution -「CF 1586F」Defender of Childhood Dreams
\(\mathcal{Description}\) Link. 定义有向图 \(G=(V,E)\),\(|V|=n\),\(\lang u,v\rang \in E \Leftrightarr ...
- Solution -「CF 1237E」Balanced Binary Search Trees
\(\mathcal{Description}\) Link. 定义棵点权为 \(1\sim n\) 的二叉搜索树 \(T\) 是 好树,当且仅当: 除去最深的所有叶子后,\(T\) 是满的: ...
- Solution -「CF 623E」Transforming Sequence
题目 题意简述 link. 有一个 \(n\) 个元素的集合,你需要进行 \(m\) 次操作.每次操作选择集合的一个非空子集,要求该集合不是已选集合的并的子集.求操作的方案数,对 \(10^9 ...
- Solution -「CF 1023F」Mobile Phone Network
\(\mathcal{Description}\) Link. 有一个 \(n\) 个结点的图,并给定 \(m_1\) 条无向带权黑边,\(m_2\) 条无向无权白边.你需要为每条白边指定边权 ...
随机推荐
- 新版本,ggplot2 v3.3.0 新特性来袭
ggplot2 迎来了新的版本,官方宣布了一些新的特性.下面一起看看吧. 1. 轴代码重写 这有利于解决轴标签重叠的情况. 2. 新的 scale bin,它可以像使用 color, fill 一样使 ...
- Python异步编程之web框架 异步vs同步 数据库IO任务压测对比
测试基本信息 主题:比较异步框架和同步框架在数据库IO操作的性能差异 python版本:python 3.8 数据库:mysql 8.0.27 (docker部署) 压测工具:locust web框架 ...
- 项目小结:使用Docker迁移服务到离线服务器
前言 最近遇到的这个场景,需要把之前开发的一套系统迁移到一个离线的服务器上,这个服务器有点麻烦,接入VPN后通过堡垒机才能访问,速度也很慢,遇到不少坑,本文记录一下迁移过程. 基本信息 原本这套系统也 ...
- 9. SpringMVC处理ajax请求
9.1.@RequestBody @RequestBody 可以获取请求体信息,使用@RequestBody 注解标识控制器方法的形参,当前请求的请求体就会为当前注解所标识的形参赋值 <!--此 ...
- 一次与 ChatGPT 的 .NET 面试问答
以常用问题来面试机器人,机器人是否能够合格 1. 您能描述一下您曾经在.NET项目中集成硬件设备的经历吗?这个过程是怎样的,您面临了哪些挑战? GPT 回答:当我在.NET项目中集成硬件设备时,我首先 ...
- SQL专家云回溯某时间段内的阻塞
背景 SQL专家云像"摄像头"一样,对环境.参数配置.服务器性能指标.活动会话.慢语句.磁盘空间.数据库文件.索引.作业.日志等几十个运行指标进行不同频率的实时采集,保存到SQL专 ...
- 创建属于自己的github、使用git提交、更新代码至github、写好readme
1. 在github上创建一个Repository 点击github网站,你可以用你的邮箱先注册一个账号. 点击New,转到创建一个repository的界面,如下图所示,你可以填写你的Reposit ...
- 零基础实现Java直播(二):实现流程
一.前提条件 在实现Java直播前,请确保: 已在项目中集成 ZEGO Express SDK,详情请参考 快速开始 - 集成. 已在 ZEGO 控制台 创建项目,并申请有效的 AppID 和 App ...
- 如何给Github上的开源项目提交PR?
前言 对于一个热爱开源的程序员而言,学会给GitHub上的开源项目提交PR这是迈出开源的第一步.今天我们就来说说如何向GitHub的开源项目提交PR,当然你提交的PR可以是一个项目的需求迭代.也可以是 ...
- Nginx之数据流代理stream模块简介和使用 ---九五小庞
一.stream模块简介 stream模块一般用于TCP/UDP数据流的代理和负载均衡,通过stream模块我们可以代理转发tcp报文.ngx_stream_core_module模块从1.9.0 ...