Codeforces Round #808 (Div. 2)

传送门https://codeforces.com/contest/1708

错过了,第二天vp的,只写出了AB就卡C了,竟然看不出是贪心555

A. Difference Operations

题意:给一个数组,由如下操作,问能不能使得\(a_2\) 到\(a_n\) 全为0

操作是选择一个i,使得\(a_i=a_i-a_{i-1}\) 。

:显然\(a_2\) 是\(a_1\)的倍数,才可能被剪成0,同理\(a_3 是a_2 被减过程中某个数字的倍数\)

那么意味着所有数字都得是\(a_1\)的倍数,并且中间不可以被0隔断。

#include <bits/stdc++.h>
signed main() {
int t;
std::cin >> t;
while (t--) {
int n;
std::cin >> n;
int a[110] = {0};
for (int i = 1; i <= n; i++)
std::cin >> a[i];
int k = a[1];
bool f = 1;
for (int i = 2; i <= n; i++) {
if (k == 0 && a[i] != 0 || a[i] % k != 0)
f = 0;
if (a[i - 1] == 0 && a[i])
f = 0;
}
if (f)
std::cout << "YES" << std::endl;
else
std::cout << "NO" << std::endl;
}
}

B. Difference of GCDs

题意:构造一个长度为n的数组,满足所有数字都在区间[l,r]内。

并且所有\(gcd(i,a_i )\) 的值互不相同。i

解法:因为\(gcd(i,a_i )<=i\) 又要互不相同,那么就必须$gcd(i,a_i )==i $ 也就是说\(a_i 必须是i的倍数\) 然后就在[l,r]里随便找个倍数就行了。找不到就输出NO

#include <bits/stdc++.h>
#define int long long
const int N = 1e5 + 10;
int a[N];
signed main() {
std::ios::sync_with_stdio(false);
int t;
std::cin >> t;
while (t--) {
int n, l, r;
std::cin >> n >> l >> r;
bool f = 1;
for (int i = 1; i <= n; i++) {
a[i] = 0;
for (int j = (l - 1) / i * i + i; j <= r; j += i) {
if (j >= a[i]) {
a[i] = j;
break;
}
}
if (!a[i])
f = 0;
}
if (!f) {
std::cout << "NO" << std::endl;
continue;
} else {
std::cout << "YES" << std::endl;
for (int i = 1; i <= n; i++)
std::cout << a[i] << " \n"[i == n];
}
}
}

C. Doremy's IQ

题意:有n天,第i天有考试i,难度为\(a_i\) 有起始智商q,当q<=0时她无法继续参加考试。

如果参加的考试\(a_i>q\)那么q--。

问如何选择哪几天考试能考的次数最多。答案以01串输出。

思路:贪心地想,掉智商肯定是越迟掉越好,如果在i天选择了掉智商的考试,那么之后也要义无反顾地考下去。于是,我们可以直接二分从哪天开始掉智商并能考完后面的全部考试的。求出i最小的方案即可输出。

#include <bits/stdc++.h>
#define int long long
const int N = 1e5 + 10;
int a[N];
int ans[N];
int n, q;
std::vector<int> ve;
bool check(int p) {
int qq = q;
for (int i = 1; i < p; i++) {
if (a[i] > qq) {
ans[i] = 0;
} else {
ans[i] = 1;
}
}
for (int i = p; i <= n; i++) {
ans[i] = 1;
if (a[i] > qq)
qq--;
}
return qq >= 0;
}
signed main() {
std::ios::sync_with_stdio(false);
int t;
std::cin >> t;
while (t--) {
std::cin >> n >> q;
for (int i = 1; i <= n; i++) {
std::cin >> a[i];
}
int l = 0, r = n;
while (l < r) {
int m = (l + r) >> 1;
if (check(m)) {
r = m;
} else
l = m + 1;
}
check(l);
for (int i = 1; i <= n; i++) {
std::cout << ans[i];
}
std::cout << "\n";
}
}

D. Difference Array

