首页 > 其他分享 >牛客OI周赛7-普及组

牛客OI周赛7-普及组

时间:2022-10-25 17:07:16浏览次数:55  
标签:周赛 OI nxt int cin long pos 牛客 include


这一场感觉良好

也只能打这种普及组长长信心这样子

牛客OI周赛7-普及组_Cowcoder

A:救救喵咪
给你坐标轴上的个点,求出对于每个点,有多少个点的坐标和坐标都大于它。(

是开玩笑的吧
直接

#include <iostream>
#define

using namespace std;
typedef long long ll;
int x[A], y[A], n;

int main(int argc, char const *argv[]) {
cin >> n;
for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];
for (int i = 1; i <= n; i++) {
int cnt = 0;
for (int j = 1; j <= n; j++)
if (x[j] > x[i] and y[j] > y[i]) cnt++;
cout << cnt << endl;
}
}

B:救救兔子
一个由个数组成的序列,给你个询问,每个询问会给你一个数,对于每个询问,你要回答出序列中与这个值最接近的元素

二分

#include <iostream>
#include <algorithm>
#define

using namespace std;
typedef long long ll;
int a[A], n, T, t;
int search(int x) {
int l = 1, r = n, m = (n + 1) >> 1;
while (l < r - 1) {
if (x < a[m]) r = m;
else l = m;
m = (l + r) >> 1;
}
if (abs(a[l] - x) <= abs(a[l + 1] - x) and l < n) return a[l];
else return a[l + 1];
}

int main(int argc, char const *argv[]) {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
cin >> T;
while (T--) {
cin >> t;
cout << search(t) << endl;
}
}

直接lower_bound也可以

#include <iostream>
#include <algorithm>
#define

using namespace std;
typedef long long ll;
int f[A], n, m, a;

int main(int argc, char const *argv[]) {
cin >> n;
for (int i = 0; i < n; i++) cin >> f[i];
sort(f, f + n);
cin >> m;
for (int i = 0; i < m; i++) {
cin >> a;
int nxt = lower_bound(f, f + n, a) - f; int las = nxt - 1;
if (nxt >= n) nxt = n - 1;
if (las < 0) las = 0;
if (f[nxt] - a < a - f[las]) cout << f[nxt];
else cout << f[las];
}
}

C:救救企鹅
将字符串a中的b都换成c

考察string函数的应用

#include <iostream>
#define
#define

using namespace std;
typedef long long ll;
string a, b, c;

int main(int argc, char const *argv[]) {
cin >> a >> b >> c;
while (1) {
int x = a.find(b);
if (x >= a.length()) break;
a.erase(x, b.length());
a.insert(x, c);
}
cout << a;
}

D:数糖纸
元素不重复区间的最长长度

尺取法
不了解可自行百度

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define
#define

using namespace std;
typedef long long ll;
int n, l = 1, r = 1, nxt[A], ans, a[A], pos[A], pre[A];

int main(int argc, char const *argv[]) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
memcpy(pos, a, sizeof a);
sort(pos + 1, pos + n + 1);
for (int i = 1; i <= n; i++) {
int k = lower_bound(pos + 1, pos + n + 1, a[i]) - pos - 1;
pre[i] = nxt[k], nxt[k] = i;
}
while (l <= n and r <= n) {
while (pre[r] < l and r <= n) ans = max(ans, r - l + 1), r++;
l = pre[r] + 1;
}
printf("%d\n", ans);
}


标签:周赛,OI,nxt,int,cin,long,pos,牛客,include
From: https://blog.51cto.com/lyle/5794945

相关文章

  • Luogu 3478 [POI2008]STA-Station
    题目链接:​​传送门​​题目描述给出一个N个点的树,找出一个点来,以这个点为根的树时,所有点的深度之和最大输入样例814564567682434输出样例7一句话题意好......
  • BZOJ 2733: [HNOI2012]永无乡
    题目链接:​​传送门​​​Description永无乡包含n座岛,编号从1到n,每座岛都有自己的独一无二的重要度,按照重要度可以将这n座岛排名,名次用1到n来表示。某些岛之间......
  • BZOJ 4592 [Shoi2015]脑洞治疗仪
    题目链接:​​传送门​​​Description曾经发明了自动刷题机的发明家SHTSC又公开了他的新发明:脑洞治疗仪–一种可以治疗他因为发明而日益增大的脑洞的神秘装置。为了简单起......
  • HDU 2844 Coins
    题目链接:​​传送门​​​题面:ProblemDescriptionWhuacmersusecoins.TheyhavecoinsofvalueA1,A2,A3…AnSilverlanddollar.OnedayHibixopenedpurseandfoun......
  • Android 渠道包生成
    目前看到了两家打包实现:美团腾讯VasDolly前言其实本文大部分资料都来自github和google,如何有兴趣的读者,可以直接阅读官方文档~什么是GradleAndroid构建系统编译应......
  • 牛客BM76(正则表达式匹配)
    BM76正则表达式匹配具体实现:1.确定dp数组以及下标的含义dp[i][j]代表s中以i结尾的子串和p中j为结尾的子串是否匹配2.状态转移(1)p[j]为普通字符:匹配的条件是前面的字符......
  • mybatis typehandler适配postgresql中的point数组数据类型
    mybatistypehandler适配postgresql中的point数组数据类型importlombok.extern.slf4j.Slf4j;importorg.apache.ibatis.type.BaseTypeHandler;importorg.apache.ibat......
  • Luogu P4171 [JSOI2010]满汉全席
    题目链接:​​传送门​​2-sat板子题注意输入的时候可不要以为w和h后面数字只有一位*/#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#includ......
  • Luogu P2455 [SDOI2006]线性方程组
    题目链接:​​传送门​​高斯消元可以去下面看一下​​​https://www.bilibili.com/video/av4688674​​​听视频比瞅博客有用得多这题算比较标准的板子了各种情况都有......
  • BZOJ 3747: [POI2015]Kinoman
    题目链接:​​传送门​​好像之前在洛谷上做过一个叫KIN的题一个电影看多次就不会记贡献那么这个电影产生贡献的区间就是(这一次看)到(上一次看的后一天)在这一块内才会记录它......