Codeforces Round 914 (Div. 2)A~C
A
反过来考虑,由皇后和国王的位置去寻找骑士的位置,当一个点既可以被皇后找到,也可以被国王找到时就说明这个点是满足条件的
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f
#define x first
#define y second
using namespace std;
const int N=3e5+10;
int n,m;
int dx[]={0,1,1,-1,-1};
int dy[]={0,1,-1,1,-1};
void solve()
{
map<PII,int>mp;
int xk,yk,xq,yq,a,b;cin>>a>>b>>xk>>yk>>xq>>yq;
rep(i,1,4)
{
mp[{xk+dx[i]*a,yk+dy[i]*b}]++;
if(a!=b) mp[{xk+dx[i]*b,yk+dy[i]*a}]++;
mp[{xq+dx[i]*a,yq+dy[i]*b}]++;
if(a!=b) mp[{xq+dx[i]*b,yq+dy[i]*a}]++;
}
int ans=0;
for(auto cnt:mp) if(cnt.y>1) ans++;
cout<<ans<<endl;
}
int main()
{
IOS
// freopen("1.in", "r", stdin);
int t;
cin>>t;
while(t--)
solve();
return 0;
}
B
思路:排序+前缀和
先排序,对于\(a[i],前面的数一定是小于它的一定可以被删除,需要找到后面最远能到达哪里\)
\(假设最远能到达r,那么[i,r]这一段区间中所有数的答案是一样的都是到r,如何判断哪里是最远?\)
\(当s[r]<a[r+1]时就说明此时r到达了最远\)
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f
#define x first
#define y second
using namespace std;
const int N=1e5+10;
ll n,m,a[N],s[N],ans[N];
struct node
{
int val,pos;
}b[N];
bool cmp(node a, node b)
{
return a.val<b.val;
}
void solve()
{
cin>>n;
rep(i,1,n) cin>>a[i],b[i].val=a[i],b[i].pos=i;
sort(b+1,b+1+n,cmp);
rep(i,1,n) s[i]=s[i-1]+b[i].val;
int last=0;
rep(i,1,n)
{
if(last<i)
{
last=i;
while(s[last]>=b[last+1].val&&last+1<=n) last++;
}
ans[b[i].pos]=last-1;
}
rep(i,1,n) cout<<ans[i]<<' ';
cout<<endl;
rep(i,1,n) s[i]=0,ans[i]=0;
}
int main()
{
IOS
// freopen("1.in", "r", stdin);
int t;
cin>>t;
while(t--)
solve();
return 0;
}
C
思路:
\(当k=1时\)显然可以直接暴力求解,\(O(n^2)枚举\)
\(当k>=3时\)结果显然是0,前两次都选择一样的i、j,后面选择新产生的两个数直接相减为0
\(当k=2时,对n^2个数每个数在排好序的a数组上面二分找到最接近的维护最小值就是答案\)
需要注意一定要和最开始的a取一下最小值,因为答案可能在最初的a中
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f
#define x first
#define y second
using namespace std;
const int N=5e6+10;
ll n,k,a[N],b[N];
void solve()
{
cin>>n>>k;
ll ans=1e18;
rep(i,1,n) cin>>a[i],ans=min(ans,a[i]);
if(k>=3)
{
cout<<0<<endl;
return;
}
sort(a+1,a+1+n);
rep(i,2,n) ans=min(ans,a[i]-a[i-1]);
if(k==1)
{
cout<<ans<<endl;
return;
}
if(k==2)
{
rep(i,1,n) rep(j,i+1,n)
{
ll xx=abs(a[j]-a[i]);
int k=lower_bound(a+1,a+1+n,xx)-a;
if(k<=n) ans=min(ans,a[k]-xx);
if(k>=2) ans=min(ans,xx-a[k-1]);
}
cout<<ans<<endl;
}
}
int main()
{
IOS
// freopen("1.in", "r", stdin);
int t;
cin>>t;
while(t--)
solve();
return 0;
}
Codeforces Round 914 (Div. 2)A~C的更多相关文章
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
随机推荐
- 消息队列RabbitMQ教程
RabbitMQ教程 翻译自RabbitMQ Tutorials. 0. 准备 前期准备 1. Hello World 最简入门教程 2. 工作队列 竞争消费者模式 3. 发布/订阅 同时发送消息给多 ...
- [1] 以逆向的角度来看流程控制语句——if
[1] 以逆向的角度来看流程控制语句--if 1. if语句(单分支) if语句转换的条件跳转指令与if语句的判断结果是相反的, 因为C语言是根据代码行的位置决定编译后二进制代码地址高低的,即低行 ...
- vim 从嫌弃到依赖(2)——vim 模式
在上一篇文章中我们获取到了neovim 并对它进行了基础配置.现在已经具备一般编辑器的基本功能了.让我们先学会如何使用vim基本功能进行编辑,后面再看如何进行配置,以达到某某IDE或者编辑器的效果 v ...
- 释放搜索潜力:基于ES(ElasticSearch)打造高效的语义搜索系统,让信息尽在掌握
释放搜索潜力:基于ES(ElasticSearch)打造高效的语义搜索系统,让信息尽在掌握[1.安装部署篇--简洁版],支持Linux/Windows部署安装 效果展示 PaddleNLP Pipel ...
- 【5】数据可视化pygal,画出美观的图表
相关文章: 全网最详细超长python学习笔记.14章节知识点很全面十分详细,快速入门,只用看这一篇你就学会了! [1]windows系统如何安装后缀是whl的python库 [2]超级详细Pytho ...
- Python 爬虫方法总结
实现爬虫的套路 准备URL 准备start_url url地址规律不明显,总数不确定 通过代码提取下一页的url 通过xpath提取 寻找url地址,部分参数在当前的响应中(比如当前页码数和总页码数在 ...
- Elasticsearch不同集群间备份恢复(S3存储)
S3存储 首先都知道需要在ES集群上安装S3插件以及重启集群 在MINIO集群创建相应的桶 Kibana上注册快照存储库,两个不同的集群需要对接到同一个S3存储库,对接后会自动识别桶里的快照 < ...
- NVME学习笔记六—Controller Architecture
Controller架构 NVMe over Fabrics使用与NVMe基础规格说明书中定义相同的controller架构.这包括主机和controller之间使用SQ提交队列和CQ完成队列来执 ...
- 使用多层RNN-LSTM网络实现MNIST数据集分类及常见坑汇总
1 前言 循环神经网络(Recurrent Neural Network, RNN)又称递归神经网络,出现于20世纪80年代,其雏形见于美国物理学家J.J.Hopfield于1982年提出的可作联想存 ...
- Springboot+Freemarker+Boostrap实现用户增删改查实战
说明 做java web用的2大模板语言分别是:thymeleaf和freemarker,thymeleaf前面已经用了很多了,所以今天用一下这个freemarker. 技术栈 springboot ...