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为还需要的蜡烛数, ...
随机推荐
- oracle配置SGA参数不当导致不能正确启动数据库实例处理
原因:生成环境数据库想要增加数据库内存配置参数SGA_TARGET增加到42G,但是没有配置SGA_MAX_SIZE参数值,导致SHUTDOWN IMMEDIATE停止数据库,再STARTUP启动数据 ...
- 独“数”一帜 双证加冕!TeleDB亮相可信数据库发展大会
近日,2024可信数据库发展大会在北京召开,主题为"自主.创新.引领".大会重磅发布多项中国信通院及中国通信标准化协会大数据技术标准推进委员会(CCSA TC601)在数据库领域最 ...
- 解决Git拉取出现“bad config line 1 in file C:\Users\quber/.gitconfig”的错误
1.问题描述 我们在拉取Git项目的时候,突然出现如下图所示的错误提示: 2.解决办法 定位到.gitconfig文件,然后将其删除掉: 然后在项目文件夹中点击鼠标右键,选择Git Bash Here ...
- SQL注入之时间盲注
SQL注入之时间盲注 一.时间盲注原理 时间盲注技术的核心在于巧妙地运用数据库中的时间延迟函数(例如 MySQL 的 SLEEP() 函数或 PostgreSQL 的 PG_SLEEP() 函数)来验 ...
- Q:Win10关闭内存压缩功能
微软在Win10中就已经启用了内存压缩机制,在Win11当中继续了这一设定. 通过任务管理器查看. taskmgr ·通过命令行查看. 使用系统管理员权限,打开PowerShell,然后输入以下命令: ...
- MySQL8.0事务知识点
mysql8.0事务学习 1.基本概念 事务(Transaction)是访问和更新数据库的程序执行单元:是一个最小的不可分割的工作单元,能保证一个业务的完整性:事务中可能包含一个或多个sql语句,这些 ...
- 最新demo版|如何0-1开发支付宝小程序之前期准备篇(一)
小程序作为目前一种轻量.便捷的应用.目前应用越来越广泛了. 很多没有开发经验的开发同学可能初次接触就是小程序开发,为了详细讲解下小程序开发的步骤,我会按照小程序的开发流程一步一步从零开始给大家介绍下如 ...
- 如何通过 Python 实现一个消息队列,为在线客服系统与海外运营的APP对接
我在业余时间开发了一款自己的独立产品:升讯威在线客服与营销系统.陆陆续续开发了几年,从一开始的偶有用户尝试,到如今线上环境和私有化部署均有了越来越多的稳定用户. 而我收到的用户需求也越来越多,产品化的 ...
- Javascript 方法有多个参数有默认值,但是只想为其中某个参数赋值
例子: function log(a, b = 2, c = 3, d = 4) { console.log(a, b, c, d) } log(1); // output: 1 2 3 4 log( ...
- Android ADB 使用笔记
ADB 工作原理 当启动某个adb客户端时,该客户端会先检查是否有adb服务器正在运行,如果没有则启动服务器进程.服务器会在启动后与本地TCP端口 5037 绑定,并监听adb客户端 发出的命令. 服 ...