Codeforces Round #645 (Div. 2)

C Celex Update

[Link](Problem - C - Codeforces)

题意

​ 给你一个图片的矩形,问你从(x1,y1)(x_1,y_1)(x1​,y1​)到(x2,y2)(x_2,y_2)(x2​,y2​)每次只能向右或向下走,有多少个路径和不同的走法。

思路

  • 构造

​ 发现对于(i,j)(i,j)(i,j)这个点往右走(i,j+1)(i,j+1)(i,j+1)与(i+1,j)(i+1,j)(i+1,j)相比差一,也就是往下会比往上权值大一点,为了不重复计数,我们从最小的路径即一直右走然后下走为起点,刨去最后一列(这样每次往下扭都使得路径变的不一样),假设矩形为n×mn\times mn×m,一共可以往下扭n−1n -1n−1次,每行有m−1m-1m−1个位置往下扭,因此一共可以扭出(n−1)×(m−1)(n-1)\times (m-1)(n−1)×(m−1)种不同情况,再加上开始的最小路径,答案即(n−1)×(m−1)+1(n-1)\times (m-1)+1(n−1)×(m−1)+1。

Code

#include <bits/stdc++.h>
#define x first
#define y second
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ULL;
const int N = 2e5 + 10, M = 2 * N, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-8, pi = acos(-1), inf = 1e20;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int h[N], e[M], ne[M], w[M], idx;
void add(int a, int b, int v = 0) {e[idx] = b, w[idx] = v, ne[idx] = h[a], h[a] = idx ++;
}
int n, m, k;
int a[N];
int main() {ios::sync_with_stdio(false), cin.tie(0);int T;cin >> T;while (T -- ) {LL x1, y1, x2, y2;cin >> x1 >> y1 >> x2 >> y2;x1 = x2 - x1, y1 = y2 - y1;cout << x1 * y1 + 1 << '\n';}return 0;
}

D The Best Vacation

[Link](Problem - D - Codeforces)

题意

给你nnn个月,第iii个月有aia_iai​天,你可以连续休息xxx天(可以跨年休息),你的每天的权值是你休息的当天是该月的第几天,问你最大权值和是多少。

思路

  • 贪心 二分

​ 首先开个二倍数组令a[i+n]=a[i]a[i+n]=a[i]a[i+n]=a[i],这样就破环成链了。那么对于某个月第几天开始时这个月的最优解呢,假设从第iii个月的第xxx天开始到了第jjj个月的第yyy天,分类来看:

  • x>yx>yx>y,我们让起点xxx左移总权值会变大
  • x<yx<yx<y,我们让起点xxx右移总权值会变大

​ 或者可与考虑从第iii个月111天开始到了第jjj个月的第xxx天,显然让我们的起点右移一直到填满第jjj个月更优,这样也可以贪出来下面的结论。

​ 所以一般从最基本的情况来贪心会更方便。

​ 最终会变成某个月末+++一些连续的月份的形式,因此我们直接枚举每个iii对于当前位置看看它往前能到哪个位置,算一下贡献即可。

​ 可以将数组倒过来然后往后二分,也可以设sis_isi​为前iii个月的天数和,从我们要找si−sj≤x→sj≥si−xs_i-s_j\le x\to s_j\ge s_i-xsi​−sj​≤x→sj​≥si​−x,即从sss中找大于等于某个数的第一个数,这样直接二分也可。

Code

转一下

#include <bits/stdc++.h>
#define x first
#define y second
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ULL;
const int N = 4e5 + 10, M = 2 * N, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-8, pi = acos(-1), inf = 1e20;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int h[N], e[M], ne[M], w[M], idx;
void add(int a, int b, int v = 0) {e[idx] = b, w[idx] = v, ne[idx] = h[a], h[a] = idx ++;
}
int n, m, k;
LL a[N], s[N], x;
LL p[N];
int main() {ios::sync_with_stdio(false), cin.tie(0);cin >> n >> x;   for (int i = 1; i <= n; i ++) cin >> a[i], a[i + n] = a[i];reverse(a + 1, a + 1 + 2 * n);for (int i = 1; i <= n * 2; i ++) s[i] = s[i - 1] + (1 + a[i]) * a[i] / 2;for (int i = 1; i <= n * 2; i ++) a[i] += a[i - 1];LL res = 0, ans = 0;for (int i = 1; i <= n * 2; i ++) {        LL p = a[i] - a[i - 1];LL d = x - p;ans = (1 + p) * p / 2;if (d <= 0) {      res = max(res, (p + p - x + 1) * x / 2);continue ;}int l = i + 1, r = n * 2;while (l < r) {int mid = l + r >> 1;if (a[mid] - a[i] >= d) r = mid;else l = mid + 1;}if (l > r) {res = max(res, ans);continue ;}ans += (s[l - 1] - s[i]);d -= (a[l - 1] - a[i]);p = a[l] - a[l - 1];d = min(d, a[l] - a[l - 1]);ans += (p + p - d + 1) * d / 2;res = max(res, ans);}cout << res << '\n';return 0;
}

