当前位置:网站首页>UPC2022 Summer Individual Training Game 19 (B, P)
UPC2022 Summer Individual Training Game 19 (B, P)
2022-07-30 13:55:00 【.Ashy。】
B: 数学 (math)
大意:
求 n(n<=1e12) The number of scenarios to decompose into consecutive integer sums
思路:
Very clever math problem
We assume that the leading term of the sum of consecutive integers is a a a ,一共有 n n n 项 ,和为 S S S
则一定满足
S = ( 首项 + 末项 ) ∗ n 2 S={(首项+末项)*n \over2} S=2(首项+末项)∗n
化简就是
2 ∗ S = ( 2 ∗ a + n − 1 ) ∗ n 2*S=(2*a+n-1)*n 2∗S=(2∗a+n−1)∗n
There are obviously two unknowns a a a 和 n n n
如果我们枚举 a a a 和 n n n it will explode
1.分析 n n n 的范围:
n 是项数,当 a = 1 a=1 a=1时 n n n 最大 这时 2 ∗ S = ( n + 1 ) ∗ n 2*S=(n+1)*n 2∗S=(n+1)∗n
所以我们可以得到 n ∗ n < ( n + 1 ) ∗ n = 2 ∗ S n*n<(n+1)*n=2*S n∗n<(n+1)∗n=2∗S
所以 n < s q r t ( 2 ∗ S ) n<sqrt(2*S) n<sqrt(2∗S) n最大在 1.5e6 左右
2.分析 a a a 的范围:
And the first item is clearly available to us a 2 a\over2 2a So it's obviously not appropriate to enumerate two values
最大为2e11
After analyzing the complexity, we can clearly see what to do n n n下手,枚举所有的 n n n ,It can be judged whether the first item at this time is legal
The first term must be a positive integer
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
const int N = 2e5+10;
const int NN = 1e6+10;
const int pp = 1e9+7;
typedef pair<int,int>PII;
ll n,ans;
int main()
{
cin>>n;
for(ll i=2;i<=sqrt(n*2);i++)
{
ll k=((n*2)-i*i+i)%(i*2);
if(k==0&&((n*2)-i*i+i)/(i*2)>0) ans++;
}
cout<<ans;
return 0;
}
问题 P: Count Interval
大意:
给出 N 个数,Find the one that satisfies the following formula l ,r 有多少组
∑ i = l r A i = k \displaystyle\sum_{i=l}^rA_i=k i=l∑rAi=k
思路
We can optimize it with prefix sum,After the optimization is completed, it is satisfied s u m [ r ] − s u m [ l − 1 ] = k sum[r]-sum[l-1]=k sum[r]−sum[l−1]=k的 l , r 有多少组
This question has become typical A − B = k A-B=k A−B=k 问题;We can store and compute as we go,Every number we deal with is one A A A,Contribution is the first few miles B B B 的数量 也就是 A − K A-K A−K 的数量
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
const int N = 2e5+10;
const int NN = 1e6+10;
const int pp = 1e9+7;
typedef pair<int,int>PII;
ll sum[N];
ll n,k,t,ans;
map<ll,ll>mp;
int main()
{
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>t;
sum[i]=sum[i-1]+t;
}
mp[0]=1;
for(int i=1;i<=n;i++)
{
ans+=mp[sum[i]-k];
mp[sum[i]]++;
// cout<<ans<<endl;
}
cout<<ans;
return 0;
}
边栏推荐
- 【23考研】408代码题参考模板——顺序表
- Markdown 3 - 流程图表
- 学习笔记——七周成为数据分析师《第二周:业务》:业务分析指标
- VLAN实验
- R语言使用aov函数进行单因素协方差分析(One-way ANCOVA)、使用effects包中的effect函数来计算调整后的分组均值(calculate adjusted means)
- “12306” 的架构到底有多牛逼
- PyQt5快速开发与实战 8.6 设置样式
- Current and voltage acquisition module DAM-6160
- CF780G Andryusha and Nervous Barriers
- 域名抢注“卷”到了表情包?ENS逆势上涨的新推力
猜你喜欢
随机推荐
干货分享:小技巧大用处之Bean管理类工厂多种实现方式
matlab画图,仅显示部分图例
Raja Koduri澄清Arc GPU跳票传闻 AXG年底前新推四条产品线
TaskDispatcher源码解析
shell 编程规范与变量
Markdown 1 - 图文音视频等
HCIP(第十五天) —— 交换机(一)
元宇宙的六大支撑技术
TaskDispatcher source code parsing
libudev 使用说明书
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
LeetCode二叉树系列——102.二叉树的层序遍历
DeFi 巨头进军 NFT 领域 用户怎么看?
20220729 Securities, Finance
(一)Multisim安装与入门
ML之PDP:基于FIFA 2018 Statistics(2018年俄罗斯世界杯足球赛)球队比赛之星分类预测数据集利用DT决策树&RF随机森林+PDP部分依赖图可视化实现模型可解释性之详细攻略
阿里 P7 到底是怎样的水平?
selenium4+pyetsst+allure+pom进行自动化测试框架的最新设计
(HR面试)最常见的面试问题和技巧性答复
程序员修炼之道:务以己任,实则明心——通向务实的最高境界