首页 > 其他分享 >CF1829G Hits Different

CF1829G Hits Different

时间:2023-05-07 10:13:36浏览次数:48  
标签:Hits int mid Different pos CF1829G ans now

题目地址

题意:有这样一个塔,初始全为蓝色,第i位上的数为i2,丢球丢中第k位时,将使得第k位和他头顶的数 以及 头顶的数的头顶的数 以及...都变成红色,求红色数的和

Solution

dp转移,我们把斜着向右下的所有数转移在一起,然后从第k位数开始往右上走,答案就是所有的和

void init()
{
	int now=1;
	int limit=1e6;
	for(int i=1;i<=limit;i++)
	{
		if(now*(now+1)/2<i)now++;
		a[i]+=i*i;
		if(i+now+1<=limit)
		a[i+now+1]+=a[i];
	}
}

void solve()
{
	int n;cin>>n;
	int l=1,r=1e6;
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(mid*(mid+1)/2>=n)r=mid;
		else l=mid+1;
	}
	int now=l; //二分找到n在哪一行
	int pos=n;
	int ans=0;
	while(now*(now+1)/2!=pos) 
	{
		ans+=a[pos];
		pos-=(now-1);//往回走
		now--;
	}
	ans+=a[pos];
	cout<<ans<<"\n";
}

标签:Hits,int,mid,Different,pos,CF1829G,ans,now
From: https://www.cnblogs.com/HikariFears/p/17378922.html

相关文章

  • CF1829G Hits Different
    话说这场比赛的题名字好像都是TaylorSwift的歌名。题意有一个由罐子排列成的金字塔,罐子自上而下依次编号:现在你要打下一个罐子,则与其有关的所有罐子也会被击落,计算所有被击落的罐子编号的平方和。比如说,你击中了\(9\)号罐子,则上图中所有标红的罐子都会被击落。\(n\le......
  • AtCoder Regular Contest 128 E K Different Values
    洛谷传送门AtCoder传送门考虑判断有无解。把序列分成\(c=\left\lceil\frac{len}{k}\right\rceil\)段,则\(\foralla_i\lec\)且\(\sum\limits_{i=1}^n[a_i=c]\le((len-1)\bmodk)+1\)。必要性显然。充分性可以考虑直接构造,不难证明。考虑如何构造字典序最小......
  • 递归比较两个字典差异-python dict different
    deffindDiff(d1,d2,path=""):forkind1:if(knotind2):print(path,":")print(k+"askeynotind2","\n")else:iftype(d1[k])isdict:......
  • Unable to create an object of type 'NetcoremvcDbcontext'. For the different patt
    问题描述:我整个项目重新生成没有报错,但是用efcore迁移数据库命令:Add-Migrationinit就生成不了文件夹Migrations,并且报错:Unabletocreateanobjectoftype'NetcoremvcDbcontext'.Forthedifferentpatternssupportedatdesigntime,seehttps://go.microsoft.com/fwlink/......
  • Hibernate_a different object with the same identifier value was already associat
    1、adifferentobjectwiththesameidentifiervaluewasalreadyassociatedwiththesession。错误原因:在hibernate中同一个session里面有了两个相同标识但是是不同实体。解决方法一:session.clean()PS:如果在clean操作后面又进行了saveOrUpdate(object)等改变数据......
  • Understanding the different flavors of Clang C and C++ compilers in Windows
    https://blog.conan.io/2022/10/13/Different-flavors-Clang-compiler-Windows.htmlThisarticlewillexplainthedifferentflavorsofClangCandC++compileryoumightencounterinWindows,andgiveyousomesuggestionsaboutwhichonesmightberightforyo......
  • Sum of Different Primes UVA - 1213
     选择K个质数,使它们的和等于N。问有多少种方案?例如,n=24,k=2时有3种方案:5+19=7+17=11+13=24 #include<iostream>#include<cstring>#include<cmath>#include<algorithm>usingnamespacestd;constintM=1e6+33;intb[M],c[M],tot;intn,m,f[2000][20];......
  • Your branch and 'origin/master' have diverged, and have 1 and 1 different commit
    当我们在本地提交到远程仓库的时候,如果遇到上述问题,我们可以首先使用如下命令:gitrebaseorigin/master 然后使用gitpull--rebase 最后使用gitpushoriginmaster 把......
  • ChIP-seq 分析:Differential Peaks(15)
    动动发财的小手,点个赞吧!1.寻找差异区域然而,识别特定于细胞系或条件的峰并不能捕获表观遗传事件的全部变化。为了识别表观遗传事件的差异,我们可以尝试量化IP样本中非......
  • algrothm_different【Integer+int】
    ......