直接找

#include <bits/stdc++.h>
#define x first
#define y second
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ULL;
const int N = 4e5 + 10, M = 2 * N, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-8, pi = acos(-1), inf = 1e20;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int h[N], e[M], ne[M], w[M], idx;
void add(int a, int b, int v = 0) {e[idx] = b, w[idx] = v, ne[idx] = h[a], h[a] = idx ++;
}
int n, m, k;
LL a[N], s[N], x;
int main() {ios::sync_with_stdio(false), cin.tie(0);cin >> n >> x;   for (int i = 1; i <= n; i ++) cin >> a[i], a[i + n] = a[i];    for (int i = 1; i <= n * 2; i ++) s[i] = s[i - 1] + (1 + a[i]) * a[i] / 2;for (int i = 1; i <= n * 2; i ++) a[i] += a[i - 1];LL res = 0, ans = 0;for (int i = 1; i <= n * 2; i ++) {        if (a[i] < x) continue ;int p = lower_bound(a + 1, a + 1 + n * 2, a[i] - x) - a;ans = s[i] - s[p];LL tt = x - (a[i] - a[p]);ans += ((a[p] - a[p - 1]) * 2 - tt + 1) * tt / 2;res = max(res, ans);}cout << res << '\n';return 0;
}

E Are You Fired?

[Link](Problem - E - Codeforces)

题意

给你一个长度为nnn的数组其中前$\lceil \frac{n}{2}\rceil 为读入为读入为读入a_i,剩下的均为,剩下的均为,剩下的均为x,问是否存在一个,问是否存在一个,问是否存在一个k使得任意长度为使得任意长度为使得任意长度为k的子区间的和均的子区间的和均的子区间的和均>0$。

思路

  • 分类讨论 贪心

设m=⌈n2⌉,si=∑j=1iaim=\lceil \frac{n}{2}\rceil, s_i=\sum_{j=1}^{i}a_im=⌈2n​⌉,si​=∑j=1i​ai​,如果长度为kkk的区间满足那么长度为2×k2\times k2×k的区间也成立,因此我们只需要证明是否有大于n2\frac{n}{2}2n​的区间成立即可,xxx是个不确定因素,对于xxx分类来看:

  • x>0x>0x>0 当x>0x>0x>0 大于mmm位置的这些xxx带来的收益都是正的,我们应该照单全收,又因为要连续的子区间,我们只需要取k=nk=nk=n即可,如果不成立,那么其它的也均不可,因为我们减少kkk会使权值减少。
  • x=0x=0x=0 当x=0x=0x=0 和x>0x>0x>0时一样 直接选k=nk=nk=n即可。
  • x<0x<0x<0 当x<0x<0x<0 我们一定要把后面的这些xxx都消除掉,这个时候我们从前往后枚举每个位置看当前iii到mmm的这个区间的和能消除多少个xxx,因为要让所有的区间均满足,即当前iii满足的区间长k1k_1k1​它前面的点也要满足,我们搞一个合法长度前缀最小值,然后如果当前点加前缀最小值−1-1−1到达nnn了即为一组合法解,注意前缀最小值要满足≤n\le n≤n。

Code

#include <bits/stdc++.h>
#define x first
#define y second
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ULL;
const int N = 5e5 + 10, M = 2 * N, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-8, pi = acos(-1), inf = 1e20;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int h[N], e[M], ne[M], w[M], idx;
void add(int a, int b, int v = 0) {e[idx] = b, w[idx] = v, ne[idx] = h[a], h[a] = idx ++;
}
LL n, m, k;
LL a[N];
int main() {ios::sync_with_stdio(false), cin.tie(0);cin >> n;m = (n + 1) / 2;for (int i = 1; i <= m; i ++) cin >> a[i];cin >> k;for (int i = m + 1; i <= n; i ++) a[i] = k;for (int i = 1; i <= n; i ++) a[i] += a[i - 1];if (k >= 0) {cout << (a[n] > 0 ? n : -1) << '\n';return 0; }LL res = 1e9;for (int i = 1; i <= m; i ++) {LL s = a[m] - a[i - 1];res = min(res, m - i + 1 + (s - 1) / (-k));if (i + res - 1 >= n) {cout << min(res, n) << '\n';return 0;}}cout << -1 << '\n';return 0;
}

