Codeforces Round 971 (Div. 4)
C. The Legend of Freya the Frog
因为是从x开始跳,贪心的取肯定是直接用max(a,b)/d向上取整然后再乘2,但是要注意,如果再x到达之前,y已经是到达了,也就是某次以后,y都取0,那么最终次数就要-1,因为最后不用再跳y方向的
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
void solve()
{
int x,y,d;
cin>>x>>y>>d;
int ans=max((x+d-1)/d,(y+d-1)/d);
ans*=2;
if((x+d-1)/d>(y+d-1)/d) ans--;
cout<<ans<<endl;
}
signed main()
{
int t=1; cin>>t;
while(t--) solve();
}
D. Satyam and Counting
分为两种情况
1.(x,0) (x,1),( )这里可以任意一点,所以这一种每一次可以贡献n-2
2.(x,0) (x+2,0),(x+1,1)和(x,1)(x+2,1) (x+1,0)
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int n;
cin>>n;
set<pair<int,int> >se;
for(int i=0;i<n;i++)
{
int x,y;
cin>>x>>y;
se.insert({x,y});
}
int ans=0;
for(auto [x,y]:se)
{
if(se.count({x+2,y}) &&se.count({x+1,y^1})) ans++;
if(y==0&&se.count({x,1}) ) ans+=n-2;
}
cout<<ans<<endl;
}
signed main()
{
int t=1;
cin>>t;
while(t--) solve();
}
E. Klee's SUPER DUPER LARGE Array!!!
直接二分答案,当cal(mid)> cal(mid+1)更新,对于绝对值里面的元素和,直接使用等差求和公式计算
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int n,k;
cin>>n>>k;
auto cal=[&](int x)
{
int res=0;
res+=(2*k+x-1)*x/2;
res-=(2*k+x+n-1)*(n-x)/2;
return abs(res);
};
int l=1,r=n;
while(l<=r)
{
int mid=(l+r)>>1;
if(cal(mid)>cal(mid+1)) l=mid+1;
else r=mid-1;
}
cout<<cal(l)<<endl;
}
signed main()
{
int t=1;
cin>>t;
while(t--) solve();
}
F. Firefly's Queries
基于官方题解我举样例方便读者理解
比如4 8 3 2 4 4 8 3 2 4,我们会发现这样接上去以后,从下标1-5开始每个数往后延4个数,便是翻转后的结果,比如从第二个数开始时8 3 2 4 4第三个数开始是3 2 4 4 8。
然后举l=2,r=13,(从0开始)|4 8 【3 2 4| 8 3 2 4 4| 3 2 4 4】 8|,那么答案就是pre【n】*3-左边那段翻转的对应位置的前缀和-右边那段翻转的对应位置后缀和
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int n,k;
cin>>n>>k;
vector<int>pre(1),ve(n);
for(auto &t:ve) {
cin>>t;
pre.push_back(pre.back()+t);
}
//按1 2 3 1 2 3这样排,前三个数字就是翻转的起点
for(auto t:ve)
{
pre.push_back(pre.back()+t);
}
// for(auto t:pre) cout<<t<<" ";
while(k--){
int l,r;
cin>>l>>r;
l--,r--;
int i,j;//i为翻转的起点,j同理
i=l/n, j=r/n;
l%=n,r%=n;//此时l,r分别为各自计算前缀和后缀的位置
cout<<pre[n]*(j-i+1)-(pre[i+l]-pre[i])-(pre[j+n]-pre[j+r+1])<<endl;
//pre[i+l]-pre[i]理解为计算前缀和
//pre[j+n]-pre[j+r+1]理解为计算后缀和
}
}
signed main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
Codeforces Round 971 (Div. 4)的更多相关文章
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- 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 ...
- 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 ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
随机推荐
- 面向对象(下)的阶段性复习:关键字abstract、模板方法的设计模式、关键字interface、代理模式、工厂的设计模式、类的结构内部类
关键字:abstract abstract: 抽象的1.可以用来修饰:类.方法2.具体的:abstract修饰类:抽象类 * > 此类不能实例化 * > 抽象类中一定有构造器,便于子类实例 ...
- AI编程:cursor使用教程
这是小卷对AI编程工具学习的第1篇文章,今天以cursor为例,通过给提示词,让不懂编程的小白也能自己用代码实现需求 1.什么是AI编程工具? 可以分为两类: 狭义的AI编程工具 面向程序员的,主要用 ...
- Django项目实战:解除跨域限制
Django项目实战:解除跨域限制 在Web开发中,跨域资源共享(CORS)是一个重要的安全特性,它限制了网页只能与其同源的服务器进行交互.然而,在开发过程中,我们经常需要前端(如Vue.js.Rea ...
- OneDrive分享、多人操作电脑中大文件的方法
本文介绍基于OneDrive网盘实现电脑大文件共享.协同办公的方法. 1 前言 作为网盘的重度用户,在学习.工作.生活中可以说少不了与各类云盘打交道.在这一过程中,也慢慢了解到不同网盘软件的特 ...
- C语言的头文件包含,竟存在这么多知识点!
文章来自:https://zhuanlan.zhihu.com/p/472808057 相关文章连接:头文件包含是可以嵌套的_[C语言]- 预处理指令3 - 文件包含! 很多事不深入以为自己懂了,但真 ...
- C51二进制数输入宏
在C语言中有十进制,十六进制,八进制;没有二进制的定义,在C51中使用十六进制表示有时不太直观,下面介绍几种方法表示二进制[均来自网络] 方法一 #define _BIN(a,b,c,d,e,f,g, ...
- vue打印浏览器页面功能的两种实现方法
目录 方法一:通过npm 安装插件 方法二:手动下载插件到本地 总结 推荐使用方法二 方法一:通过npm 安装插件 1,安装 npm install vue-print-nb --save 2,引入 ...
- Typecho头像被墙的解决方法
首先下载最新开发版本的TYPECHO,然后,在config.inc.php自定义如下: /** 自定义gravatar url前缀 */ define('__TYPECHO_GRAVATAR_PREF ...
- Kubernetes - [02] 网络通讯方式
题记部分 一.网络通讯模式 Kubernetes的网络模型假定了所有Pod都在一个可以直接连通的扁平的网络空间中,这在(GCEGoogle Compute Engine)里面是现成的网络模型,Ku ...
- Flink学习(五) Flink 的核心语义和架构模型
Flink 的核心语义和架构模型我们在讲解 Flink 程序的编程模型之前,先来了解一下 Flink 中的 Streams.State.Time 等核心概念和基础语义,以及 Flink 提供的不同层级 ...