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的更多相关文章

  1. 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 ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  10. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

随机推荐

  1. Docker 完整指南

    欢迎来到 Docker 的完整指南!在这个教程中,我们将深入研究 Docker 的各种特性,从基础的容器操作到高级的网络配置和数据管理.让我们一步步地探索 Docker 的丰富功能. 1. 安装 Do ...

  2. 每日一库:使用Viper处理Go应用程序的配置

    在开发Go应用程序时,处理配置是一个常见的需求.配置可能来自于配置文件.环境变量.命令行参数等等.Viper是一个强大的库,可以帮助我们处理这些配置. 什么是Viper? Viper是一个应用程序配置 ...

  3. AspnetCore接入Nacos配置中心

    一.什么是nacos Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service的首字母简称,一个更易于构建云原生应用的动态服务发现.配置管理 ...

  4. vscode连不上云服务器,一直报超时错误|但是xshell那些又可以连上?为什么vscode连不上?|命令行输出管道报错 -bash: command not found 导致的一系列问题

    前言 那么这里博主先安利一些干货满满的专栏了! 首先是博主的高质量博客的汇总,这个专栏里面的博客,都是博主最最用心写的一部分,干货满满,希望对大家有帮助. 高质量博客汇总https://blog.cs ...

  5. .NET Avalonia开源、免费的桌面UI库 - SukiUI

    前言 今天分享一款.NET Avalonia基于MIT License协议开源.免费的桌面UI库:SukiUI. Avalonia介绍 Avalonia是一个强大的框架,使开发人员能够使用.NET创建 ...

  6. Codeforces Round #825 (Div. 2) A-D

    比赛链接 A 题解 知识点:贪心. 考虑两种方法: 所有不同的位置使用操作1变成相同 使用操作1将两串01数量相同,然后使用1次操作2 取其中最小的即可. 时间复杂度 \(O(n)\) 空间复杂度 \ ...

  7. Linux dmesg命令使用方法详解

    一.命令简介  dmesg(display message)命令用于显示开机信息.kernel 会将开机信息存储在 ring buffer 中.您若是开机时来不及查看信息,可利用 dmesg 来查看. ...

  8. 开年!5 款令人惊艳的开源项目「GitHub 热点速览」

    朋友们开工大吉啊!我刚从假期模式切换回来,完全无心工作有些不在状态,比如开机密码错了好几次.闲话少叙,下面就让我们一起看看,春节这段时间 GitHub 上又出了什么有趣.好玩的开源项目. 今年上来就是 ...

  9. el-dialog关闭后重置表单和校验提示

    问题说明 最近测试反馈操作某新增/修改表单,点击[取消]或[关闭]窗口后再次点击[新增]或[修改]发现校验提示仍然存在! 问题原因 项目采用Vue+ElementUI,修改表单的窗口控件采用el-di ...

  10. linux如何发送电子邮件

      使用linux时,有时我们想发邮件给朋友或同事,可不可以通过命令行直接发呢?         想通过linux监控网站或者系统状况并自动报警,如何使用脚本发出邮件给外部邮箱呢?         不 ...