这一次的Div.2 大多数学思维。。

A. Park Lightingtime

https://codeforces.com/contest/1358/problem/A

题意:给一个n,m为边的矩形,问最少的灯使得整个矩形照亮

思路:n * m 为总区域数一个灯最多能照亮两块区域,贪心做:每次都取照亮两块

#include<bits/stdc++.h>
using namespace std;
int main() {
//freopen("in.txt","r",stdin);
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t, n, m; cin >> t;
while (t--) {
cin >> n >> m;
cout << (n * m) / 2 + (n *m) % 2 << endl;
}
}

B. Maria Breaks the Self-isolation

https://codeforces.com/contest/1358/problem/B

题意:每个人有一个聚会值,要求来了的人数(算同时来的)>=聚会值,问最多能拉到多少人

思路:和之前的cfdiv2一道分配人,每个人有经验值很像,那道题是sort后从前往后尺取,这道题sort就从后往前贪心

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=2e5+10;
typedef long long LL;
LL a[maxn];
int main()
{
LL t;cin>>t;
while(t--)
{
LL n;cin>>n;
for(LL i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+1+n);
if(a[n]<=n) cout<<n+1<<endl;
else
{
LL ans=1;LL sum=0;
for(LL i=n;i>=1;i--)
{
if(a[i]<=i)
{
sum+=i;break;
}
}
cout<<sum+1<<endl;
}
}
return 0;
}

C. Celex Update

https://codeforces.com/contest/1358/problem/C

题意:求(a,b)–>(c,d)的所有路径总数中有多少路径和不同的。

思路:考虑到xy变化,移动方法一定是 (x2 - x1) * (y2 - y1) ,然后发现自己到自己也是一种 故最后+1

#include<bits/stdc++.h>
using namespace std;
int main() {
//freopen("in.txt","r",stdin);
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
long long x1, x2, y1, y2, t;
cin >> t; while (t--) {
cin >> x1 >> y1 >> x2 >> y2;
cout << (x2 - x1) * (y2 - y1) + 1 << endl;
}
}

D. The Best Vacation

https://codeforces.com/contest/1358/problem/D

题意:每个月有d[i]天,有x天度假,要求连续,可以跨年,保证度假日子小于一整年。求d[i]求和最大的一段

思路:贪心+前缀和+二分

贪心:

有这么一段区间,贪A和贪B。

当bn(月的最后一天)>an-2,明显可以得出B是最优的。

那么当bn<an-2时,可以推出an-2>bn—->(等差递增)an>bn,而且a月比b月长且最大值更大,所以在a月的末尾作为最后一天最优。

所以贪心把末尾的一天放到月末。

然后我们利用前缀和统计每个月的天数和价值。然后枚举右端点,二分左端点,找到

sum[i]-sum[l]>x;且sum[i]-sum[l+1]<=x

那么价值为summoney[i]-summoney[l+1];再算多出的x部分–知道x多出有多少天,然后在多出的区间里用等差数列公式算出来。比如多出3天,就是那段区间的后三天的价值和。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 20;
typedef long long LL;
LL a[maxn];
LL sumday[maxn];
LL summoney[maxn];
int main(void)
{
LL n, x; cin >> n >> x;
for (LL i = 1; i <= n; i++)
{
cin >> a[i];
sumday[i] = sumday[i - 1] + a[i];
summoney[i] = summoney[i - 1] + (1 + a[i]) * a[i] / 2;
}
for (LL i = n + 1; i <= 2 * n; i++)
{
a[i] = a[i - n];
sumday[i] = sumday[i - 1] + a[i];
summoney[i] = summoney[i - 1] + (1 + a[i]) * a[i] / 2;
}
LL res = 0;
for (LL i = 1; i <= 2 * n; i++)
{
LL l = 0; LL r = i + 1;
//边界处理
//找出第一个区间差大于等于x的位置
while (l < r)
{
LL mid = (l + r) >> 1;
if (sumday[i] - sumday[mid] <= x) r = mid;
else l = mid + 1;
}
if (l == 0 || r == i + 1) continue;
LL resday = x - (sumday[i] - sumday[l]); LL sum = summoney[i] - summoney[l];
if (a[l] >= resday) sum += (2 * a[l] - resday + 1) * resday / 2;
res = max(res, sum); }
cout << res << endl;
return 0;
}

