Shifting Stacks
给你 n 长度的数组,每个下标包含 000-nnn 个木块 其中可以将某一位置的木块向右边平移 请问是否能凑出高度严格上升的数组 一开始想简单了 直接判断木块的和是否大于 (111+(n−1)(n-1)(n−1))*(n−1)(n-1)(n−1)/2 但是这样是错误的 因为你不能一定凑出这样的排列 假如都在最后一列 所以需要按照符合情况所需最小木板数去做模拟 check

#include<cstdio>
#include<cstring>
#include<vector>
#include<cstring>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<iostream>
using namespace std;#define dbg(x) cout << #x << " = " << (x) <<endl;
#define dbg2(x,y) cout << #x << " = " << (x) << " " << #y << " = " << (y) <<endl;
#define dbg3(x,y,z) cout << #x << " = " << (x) << " " << #y << " = " << (y) <<" " << #z << " = " << z <<endl;
#define ll long long
#define fi first
#define se second
#define pb push_backconst int MAX_N = 105;
ll arr[MAX_N];int main()
{int t;scanf("%d",&t);while(t--){int n,x;ll sum = 0;scanf("%d",&n);int ck = n*(n-1)/2;for(int i = 1;i<=n;++i){scanf("%lld",&arr[i]);}bool flag = true;for(int i = 1;i<=n;++i){if(sum+arr[i]<(i-1)){flag = false;break;}sum+=arr[i]-(i-1);}if(flag) printf("YES\n");else printf("NO\n");}return 0;
}

Eastern Exhibition
给你 n 个点,横纵坐标的范围是 0−1e90-1e90−1e9 其实这个答案是会有很多种的,想到找中点,但是一开始nc写了个dfs(zz) 其实我们考虑假设nnn个点都在同一纵坐标,那么假如是偶数个点,在中间两个点(下标不同)之间任意平移不影响对xxx的贡献 奇数点则不满足条件 只能按着不动 分类乘法一下即可 dfs可太秀了

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;#define debug(x) cout << #x << " = " << (x) <<endl;
#define ll long long
const int MAX_N = 200025;ll arr[MAX_N],brr[MAX_N];int main()
{int t;scanf("%d",&t);while(t--){int n;scanf("%d",&n);for(int i = 1;i<=n;++i){scanf("%lld",&arr[i]);scanf("%lld",&brr[i]);}sort(arr+1,arr+1+n);sort(brr+1,brr+1+n);if(n%2==0){printf("%lld\n",(arr[n/2+1]-arr[n/2]+1)*(brr[n/2+1]-brr[n/2]+1));}else{printf("1\n");}}return 0;
}

Guessing the Greatest
比较有意思的交互题 给你nnn个值不同的数组成的数组 你可以选择一个区间进行询问,题目会告诉你这个区间内第二大的数的下标是什么 要求你不超过20次查询得到最大数的下标所在地
222^202020 次方 > 1e61e61e6 所以我们自然想到二分
如何进行二分呢?
我们首先对整个数组查询一次,我们知道全局第二大的数在哪,那么我们可以每次判断一个区间是否含有最大值的check表达式为 整个区间内第二大是否为全局第二大,那么经过一次check你就可以知道全局最大是在左区间还是在右区间(所在的区间查询得到的下标为一开始所求的全局第二大)那么就可以二分递归下去求解了

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
using namespace std;#define dbg(x) cout << #x << " = "  << (x) << endl;int Find(int l,int r)
{int x;printf("? %d %d\n\n",l,r);fflush(stdout);scanf("%d",&x);return x;
}int main()
{bool flag = false;int n,ans;scanf("%d",&n);int xb = Find(1,n);if(xb<n&&Find(xb,n)==xb){int l = xb+1, r = n;while(l<=r){int mid = l+r>>1;int now_xb = Find(xb,mid);if(now_xb==xb){flag = true;ans = mid;r = mid - 1;}else{l = mid + 1;}}if(flag){printf("! %d\n",ans);fflush(stdout);}}if(xb>1&&!flag){int l = 1,r = xb-1;while(l<=r){int mid = l+r>>1;int now_xb = Find(mid,xb);if(now_xb==xb){flag = true;ans = mid;l = mid + 1;}else{r = mid - 1;}}if(flag){printf("! %d\n",ans);fflush(stdout);}}return 0;
}

