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. ABP .net Core 将日志打印在控制台

    上效果图 来看一下操作流程: 一.分为.net Core 2.2 和 .net Core 3.0及以上 (一)..net Core 2.2 1.在 EntityFrameworkCore中安装Nuge ...

  2. 3D圆饼图,可修改颜色,图片等,具体见代码:

    组件代码: <template> <!-- 饼图 --> <div :id="histogramId" v-bind:style="{hei ...

  3. 13.2 外部DirectX绘制实现

    在前一节中我们简单介绍了D3D绘制窗体所具备的基本要素,本节将继续探索外部绘制技术的实现细节,并以此实现一些简单的图形绘制功能,首先外部绘制的核心原理是通过动态创建一个新的窗口并设置该窗口属性为透明无 ...

  4. 有用的工具类(Java)

    IP地址获取 public class IPUtil { private static final String UNKNOWN = "unknown"; protected IP ...

  5. Windows 7 Ultimate with Service Pack 1 (x64)

    Windows 7 Ultimate with Service Pack 1 (x64) 链接:https://pan.baidu.com/s/1ZHODDFlJPLQ3ydxZ4rfc3g 提取码: ...

  6. GJK算法:两个凸集的碰撞测试

      GJK算法用于判断两个凸集是否相交,其中GJK是三个提出者的姓名首字母.为了便于理解(偷懒),下面的内容都只在二维平面内讨论. 1. 回顾凸集   可能有很多小伙伴忘了什么是凸集.凸集有很多等价的 ...

  7. STM8 bootloader 升级方案程序设计(一)

    1.前言 上一篇单片机 IAP 功能基础开发篇之APP升级(一)讲到了单片机 IAP 功能给 APP 程序升级的设计思路,这篇介绍的是具体实现方式. 这篇介绍关于 STM8 系列实现 bootload ...

  8. POJ1080 滑雪

    题目链接 题目 Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Mi ...

  9. sensitive-word-admin 敏感词控台 v1.2.0 版本开源

    开源目的 丰富 sensitive-word 的生态. 提供最基本的操作例子,便于在此基础上丰富实现自己的敏感词控台. 避免重复开发的成本,让更多的精力专注于业务. 拓展阅读 sensitive-wo ...

  10. Ubuntu下SSH管理及SFTP下载工具Muon(Snowflake)

    简介 Muon其实更像是一个基于ssh的服务器管理工具, 界面中有PAC Manager的影子, 集成了文件管理, ssh命令行, 服务器性能监测和工具包等功能. 因为这个工具的编写语言是Java, ...