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的更多相关文章
随机推荐
- MinGW-W64下载与安装
安装方案 1 下载安装包,MinGW-w64 - for 32 and 64 bit Windows,然后直接以管理员安装即可,但是这个方案在部分电脑可能不行,会提示 cannot download ...
- docker+mysql 构建数据库的主从复制
docker+mysql 构建数据库的主从复制 在最近的项目中,决定将项目改造成数据库读写分离的架构,后续会有博文详细讲述我的开发改造,本文主要记录我是如何一步步的构建数据库的主从复制. 为什么使用d ...
- Spring中PropertiesLoaderUtils应用
FileSystemResource fileSystemResource =new FileSystemResource("D:/home/conf/mail.properties&quo ...
- spring同时操作多数据库 多个mysql和mongoDB,不需切换数据源,同时操作mysql和mongodb
源码:https://github.com/haihai1172/spring-mysql-mongoDB 项目目录 1.环境搭建,java-sdk 1.8 具体怎么搭建,就不说了 2.配置jdbc. ...
- Java HashSet集合的子类LinkedHashSet集合
说明 HashSet保证元素的唯一性,可是元素存放进去是没有顺序的. 在HashSet下面有一个子类java.util.LinkedHashSet,它是 链表 + 哈希表(数组+链表 或者 数组+红黑 ...
- Logback源码分析
在日常开发中经常通过打印日志记录程序执行的步骤或者排查问题,如下代码类似很多,但是,它是如何执行的呢? package chapters; import org.slf4j.Logger; impor ...
- 用K-Means聚类分析做客户分群
聚类指的是把集合,分组成多个类,每个类中的对象都是彼此相似的.K-means是聚类中最常用的方法之一,它是基于点与点距离的相似度来计算最佳类别归属. 在使用该方法前,要注意(1)对数据异常值的处理:( ...
- matplotlib 直方图
一.特点 数据必须是原始数据不能经过处理,数据连续型,显示一组或多组分布数据 histogram 直方图 normed 定额 二.核心 hist(x, bins=None, normed=None) ...
- 洛谷P2585 [ZJOI2006]三色二叉树
题目描述 输入输出格式 输入格式: 输入文件名:TRO.IN 输入文件仅有一行,不超过10000个字符,表示一个二叉树序列. 输出格式: 输出文件名:TRO.OUT 输出文件也只有一行,包含两个数,依 ...
- Docker windows nano server容器中安装ssh实现远程登录管理
[问题] 使用ServiceMonitor.exe作为前台进程运行起来的容器无法attach. 无法远程连接到运行中的容器中进行管理. [解决方法] 在container中新建管理员用户,通过SSH实 ...