纪中2020.5.30普及C组模拟赛总结

为啥全是求方案总数的题(晕)

T1

我们可以用暴力来找规律,会发现:

nans
11+2=3
21+2+3=6
31+2+3+4=10
41+2+3+4+5=15

总结起来可得出公式:
a n s = ( n + 1 ) ∗ ( n + 2 ) / 2 ans=(n+1)*(n+2)/2 ans=(n+1)(n+2)/2

A C   C o d e AC~Code AC Code

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
long long n;
int main()
{
	freopen("h2o.in","r",stdin);
	freopen("h2o.out","w",stdout);
	cin>>n;
	cout<<(n+1)*(n+2)/2;  //公式
    return 0;
}

T2

A C   C o d e AC~Code AC Code

未做出

T3

A C   C o d e AC~Code AC Code

未做出

T4

这道题以前考试做过(<_<)
前缀和+离散化+树状数组

A C   C o d e AC~Code AC Code

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
long long a[100010],f[100010];
long long n,m,c,ans,w;
struct node 
{
	long long sum,place;
}b[100010];
bool cmp(node a,node b)
{
	return a.sum<b.sum;
}
bool cmp2(node a,node b)
{
	return a.place<b.place;
}
int main()
{
	freopen("sequence.in","r",stdin);
	freopen("sequence.out","w",stdout);
	cin>>n>>m;
	for(int i=1; i<=n; i++)
	 {
		scanf("%lld",&a[i]);
		a[i]-=m;  //首先统计一轮单个
		b[i].sum=b[i-1].sum+a[i];  //前缀和
		b[i].place=i;  //离散化
		if(b[i].sum>=1)   //单个比较
		  ans++;
	 }
	sort(b+1,b+1+n,cmp);
	for(int i=1; i<=n; i++)
	 {
		if(b[i].sum!=w||i==1)
		  c++;
		w=b[i].sum;
		b[i].sum=c;  //算次数
	 }
	sort(b+1,b+1+n,cmp2);
	for(int i=1; i<=n; i++)
	 {
		for(int j=b[i].sum-1; j>=1; j-=j&(-j))  //树状数组
			ans+=f[j];
		for(int j=b[i].sum; j<=c; j+=j&(-j))
			f[j]++;
	 }
	cout<<ans;
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值