A.线性判断。

#include<bits/stdc++.h>
using namespace std; int n,a[] = {}; int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= n;i++) cin >> a[i];
int t = ;
while(a[t] > a[t-]) t++;
while(a[t] == a[t-]) t++;
while(a[t] < a[t-]) t++;
if(t > n) cout << "YES" << endl;
else cout << "NO" << endl;
return ;
}

B.map转换一下。

#include<bits/stdc++.h>
using namespace std; map<char,char> mp;
string s,s1,s2;
int main()
{
ios::sync_with_stdio();
cin >> s1 >> s2 >> s;
for(int i = ;i < ;i++)
{
mp[s1[i]] = s2[i];
mp[s1[i]+'A'-'a'] = s2[i]+'A'-'a';
}
for(int i = ;i < s.length();i++)
{
if(mp.count(s[i])) cout << mp[s[i]];
else cout << s[i];
}
cout << endl;
return ;
}

C.先求评委前缀和,若要某方案符合,则必须所有n个点在k个评委的评分间隔内,枚举每个评委,对应一个点,判断是否符合要求即可,注意重复的情况。

#include<bits/stdc++.h>
using namespace std; int n,k,a[],b[];
map<int,int> mp,ok; int main()
{
ios::sync_with_stdio();
cin >> k >> n;
for(int i = ;i <= k;i++) cin >> a[i];
for(int i = ;i <= k;i++) a[i] += a[i-];
for(int i = ;i <= k;i++) mp[a[i]] = ;
for(int i = ;i <= n;i++) cin >> b[i];
for(int i = n;i >= ;i--) b[i] -= b[];
int ans = ;
for(int i = ;i <= k;i++)
{
int flag = ;
for(int j = ;j <= n;j++)
{
if(!mp.count(a[i]+b[j]))
{
flag = ;
break;
}
}
if(flag && !ok.count(a[i]))
{
ans++;
ok[a[i]] = ;
}
}
cout << ans << endl;
return ;
}

D.先对人和钥匙排序,最优的结果肯定是人在钥匙中连续的某一段,暴力枚举每一段就可以了。

#include<bits/stdc++.h>
using namespace std; int n,k,p,a[],b[]; int main()
{
ios::sync_with_stdio();
cin >> n >> k >> p;
for(int i = ;i <= n;i++) cin >> a[i];
for(int i = ;i <= k;i++) cin >> b[i];
sort(a+,a++n);
sort(b+,b++k);
int ans = INT_MAX;
for(int i = ;i+n- <= k;i++)
{
int maxx = ;
for(int j = ;j <= n;j++)
{
int t = i+j-;
maxx = max(maxx,abs(a[j]-b[t])+abs(b[t]-p));
}
ans = min(ans,maxx);
}
cout << ans << endl;
return ;
}

E.给每个数字开个set,储存每个数字下标,原数组排序一下,从小到大开始操作,用树状数组计数。

#include<bits/stdc++.h>
using namespace std; int n,a[],tree[] = {};
set<int> s[]; inline int lowbit(int x)
{
return x&-x;
} void update(int pos,int x)
{
while(pos <= n)
{
tree[pos] += x;
pos += lowbit(pos);
}
} int getsum(int pos)
{
int sum = ;
while(pos > )
{
sum += tree[pos];
pos -= lowbit(pos);
}
return sum;
} int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= n;i++)
{
cin >> a[i];
s[a[i]].insert(i);
update(i,);
}
sort(a+,a++n);
int now = ;
long long ans = ;
for(int i = ;i <= n;i++)
{
int t = a[i];
auto it = s[t].lower_bound(now);
if(it == s[t].end())
{
ans += getsum(n)-getsum(now);
it = s[t].lower_bound();
now = ;
}
ans += getsum(*it)-getsum(now);
now = *it;
update(*it,-);
s[t].erase(it);
}
cout << ans << endl;
return ;
}

F.要求最大的d,使得 