E、F待补。。。

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

  1. 05.24 ICPC 2019-2020 North-Western Russia Regional Contest复现赛+Codeforces Round #645 (Div. 2)

    A.Accurate Movement(复现赛) 题意:两个木块最左边都在0的位置,最右边分别为a,b(b>a),并且短的木条只能在长木条内移动,问两个木条需要移动多少次才能使两个木条的右端都在 ...

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

    题目链接:The Best Vacation 题意: 给你n个月份,每一个月份有di天.你可以呆在那里x天(x天要连续),如果你在某月的第y天呆在这.那么你的拥抱值就加y 1<=n<=2e ...

  3. Codeforces Round #645 (Div. 2) C. Celex Update

    题目链接:C.Celex Update 题意: 给你如图所示的图形,问从(x1,y1)−>(x2,y2)路径上的不同的元素和的数量是多少. 题解: 从(1,1)到(3,3) 元素和的1−2−4− ...

  4. Codeforces Round #645 (Div. 2) D. The Best Vacation (贪心,二分)

    题意:一年有\(n\)个月,每月有\(d_{i}\)天,找出连续的\(x\)天,使得这\(x\)天的日期总和最大,任意一年都能选. 题解:首先要先贪心,得到:连续的\(x\)天的最后一天一定是某个月的 ...

  5. 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 ...

  6. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  7. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  8. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  9. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  10. 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 ...

随机推荐

  1. 发现AI自我意识:不期而遇的局部技术奇点

    Q*的启示 之前的文章里提到过,人工智能思维能力创造的必不可少的条件是状态空间的搜索.今天的大新闻里,我们都看到了Q*的确使用了搜索算法.所以今天我会稍微谈一下这个话题. 主要思想就是人工智能的进一步 ...

  2. 12k Star、40万+开发者信赖的开源商城系统

    前几天,有位读者问我有没有什么优秀的国产开源电商平台,他要拿来接单赚外快.我一听这话,精神头就来了. 所以,今天 HelloGitHub 就给大家找来了一款自用.二开都很方便的国产开源商城系统--CR ...

  3. STM32外设:信号转换器 ADC、DAC

    主要外设: ADC:Analog to Digital Converter 模数转换器 DAC:Digital to Analog Converter 数模转换器 ADC_IN` 主要功能:测外部引脚 ...

  4. 使用CompletableFuture实现多个异步任务并行完成后合并结果

    业务场景 需要同时从多个副本数据库中查询数据,并对查询结果进行合并去重处理后返回前端. 实现过程涉及多数据源切换,这里不作过多讨论. 编码实现 实现过程: 1.定义异步查询数据方法: 2.通过Comp ...

  5. Kafka核心逻辑介绍

    1.概念 Kafka是最初由Linkedin公司开发,是一个分布式.支持分区的(partition).多副本的(replica)分布式消息系统(kafka2.8.0版本之后接触了对zk的依赖,使用自己 ...

  6. 什么是革命性技术eBPF?为什么可观测性领域都得用它

    公众号「架构成长指南」,专注于生产实践.云原生.分布式系统.大数据技术分享. 如果有一种技术可以监控和采集任何应用信息,支持任何语言,并且应用完全无感知,零侵入,想想是不是很激动,那么这个技术是什么呢 ...

  7. ElasticSearch之Force merge API

    使用本方法,可以触发强制合并操作. 默认情况下,ElasticSearch会在后台周期性触发合并操作,因此不需要用户刻意使用本方法. 使用强制合并的弊端: 可能会产生大于5G的segment对象,而E ...

  8. ncurses 与 panel

    ncurses 与 panel 一下是ncurses使用面板库panel的一个demo程序. #include <ncurses.h> #include <panel.h> # ...

  9. 以报时机器人为例详细介绍tracker_store和event_broker

      报时机器人源码参考[1][2],本文重点介绍当 tracker_store 类型为 SQL 时,events 表的表结构以及数据是如何生成的.以及当 event_broker 类型为 SQL 时, ...

  10. k8s集群Node节点管理:节点信息查看及节点label标签管理

    k8s集群Node节点管理:节点信息查看及节点label标签管理 Kubernetes集群Node管理 一.查看集群信息 [root@k8s-master1 ~]# kubectl cluster-i ...