Codeforces_831
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的更多相关文章
随机推荐
- Windows和Linux下与VMware虚拟机通过内网IP通讯
首先分两种情况:一种是你的电脑已经在一个内网的环境下且有额外的内网IP地址,和另一种只是想给自己电脑上的虚拟机分配个内网IP来通讯. ①有可用的内网IP 找到一个空闲的IP地址(这里以192.168. ...
- SpringCloud入门系列0-Nacos的安装与配置
背景 工作有一些年头了,自从19年初彻底转了java(这又是另一篇心酸的故事),突然感觉自己荒废了好几年(不是说.net不好,而是回顾自己这几年做的很多东西都浮于表面,有时候弄成很忙的样子,回头看看自 ...
- 11 个最佳的 Python 编译器和解释器
原作:Archie Mistry 翻译:豌豆花下猫@Python猫 原文:https://morioh.com/p/765b19f066a4 Python 是一门对初学者友好的编程语言,是一种多用途的 ...
- 【DPDK】【Multiprocess】一个dpdk多进程场景的坑
[前言] 这是一个隐藏了近3年的问题,理论上只要用到DPDK multiprocess场景的都会遇到这个问题,具体出不出问题只能说是看运气,即使不出问题也仍然是一个风险. [场景] 我先描述一下这个问 ...
- 重拾c++第一天(1):环境配置
时过多年,c++基本不记得了,故在此记录相关重拾记录. 学习语言第一步当然是环境配置了(笑),由于暂无用c++进行大型项目开发的需求,所以先下载dev进行过渡. 安装过程非常简单,值得注意的是配置时选 ...
- 16. 产生Javadoc
过程与export >> javadoc一致,需要注意的是字符集的设置. -encoding UTF-8 -charset UTF-8 export >> javadoc : ...
- 三分钟网络基础-IP地址分类
IP 地址的编址方法共经过了三个历史阶段: 分类的 IP 地址 子网的划分 超网 这篇文章首先介绍,最初始的 IP 地址分类方法. 分类的 IP 将 IP 地址划分为若干个固定类,每一类地址都由两个固 ...
- Java入门 - 语言基础 - 15.StringBuffer
原文地址:http://www.work100.net/training/java-stringbuffer.html 更多教程:光束云 - 免费课程 StringBuffer 序号 文内章节 视频 ...
- 第二阶段冲刺个人任务——seven
今日任务: 整体运行测试上传到公网上的程序. 昨日成果: 搭建网络服务器,上传数据库及程序.
- ps入门
目标:把运动截图的日期改掉.一次运动,天天装逼! 1 左上角 文件 -> 打开 选中要P的图片 2 CRTL 和 +号 放大 3 摁住空格键就可以用鼠标拖动图片(把要P的部分放到中间) ...