题意:给一个数组。让你把它变成它的差分数组,然后升序,继续变成差分数组...

直到最终只剩一个数字,输出这个数字。

思路:直接模拟肯定不行,但是发现,随着差分操作,一定会出现大量的0,而0和0的差分还是0,那么我们就可以直接把所有的0拿出来,每次操作减一,然后算上新生成的。其他过程就暴力模拟就好了。

#include <bits/stdc++.h>
#define int long long
const int N = 1e5 + 10;
int a[N];
signed main() {
std::ios::sync_with_stdio(false);
int t;
std::cin >> t;
while (t--) {
int n;
std::cin >> n;
std::vector<int> ve[2];
for (int i = 1; i <= n; i++) {
std::cin >> a[i];
ve[0].push_back(a[i]);
}
int now = 0;
int cost0 = 0;
while (ve[now].size() >= 2) {
std::sort(ve[now].begin(), ve[now].end());
ve[now ^ 1].clear();
if (cost0) {
ve[now ^ 1].push_back(ve[now][0]);
cost0--;
}
for (int i = 0; i < ve[now].size() - 1; i++) {
int k = ve[now][i + 1] - ve[now][i];
if (k == 0) {
cost0++;
} else
ve[now ^ 1].push_back(k);
}
now ^= 1;
}
if (ve[now].size() == 0)
std::cout << 0 << "\n";
else if (ve[now].size() == 1) {
std::cout << ve[now][0] << "\n";
} else if (cost0 >= 1) {
std::sort(ve[now].begin(), ve[now].end());
int k1 = ve[now][0], k2 = ve[now][1] - ve[now][0];
std::cout << std::abs(k1 - k2) << "\n";
} else
std::cout << std::abs(ve[now][0] - ve[now][1]) << "\n";
}
}

Codeforces Round #808 (Div. 2)的更多相关文章

  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. 模型 线框shader

    https://www.assetstore.unity3d.com/cn/?stay#!/content/21897

  2. trzcopy

    @echo offcd /d %~dp0setlocal enabledelayedexpansionset aa=伟大的中国!我为你自豪echo 替换前:%aa%echo 替换后:%aa:中国=中华 ...

  3. fail-fast简介

    转载请注明出处:http://www.cnblogs.com/skywang12345/p/3308762.html fail-fast简介(使用concurrentHashMap可以完美避免这个问题 ...

  4. How to Check and Repair EXT4 Filesystem in Linux

    The fsck (stands for File System Consistency Check) is used to check and repair one or more Linux fi ...

  5. Spring RMI 介绍

    Spring RMI RMI全称是Remote Method Invocation-远程方法调用,是纯Java的网络分布式应用系统的核心解决方案之一.Java RMI 支持存储于不同地址空间的程序级对 ...

  6. 20211306 2021-2022-2 《Python程序设计》第二次实验报告

    20211306 2021-2022-2 <Python程序设计>第二次实验报告 课程:<Python程序设计> 班级:2113 姓名:丁文博 学号:20211306 实验教师 ...

  7. labuladong数据结构

    缓存淘汰算法:LRU①.LFU② BST③ 完全二叉树④ 序列化和反序列化二叉树⑤ 最近公共祖先⑥ 单调栈⑦ 单调队列⑧ 递归反转链表⑨ k个一组反转链表

  8. mysql-列拆分

    tableA id warehouse_id 1 1,2 想要的结果: id warehouse_id 1 1 2 2 select *(其他的字段), substring_index(substri ...

  9. react+antd upload实现图片宽高、视频宽高尺寸校验

    图片宽高校验方法: // 上传图片尺寸限制 const checkIconWH = (file: any) => { return new Promise<void>(functio ...

  10. oracle 存过调试 stepinto stepover stepout

    step into:单步执行,遇到子函数就进入并且继续单步执行(简而言之,进入子函数): step over:在单步执行时,在函数内遇到子函数时不会进入子函数内单步执行,而是将子函数整个执行完再停止, ...