Codeforces Round #707 (Div. 2)A~C题解
写在前边
链接:Codeforces Round #707 (Div. 2)
心态真的越来越不好了,看A没看懂,赛后模拟了一遍就过了,B很简单,但是漏了个判断重复的条件。
A. Alexey and Train
链接:A题链接
题目大意:
不想说了,题目看了半天没看懂,心态又看炸了。
思路:
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
using namespace std;
#define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n'
#define pub push_back
#define pob pop_back
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI;
const int Mod = 1000000007;
LL gcd(LL a, LL b) {
return b ? gcd(b, a % b) : a;
}
const int N = 110;
int a[N], b[N], tm[N];
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 1; i <= n; i++) {
cin >> tm[i];
}
int moment = 0;
for (int i = 1; i <= n; i++) {
moment = moment + a[i] - b[i - 1] + tm[i];
if (i == n) break;
int wait = (b[i] - a[i] + 1) / 2;
moment += wait;
if (moment >= b[i]) continue;
else moment = b[i];
}
cout << moment << endl;
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}
B. Napoleon Cake
链接:B题链接
题目大意:
就是往n层蛋糕上涂奶油,看最后有哪些层被奶油浸透。
思路:
- 双指针。
倒序枚举,枚举到一个涂有奶油的层,那么比它小的\(i - a[i] + 1\)都会被浸透,同时要注意如果遇到一个奶油更多的应该更新一下,比如1 0 0 0 4 3这个数据,枚举到3的时候,我们知道它能将蛋糕变成1 0 0 1 1 1,但是由于它的前边还有一个更厚的奶油,会使得蛋糕变成1 1 1 1 1 1所以应该要判断一下,详细说不清,看代码吧,主要要判断是否越界!
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
using namespace std;
#define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n'
#define pub push_back
#define pob pop_back
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI;
const int Mod = 1000000007;
LL gcd(LL a, LL b) {
return b ? gcd(b, a % b) : a;
}
const int N = 2e5 + 10;
int a[N];
bool st[N];
void solve() {
memset(st, false, sizeof(st));
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = n; i >= 1; i--) {
if (a[i] > 0) {
int j = i;
int temp = a[i];
while (temp) {
st[j] = true;
temp--;
j--;
if (j <= 0) break;
if (a[j] >= temp) break;
}
i = j + 1;
}
}
for (int i = 1; i <= n; i++) {
if (st[i]) printf("%d ", 1);
else printf("%d ", 0);
}
cout << endl;
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}
2.差分
让\(b[i + 1]--\), 让\(b[max(i - a[i] + 1, 1)]++\) 也挺巧妙。
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
using namespace std;
#define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n'
#define pub push_back
#define pob pop_back
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI;
const int Mod = 1000000007;
const int N = 2E5 + 10;
int b[N], n, a[N];
void solve() {
memset(b, 0, sizeof(b));
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
b[i + 1]--;
b[max(i - a[i] + 1, 1)]++;
}
for (int i = 1; i <= n; i++) b[i] += b[i - 1];
for (int i = 1; i <= n; i++) printf("%d ", (b[i] > 1 ? 1 : b[i]));
puts("");
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}
C. Going Home
链接:C题链接
题目大意:
给定\(n\)个数,找出四个坐标\(x,y,z,w\)使得\(a_x + a_y = a_z + z_w\)
思路:
这个题是真的没想到,暴力\(O(n^2)\)随便过,原理是抽屉原理,比如有8个苹果7个箱子,现在将苹果全部装入箱子,那么至少有一个箱子有两个苹果,而现在给了N个数,那么我们可以有\(N * (N - 1) / 2\)个对,如果\(\cfrac{N * (N - 1)}{2} > 5,000,000\),那么其中必然有和相同的对。一共可以枚举出\(\cfrac{n*(n - 1)}{2}\)个数对,但是由于两个数最大之和为\(5*10^6\),我们所能枚举到的和的个数最多也就是\(5*10^6\),我们可以把先枚举到的和存到一个数组里,而最多枚举到\(5*10^6\)个数我们就能接着枚举到一个重复的和,而大部分情况下根本不用枚举到\(5*10^6\)个数我们就能枚举到一个已经存在的数,那么跳出循环即可,所以复杂度就是\(O(min(n^2, n + c))\),做过好几个类似的题了,都是可以通过判断出最大枚举范围然后直接暴力来做的。
代码
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
using namespace std;
#define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n'
#define pub push_back
#define pob pop_back
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI;
const int Mod = 1000000007;
const int N = 2e5 + 10, M = 5e6 + 10;
int a[N];
PII temp[M];
void solve() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= n - 1; i++) {
for (int j = i + 1; j <= n; j++) {
int t = a[i] + a[j];
if (temp[t].first == 0 || temp[t].second == 0) {
temp[t] = {i, j};
continue;
} else {
if (temp[t].first != i && temp[t].first != j && temp[t].second != i && temp[t].second != j) {
puts("YES");
printf("%d %d %d %d\n", temp[t].first, temp[t].second, i, j);
return;
}
}
}
}
puts("NO");
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
solve();
return 0;
}
Codeforces Round #707 (Div. 2)A~C题解的更多相关文章
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #198 (Div. 2)A,B题解
Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...
- Codeforces Round #672 (Div. 2) A - C1题解
[Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...
- Codeforces Round #614 (Div. 2) A-E简要题解
链接:https://codeforces.com/contest/1293 A. ConneR and the A.R.C. Markland-N 题意:略 思路:上下枚举1000次扫一遍,比较一下 ...
- Codeforces Round #610 (Div. 2) A-E简要题解
contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...
- Codeforces Round #611 (Div. 3) A-F简要题解
contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...
- Codeforces Round #499 (Div. 2) D. Rocket题解
题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...
- Codeforces Round #499 (Div. 2) C Fly题解
题目 http://codeforces.com/contest/1011/problem/C Natasha is going to fly on a rocket to Mars and retu ...
- Codeforces Round #198 (Div. 2)C,D题解
接着是C,D的题解 C. Tourist Problem Iahub is a big fan of tourists. He wants to become a tourist himself, s ...
- Codeforces Round #579 (Div. 3) 套题 题解
A. Circle of Students 题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...
随机推荐
- 如何编写难以维护的React代码?耦合组件
如何编写难以维护的React代码?耦合组件 在许多项目中,我们经常会遇到一些难以维护的React代码.其中一种常见的情况是:子组件直接操作父组件方法,从而导致父子组件深度耦合.这样的实现让子组件过于依 ...
- C#.NET 国密SM4对称加解密 与JAVA互通 ver:20230731
C#.NET 国密SM4对称加解密 与JAVA互通 ver:20230731 .NET 环境:.NET6 控制台程序(.net core). JAVA 环境:JAVA8,带maven 的JAVA控制台 ...
- 【技术积累】Linux中的命令行【理论篇】【三】
apt-get命令 命令介绍 Debian Linux发行版中的APT软件包管理工具,apt-get命令 是Debian Linux发行版中的APT软件包管理工具.所有基于Debian的发行都使用这个 ...
- 利用选项卡提高Visual Studio 2022开发效率
设计器作为软件开发的必要工具,其效率的提高显得尤为重要.Visual Studio 2022作为一款功能强大的设计器,通过选项卡提高了工作效率,让开发者在使用过程中更加便捷. 在Visual Stud ...
- Spring Cloud Gateway Actuator API SpEL表达式注入命令执行漏洞(CVE-2022-22947)
描述: Spring Cloud Gateway 是基于 Spring Framework 和 Spring Boot 构建的 API 网关,它旨在为微服务架构提供一种简单.有效.统一的 API 路由 ...
- ctypes使用浅谈
什么是ctypes: ctypes 是 Python 的一个标准库,用于与 C 语言进行交互.它提供了一组工具和函数,可以方便地调用动态链接库(DLL)或共享对象(SO)中的 C 函数,并处理 C 数 ...
- Kafka-基础
1. 简介 Kafka(Apache Kafka) 是一种分布式流数据平台,最初由LinkedIn开发,并于后来捐赠给Apache软件基金会,成为了一个Apache顶级项目.它被设计用于处理大规模.实 ...
- xv6 中的进程切换:MIT6.s081/6.828 lectrue11:Scheduling 以及 Lab6 Thread 心得
絮絮叨 这两节主要介绍 xv6 中的线程切换,首先预警说明,这节课程的容量和第 5/6 节:进程的用户态到内核态的切换一样,细节多到爆炸,连我自己复习时都有点懵,看来以后不能偷懒了,学完课程之后要马上 ...
- Row Major
Smiling & Weeping ----昨天, 别人在我身旁大声说出你的名字, 这对于我, 像从敞开的窗口扔进了一朵玫瑰花. 思路:不客气地说,这是一道令人费解的题目,要求构造一个字符串, ...
- IOS 16 无法打开开发版或者企业版本APP解决方案 - 需要开启开发者模式
在IOS 16系统上,打开开发版本APP,或者企业版本APP时,会看到如下的提示信息: 需要开启开发者模式, xxx 需要在开发者模式下运行. 启用开发者模式前, 此App不可用 这个时由于IOS 1 ...