当前位置:网站首页>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;
}
边栏推荐
- libudev 使用说明书
- SQL 26 calculation under 25 years of age or older and the number of users
- What is the level of Ali P7?
- 【Advanced Mathematics】【7】Double Integral
- 一本通循环结构的程序设计题解(2)
- [ARC092B] Two Sequences
- [Go]四、模块和包、流程控制、结构体
- [论文翻译] Unpaired Image-To-Image Translation Using Cycle-Consistent Adversarial Networks
- [C# 循环跳转]-C# 中的 while/do-while/for/foreach 循环结构以及 break/continue 跳转语句
- Current and voltage acquisition module DAM-6160
猜你喜欢

人社部公布“数据库运行管理员”成新职业,OceanBase参与制定职业标准

LeetCode二叉树系列——144.二叉树的最大深度

js男女身高体重关系图

LeetCode二叉树系列——144.二叉树的最小深度

for循环的3个表达式执行顺序

ENVI图像处理(6):NDVI和植被指数

元宇宙的六大支撑技术

jsArray array copy method performance test 2207292307

BUUCTF刷题十一道(06)

ML之PDP:基于FIFA 2018 Statistics(2018年俄罗斯世界杯足球赛)球队比赛之星分类预测数据集利用DT决策树&RF随机森林+PDP部分依赖图可视化实现模型可解释性之详细攻略
随机推荐
【自校正控制】自校正PID
群晖系统安装相关文件分享
BUUCTF刷题十一道(06)
ARC117E零和范围2
干货分享:小技巧大用处之Bean管理类工厂多种实现方式
DeFi 巨头进军 NFT 领域 用户怎么看?
666666
No-code development platform all application settings introductory tutorial
ML之PDP:基于FIFA 2018 Statistics(2018年俄罗斯世界杯足球赛)球队比赛之星分类预测数据集利用DT决策树&RF随机森林+PDP部分依赖图可视化实现模型可解释性之详细攻略
Eleven BUUCTF questions (06)
jsArray array copy method performance test 2207300823
OFDM 十六讲 3- OFDM Waveforms
05 | 后台登录:基于账号密码的登录方式(下)
R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化分组箱图、使用ggpar函数改变图形化参数(xlab、ylab、改变可视化图像的坐标轴标签内容)
VLAN实验
程序员修炼之道:务以己任,实则明心——通向务实的最高境界
UPC2022暑期个人训练赛第19场(B,P)
重保特辑|筑牢第一道防线,云防火墙攻防演练最佳实践
ARC117E Zero-Sum Ranges 2
cpu / CS 和 IP