Max Median
给你nnn个数组,mmm长度,你可以选择长度大于等于mmm的连续区间 此区间正序排序 (n+1)/2(n+1)/2(n+1)/2向下取整的下标的数为 median 问你所有median中的最小值最大为多少
我们很自然的可以想到二分答案 那么怎么将二分的答案与check过程联立呢?我们很自然的想到将原数大小大于等于二分所得答案的贡献为111,其余为−1-1−1 那么我们就可以去解决如何选出长度大于等于mmm的连续区间了
考虑前缀和 如果两个前缀和值为一样,则代表他们之间的差的值为000,即中间这段区间可以选来 我们发现区间值为000是没用的 会取到下标为−1-1−1的数(与正序有关)所以我们只求前缀和 > 111的情况 这样我们还得同时保证长度大于 mmm 那么不难想到维护一个前缀最小值 代表前缀和的最小值 然后利用前缀和求解即可

#include<cstdio>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<set>
#include<cmath>
#include<stack>
using namespace std;
const int MAX_N = 200025;
int arr[MAX_N],brr[MAX_N],sum[MAX_N],minn[MAX_N];
map<int,int> mp;
#define dbg(x) cout << #x << " = " << (x) << endl;
#define dbg2(x,y) cout << #x << " = " << (x) << " " << #y << " = " << (y) << endl;
#define dbg3(x,y,z) cout << #x << " = " << (x) << " " << #y << " = " << (y) << " " << #z << " = " << (z) << endl;int main()
{int n,m;scanf("%d%d",&n,&m);for(int i = 1;i<=n;++i){scanf("%d",&arr[i]);}minn[0] = 0x3f3f3f3f;sum[0] = 0;int l = 1, r = n;while(l<=r){bool flag = false;mp.clear();mp[0] = 0;int mid = l + r >>1;for(int i = 1;i<=n;++i){brr[i] = (arr[i]>=mid)?1:-1;sum[i] = sum[i-1]+brr[i];if(mp.find(sum[i])==mp.end()) mp[sum[i]] = i;minn[i] = min(minn[i-1],sum[i]);}for(int i = m;i<=n;++i){if(sum[i]>0) flag = true;if(i>m&&((sum[i]-minn[i-m])>0)) flag = true;}if(flag) l = mid + 1;else r = mid - 1;}printf("%d\n",r);return 0;
}

Paired Payment
最短路的两跳版本,由于题意比较明确,所以一上来就撸了个 n2n^2n2n2n^2n2 的最短路,这要是以前 zls 肯定说是肯定过不去的,然后我又会说我来几个玄学优化(每次都会被zls反驳哈哈,过去的时光还是很美好的),那么显然我一开始也是这样做了
后来去学习了题解,发现其实n2∗n2n^2*n^2n2∗n2的原因是因为我们想维护边 但是图论里面有很重要的虚边的概念 用虚点连接虚边 我们得注意到这题的长度是505050(之前一直没有注意到)我们将每个点都乘 * 515151 代表虚点,每条边有两个状态,作为两跳中的第一跳,则与 v * 515151 + w 连一条边权为000的边,遍历上一跳边权从111-505050枚举作为第二条的边权 (was+w)
(was+w) 后续用大跟堆最短路所求即可

#include<cstdio>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
const int MAX_N = 200025;
const int MAX_M = 200000*51+5;
const int INF = 1e9+7;#define ll long long
#define dbg(x) cout << #x << " = " << (x) << endl;
#define dbg2(x,y) cout << #x << " = " << (x) << " " << #y << " = " << (y) << endl;
#define dbg3(x,y,z) cout << #x << " = " << (x) << " " << #y << " = " << (y) << " " << #z << " = " << (z) << endl;vector<pair<int,int> > vt[MAX_M];
priority_queue<pair<int,int> > q;
int dp[MAX_M];void add(int u,int v,int w)
{vt[u*51].push_back(make_pair(v*51+w,0)); // middle pointfor(int was = 1;was<=50;++was){vt[u*51+was].push_back(make_pair(v*51,(was+w)*(was+w))); // end point}
}int main()
{int n,m,u,v,w;scanf("%d%d",&n,&m);for(int i = 1;i<=n*51;++i){dp[i] = INF;}for(int i = 1;i<=m;++i){scanf("%d%d%d",&u,&v,&w);u--,v--;add(u,v,w);add(v,u,w);}dp[0] = 0;q.push(make_pair(-dp[0],0));while(!q.empty()){pair<int,int> top = q.top();q.pop();for(auto v:vt[top.second]){if(dp[v.first]>-top.first+v.second){dp[v.first] = -top.first+v.second;q.push(make_pair(-dp[v.first],v.first));}}}for(int i=0;i<n;++i){if(dp[i*51]==INF) dp[i*51] = -1;i==n?printf("%d\n",dp[i*51]):printf("%d ",dp[i*51]);}return 0;
}