Codeforces Round #645 (Div. 2)相关推荐

  1. codeforces Round #645 (Div. 2)D题解

    Codeforces Round #645 (Div. 2)--D题解 作为一名菜鸡,理所当然得没有A出来,这道题数据放小就一水题了,可惜数据这块卡的死死的. 本题最重要的一点就是你要推出来一个结论: ...

  2. Codeforces Round #645 (Div. 2) D. The Best Vacation

    Codeforces Round #645 (Div. 2) D. The Best Vacation 题目链接 You've been in love with Coronavirus-chan f ...

  3. Codeforces Round #645 (Div. 2)(D.The Best Vacation)

    题目链接:https://codeforces.com/contest/1358/problem/D 思路:双指针+前缀和 前缀和主要处理了两组数据:sum[]是某月到某月的天数,ans[] 代表某月 ...

  4. Codeforces Round #645 (Div. 2)(AB)

    Park Lighting CodeForces - 1358A 思路:水题不解释. 代码如下: #include<bits/stdc++.h> #define ll long long ...

  5. Codeforces Round #645 (Div. 2) / contest 1358

    目录 A Park Lighting B Maria Breaks the Self-isolation C Celex Update D The Best Vacation E Are You Fi ...

  6. 双指针--Codeforces Round #645 (Div. 2) d题

    D. The Best Vacation 题目大意: 算出连续x天最多的拥抱,一个月第i号就有i个拥抱 思路:双指针,扫描过去(每个月每个月的计算,最后超出的部分再一天一天算) 代码 : #inclu ...

  7. 思维--找规律--Codeforces Round #645 (Div. 2) c题

    C. Celex Update 题目大意:给出两点的坐标,找出不同的路径的总数(路径数字总和不同) 思路:根据观察向下走比向右走的增加幅度加1,所以在第i步 向下 对sum的影响是 n-i+1 所以最 ...

  8. Codeforces Round #645 (Div. 2) D - The Best Vacation 题解(二分+思维)

    题目链接 题目大意 一年有n个月,每个月有d[i]天,让你找出连续x天,使其日期的总和最大,可以跨年 题目思路 这里要发现一个性质:即连续的x天一定满足最后一天在月份的结尾,结论是显然的. 然后用两个 ...

  9. Codeforces Round #645 (Div. 2) E - Are You Fired? 题解(思维)

    题目链接 题目大意 给你一个长为n的数组前(n+1)/2个数为a[i],后面的数为x,让你求出一个长度k使其所有连续为k的数组之和都大于0 题目思路 首先要找性质,如果k满足,那么显然k*2也满足那么 ...

  10. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

最新文章

  1. 爬虫之JS的解析确定js的位置
  2. hanlp中的N最短路径分词
  3. 船舶双向曲率板曲率可视化研究
  4. java基础学习总结——对象转型
  5. mysql更改数据语句6_MySQL的SQL语句 - 数据定义语句(6)- ALTER TABLE 语句(1)
  6. mysql索引底层图_MySQL索引底层数据结构
  7. 【.Net】C#实现多线程的方式:使用Parallel类
  8. javascript基础知识(3) 基本语法
  9. Java中Date和Calender类的使用方法
  10. 机器学习系列------1. GBDT算法的原理
  11. 哪些英语母语者常用的词组对于普通中国大学生来说是生疏的?
  12. 【优化算法】蛾群优化算法(MSA)【含Matlab源码 1451期】
  13. 今日干货:PDF转Word工具有哪些?
  14. C语言宏定义-跟踪调试宏
  15. C++:函数指针进阶(三):Lambda函数详解
  16. c 语言 如何设置串口波特率,STC89C52RC串口波特率程序
  17. 三维GIS可视化技术在智慧城市基本建设中的作用
  18. C语言------函数
  19. 【PAT乙级】1031 查验身份证
  20. linux rootkit手动排查,Linux Rootkit如何避开内核检测的

热门文章

  1. Spring AOP基础组件 Advised
  2. [译]-100行代码从零实现 Facebook 的 Recoil 库
  3. 2020牛客暑期多校训练营(第九场) Groundhog and Gaming Time
  4. java程序员怎么创建自己的网站:第一章:总体流程,我崩溃了
  5. iOS - 手机摇一摇
  6. 西南石油大学计算机科学学院李欣,南充西南石油大学财经学院学霸寝室 6女生一年70张奖状...
  7. java序号带圈_疯狂创客圈 -- Java 高并发社群
  8. 实验吧-Web-天网管理系统
  9. python躲方块_pygame实现的《躲小球》
  10. linux内核态文件操作filp_open/filp_close/vfs_read/vfs_write