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 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...
随机推荐
- 王道oj/problem17
网址:http:oj.lgwenda.com/problem17 思路:指针其实就是存储地址的一个空间,LinkList=LNode* 代码: #define _CRT_SECURE_NO_WARNI ...
- 带你走进数仓大集群内幕丨详解关于作业hang及残留问题定位
本文分享自华为云社区<[带你走进DWS大集群内幕]大集群通信:作业hang.残留问题定位>,作者: 雨落天穹丶. 前言: 测试过程中,我们会遇到这样一种情况,我的作业都执行很久了,为啥还不 ...
- Thinkphp 5.x 远程代码执行漏洞利用小记
Thinkphp 5.x远程代码执行漏洞存在于Thinkphp 5.0版本及5.1版本,通过此漏洞,可以在远程执行任意代码,也可写入webshell 下面是对其进行的漏洞利用! 漏洞利用: 1,利用s ...
- Java 日志系列:JUL 使用和原理分析
目录 一. 简介 二.使用 三.日志级别 四.Logger 继承关系 五.配置文件 六.原理解析 一. 简介 JUL 全称 Java util Logging 是 java 原生的日志框架,使用时不需 ...
- 用了好几年的IDEA主题及配置,拿去吧不谢。
前言 最近这几年一直用一套IDEA的主题及配置,分享给各位,如果符合你的口味,可以下载了玩玩. 我个人是非常喜欢的,不管是观感还是敲代码都很爽的. 附上一张代码的主题色,大概就是这样子,我个人喜欢清爽 ...
- Jmeter读取结果文件报错Error loading results file解决方法
最近在项目性能测试过程中,遇到jmeter读取jtl文件出错的问题,如下图所示: 方法一:修改配置文件 将要读取结果文件的组件Configure界面配置都勾选上,默认情况下有些选项没勾选会出错. 第一 ...
- 虾皮shopee根据ID取商品详情 API 返回值说明
item_get-根据ID取商品详情 注册开通 shopee.item_get 公共参数 名称 类型 必须 描述 key String 是 调用key(必须以GET方式拼接在URL中) secr ...
- springBoot使用注解Aop实现日志模块
我们在日常业务操作中需要记录很多日志,可以在我们需要的方法中对日志进行保存操作,但是对业务代码入侵性大.使用切面针对控制类进行处理灵活度不高,因此我们可以使用自定义注解来针对方法进行日志记录 1.注解 ...
- 【matplotlib基础】--手绘风格
Matplotlib 中有一个很有趣的手绘风格.如果不是特别严肃的分析报告,使用这个风格能给枯燥的数据分析图表带来一些活泼的感觉. 使用手绘风格非常简单,本篇主要手绘风格的效果以及如何配置中文的支持. ...
- 在 Net7.0环境下通过反射创建泛型实例和调用泛型方法
一.介绍 最近没事干,就用闲暇时间写点东西,也记录一下温习历程.老人说的好,好记性,不如烂笔头.时间一长,当时记忆的再清楚,都会变得模糊,索性就写博客记录下来,如果下次需要,直接打开博客就找到了,不用 ...