Codeforces Round #703 (Div. 2) A-E 题解相关推荐

  1. Codeforces Round #703 (Div. 2)

    Codeforces Round #703 (Div. 2) 题号 题目 知识点 A Shifting Stacks 思维 B Eastern Exhibition 思维 C1 Guessing th ...

  2. Codeforces Round #198 (Div. 2)A,B题解

    Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...

  3. Codeforces Round #774 (Div. 2)E题题解

    Codeforces Round #774 (Div. 2) E. Power Board 题目陈述 有一个n×m(1≤n,m≤106)n\times m(1\le n,m\le10^6)n×m(1≤ ...

  4. Codeforces Round #703 (Div. 2) 题解

    文章目录 A. Shifting Stacks B. Eastern Exhibition C. Guessing the Greatest D. Max Median E. Paired Payme ...

  5. Codeforces Round #703 (Div. 2)(A ~ F)超高质量题解【每日亿题2 / 19】

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A. Shifting Stacks B - Eastern Exhibition C1 - G ...

  6. Codeforces Round #640 (Div. 4)(ABCDEG题解)

    文章目录 A. Sum of Round Numbers B - Same Parity Summands C - K-th Not Divisible by n D - Alice, Bob and ...

  7. Codeforces Round #635 (Div. 2)(A~D)题解

    Codeforces #635 A~D A.Ichihime and Triangle B.Kana and Dragon Quest game C.Linova and Kingdom D.Xeni ...

  8. Codeforces Round #703 (Div. 2) C. Guessing the Greatest

    C1. Guessing the Greatest (easy version) C2. Guessing the Greatest (hard version) Codeforces C题Guess ...

  9. 【记录CF】Codeforces Round #777 (Div. 2) A~C 题解

    目录 杂谈 A. Madoka and Math Dad B. Madoka and the Elegant Gift C. Madoka and Childish Pranks 杂谈 又是一场离谱掉 ...

最新文章

  1. 分析JDK源码 | Java Object
  2. 全部都是div,换点新花样。【HTML5的标签】
  3. 被七牛云OSS对象存储测试域名回收后正确数据迁移姿势!
  4. Java 配置C3P0数据连接池存入数据存入数据库出现中文乱码问题
  5. Keras处理TIFF图像
  6. 纯JDBC系统的开发随想
  7. centos 卸载_CentOS安装mysql
  8. 计算(a+b)*c的值
  9. 区块链学习笔记:DAY05 如何使用公有云区块链服务
  10. 随机森林、gbdt算法
  11. 更高速 更智能 WLAN领域H3C再获领先——H3C发布新一代高性能802.11n 无线产品
  12. c# 对象json互相转换_C#编程实现对象与JSON串互相转换实例分析
  13. 研究生能合作发表论文吗?
  14. 迅雷某页面存在sql注入漏洞
  15. Java基础第一讲:Java的故事和Java编程环境搭建
  16. 软件壳的概念和如何脱壳基础
  17. EM期望最大化算法实现二项混合分布与高斯混合分布
  18. CVE-2021-3560-POLKIT本地提权漏洞复现
  19. 开源NLP(自然语言处理)库的功能对比
  20. 技术分享 | 黑盒测试方法论—场景法

热门文章

  1. 安装centOS7报未知错误
  2. idea maven 本地仓库有但是引不进来问题记录
  3. 单道批处理 多道批处理
  4. 图形图像基础 之 bmp介绍
  5. 基于JSP的火车高铁购票的系统【数据库设计、源码、开题报告】
  6. 在cadence集成calibre
  7. 温岭商务局局长施珍娟莅临卧兔总部调研考察
  8. Java程序员需要了解的几个开源协议开源协议
  9. 大数据的产生和作用(详细分析)
  10. 公司开始裁员了,33岁的我何去何从