「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」的更多相关文章

  1. Diary / Solution Set -「WC 2022」线上冬眠做噩梦

      大概只有比较有意思又不过分超出能力范围的题叭.   可是兔子的"能力范围" \(=\varnothing\) qwq. 「CF 1267G」Game Relics   任意一个 ...

  2. 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 ...

  3. Solution -「CF 1342E」Placing Rooks

    \(\mathcal{Description}\)   Link.   在一个 \(n\times n\) 的国际象棋棋盘上摆 \(n\) 个车,求满足: 所有格子都可以被攻击到. 恰好存在 \(k\ ...

  4. Solution -「CF 1622F」Quadratic Set

    \(\mathscr{Description}\)   Link.   求 \(S\subseteq\{1,2,\dots,n\}\),使得 \(\prod_{i\in S}i\) 是完全平方数,并最 ...

  5. Solution -「CF 923F」Public Service

    \(\mathscr{Description}\)   Link.   给定两棵含 \(n\) 个结点的树 \(T_1=(V_1,E_1),T_2=(V_2,E_2)\),求一个双射 \(\varph ...

  6. Solution -「CF 923E」Perpetual Subtraction

    \(\mathcal{Description}\)   Link.   有一个整数 \(x\in[0,n]\),初始时以 \(p_i\) 的概率取值 \(i\).进行 \(m\) 轮变换,每次均匀随机 ...

  7. Solution -「CF 1586F」Defender of Childhood Dreams

    \(\mathcal{Description}\)   Link.   定义有向图 \(G=(V,E)\),\(|V|=n\),\(\lang u,v\rang \in E \Leftrightarr ...

  8. Solution -「CF 1237E」Balanced Binary Search Trees

    \(\mathcal{Description}\)   Link.   定义棵点权为 \(1\sim n\) 的二叉搜索树 \(T\) 是 好树,当且仅当: 除去最深的所有叶子后,\(T\) 是满的: ...

  9. Solution -「CF 623E」Transforming Sequence

    题目 题意简述   link.   有一个 \(n\) 个元素的集合,你需要进行 \(m\) 次操作.每次操作选择集合的一个非空子集,要求该集合不是已选集合的并的子集.求操作的方案数,对 \(10^9 ...

  10. Solution -「CF 1023F」Mobile Phone Network

    \(\mathcal{Description}\)   Link.   有一个 \(n\) 个结点的图,并给定 \(m_1\) 条无向带权黑边,\(m_2\) 条无向无权白边.你需要为每条白边指定边权 ...

随机推荐

  1. 如何解决安装完 webdriver-helper 但不可用的问题?

    一.问题分析 使用 selenium ,并使用自动化安装浏览器驱动的方法,下载 webdriver_helper 的官网:webdriver-helper · PyPI.下载完成后在终端使用 pip ...

  2. CANoe学习笔记(一):创建第一个仿真工程(基于CAN):点灯

    目录 内容: ①创建两个节点,Switch和Light节点 ②创建两个Panel界面 ③capl代码实现Switch控制Light亮灭 事先准备: 养成良好的习惯,将不同文件放入不同文件夹,创建如下几 ...

  3. ChatGPT在工业领域的研究与应用探索-AI助手实验应用

    为什么我的工作效率和质量要比其他人要高,因为我的电脑里有代码库.产品库.方案库.自己工作经验资料库等,根据一个应用场景或需求能够很快关联到想要的资料,并且整合成新的方案.我的核心竞争力是什么?各种资料 ...

  4. Fabric架构详解

    1 整体架构 2 运行架构 Fabric CA(可选) peer:主节点模块,负责存储区块链数据,运行维护链码 orderer:交易打包,排序模块 cryptogen:组织和证书等资料生成模块 con ...

  5. SpringIoc容器之Aware

    1 前言 Aware是Spring提供的一个标记超接口,指示bean有资格通过回调样式的方法由Spring容器通知特定的框架对象,以获取到容器中特有对象的实例的方法之一.实际的方法签名由各个子接口确定 ...

  6. 【Python】从同步到异步多核:测试桩性能优化,加速应用的开发和验证

    测试工作中常用到的测试桩mock能力 在我们的测试工作过程中,可能会遇到多个项目并行开发的时候,后端服务还没有开发完成,或者我们需要压测某个服务,这个服务测在试环境的依赖组件(如 MQ) 无法支撑我们 ...

  7. C语言基础-结构体基础

    文章目录 前言 1.结构体的创建 1.1 第一种方法 1.2 第二种方法 1.3 全局结构体和局部结构体的声明 2.结构体的使用 2.1 局部结构体的声明 & 初始化 2.1.1 指针方法 2 ...

  8. 大白话讲讲 Go 语言的 sync.Map(一)

    阅读本文大约需要 4.25 分钟. 程序是枯燥乏味的. 在讲 sync.Map 之前,我们先说说什么是 map(映射). 我们每个人都有身份证号码,如果我需要从身份证号码查到对应的姓名,用 map 存 ...

  9. python分割多个分隔符

    想一次指定多个分隔符,可以用re模块 import retext='3.14:15'result = re.split('[.:]', text)print(result) 输出结果如下: ['3', ...

  10. nacos系列:简介和安装

    目录 版本选择 安装 windows安装 centos安装 mysql方式存储 官网:https://nacos.io github:https://github.com/alibaba/nacos ...