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\) 条无向无权白边.你需要为每条白边指定边权 ...
随机推荐
- 基于 Dash Bio 的生物信息学数据可视化
Dash 是用于搭建响应式 Web 应用的 Python 开源库.Dash Bio 是面向生物信息学,且与 Dash 兼容的组件,它可以将生物信息学领域中常见的数据整合到 Dash 应用程序,以实现响 ...
- rust实现weatherforecast的获取天气webapi
rust用来写webapi可能有点大材小用,但是作为入门学习应该说是不错的选择. cargo new webapi创建一个webapi项目,在src下面新建handler文件夹和models文件夹. ...
- 【Python&目标识别】调用百度智能云API实现植被识别
百度智能云于2015年正式对外开放运营,以"云智一体"为核心赋能千行百业,致力于为企业和开发者提供全球领先的人工智能.大数据和云计算服务及易用的开发工具.凭借先进的 ...
- 推荐一个 C#写的 支持OCR的免费通用扫描仪软件
NAPS2是一个开源免费软件,体积只有6M不到,支持运行在 Windows, Mac 和 Linux操作系统中,默认就带有简体中文界面,官方默认就提供绿色版,所以解压即可使用,直接可以从官方网站下载: ...
- 从0搭建Vue3组件库(十):如何搭建一个 Cli 脚手架
本篇文章将实现一个名为create-easyest脚手架的开发,只需一个命令npm init easyest就可以将整个组件库开发框架拉到本地. 创建 Cli 包 首先,我们在 packages 目录 ...
- 【.NET 深呼吸】全代码编写WPF程序
学习 Code 总有这样一个过程:入门时候比较依赖设计器.标记语言等辅助工具:等到玩熟练了就会发现纯代码写 UI 其实更高效.而且,纯代码编写也是最灵活的.Windows Forms 项目是肯定可以全 ...
- 【HarmonyOS】【ArkTS】如何使用HTTP网络请求获取动态数据刷新UI界面
[关键字] HttpRequest.ArkTS.网络数据请求.@ohos.net.http [前言] 在使用ArkTS开发HarmonyOS应用时,需要调用HTTP网络请求 @ohos.net.h ...
- 2021/1/10例会 academy of management journal 2014vol 57 No.2,484-514
这次的论文由于考试周的原因看的不是很细,但大概还是浏览过一遍了.然后这次我的拓展又神奇的匹配到了教授想让我们接下来想看的论文. perfect! 但不足的是,没有进行相关论文的检索,自己的拓展没有理论 ...
- JS逆向实战19——通杀webpack逆向
声明 本文章中所有内容仅供学习交流,抓包内容.敏感网址.数据接口均已做脱敏处理,严禁用于商业用途和非法用途,否则由此产生的一切后果均与作者无关,若有侵权,请联系我立即删除! 网站 aHR0cHM6Ly ...
- Redis数据类型之Stream系列一
一:Stream简介 Redis Stream是5.0版本之后新增的一种数据结构,其结构类似于'仅追加日志'.但也实现了多种操作来克服'仅追加日志'的一些限制,如读取策略(xread,xrange ...