枚举每一个可能的 中d的值,对每一个可能的值计算d再判断。

#include<bits/stdc++.h>
using namespace std; long long n,k,a[],b[]; int main()
{
ios::sync_with_stdio();
cin >> n >> k;
int cnt = ;
long long sum = k;
for(int i = ;i <= n;i++)
{
cin >> a[i];
sum += a[i];
for(int j = ;j*j <= a[i];j++)
{
b[++cnt] = j;
b[++cnt] = (a[i]+j-)/j;
}
}
sort(b+,b++cnt);
cnt = unique(b,b++cnt)-b-;
long long ans = ;
for(int i = ;i <= cnt;i++)
{
long long now = ;
for(int j = ;j <= n;j++) now += (a[j]+b[i]-)/b[i];
if(sum/now >= b[i]) ans = max(ans,sum/now);
}
cout << ans << endl;
return ;
}

Codeforces_831的更多相关文章

随机推荐

  1. pom.xml引入依赖时顺序错误而编译异常

    java.lang.NoClassDefFoundError: Lorg/springframework/beans/factory/access/BeanFactoryReference; at j ...

  2. 【一起学源码-微服务】Feign 源码三:Feign结合Ribbon实现负载均衡的原理分析

    前言 前情回顾 上一讲我们已经知道了Feign的工作原理其实是在项目启动的时候,通过JDK动态代理为每个FeignClinent生成一个动态代理. 动态代理的数据结构是:ReflectiveFeign ...

  3. 【阿里云IoT+YF3300】11.物联网多设备快速通信级联

    我们见到的很多物联网设备,大都是“一跳”上网,所谓的“一跳”就是设备直接上网,内嵌物联网模块或者通过DTU直接上网.其实稍微复杂的物联网现场,往往网关下面连接若干物联网设备(如下图),并且这些物联网设 ...

  4. Longhorn入门级教程!轻松实现持久化存储!

    介 绍 在本文中你将学会如何使用k3s在Civo上运行Longhorn.如果你还没使用过Civo,可以到官网注册(https://www.civo.com/ )还可以申请免费的使用额度.首先,需要一个 ...

  5. Redis-缓存穿透、缓存雪崩、缓存击穿、缓存一致性、并发竞争

    缓存流程 在讲这五个问题之前,首先我们回顾下正常的缓存的使用流程 程序在处理请求时,会先从缓存中进行查询,如果缓存中没有对应的key,则会从数据库中查询,如果查询到结果,并将查询结果添加到缓存中去,反 ...

  6. 《【面试突击】— Redis篇》-- Redis的主从复制?哨兵机制?

    能坚持别人不能坚持的,才能拥有别人未曾拥有的.关注左上角编程大道公众号,让我们一同坚持心中所想,一起成长!! <[面试突击]— Redis篇>-- Redis的主从复制?哨兵机制? 在这个 ...

  7. 倍增LCA模板2董博文版 伪代码

    Dfs(int rt){ f[][rt]; ;k<=;k++) f[k][rt]=f[k-][f[k-][rt]]; } int LCA(int x,int y){ if(Dp[x]<Dp ...

  8. wannafly camp day1

    题目描述: 恬恬的生日临近了.宇扬给她准备了一个大 蛋糕. 正如往常一样,宇扬在蛋糕上插了nnn支蜡烛,并把蛋糕分为mmm个区域.因为某种原因,他必须把第iii根蜡烛插在第aia\_iai​个区域或第 ...

  9. 《C# 爬虫 破境之道》:概述

    第一节:写作本书的目的 关于笔者 张晓亭(Mike Cheers),1982年出生,内蒙古辽阔的大草原是我的故乡. 没有高学历,没有侃侃而谈的高谈阔论,拥有的就是那一份对技术的执著,对自我价值的追求. ...

  10. kubernetes concepts -- Pod Overview

    This page provides an overview of Pod, the smallest deployable object in the Kubernetes object model ...