Educational Codeforces Round 85 (Rated for Div. 2)

本文深入探讨了使用C++进行编程竞赛的高级技巧,包括快速输入输出、模板使用、常见算法实现及优化策略,旨在帮助程序员提升算法设计与实现能力。

在这里插入图片描述
开幕雷击,去世现场
A

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> pll;
template<class T>inline void rd(T &x){x=0;char o,f=1;while(o=getchar(),o<48)if(o==45)f=-f;do x=(x<<3)+(x<<1)+(o^48);while(o=getchar(),o>47);x*=f;}
const int inf=~0u>>2; //1073741823
const ll INF=~0ull>>2;//4611686018427387903
const int maxn=1e2+10;
int n,c[maxn],p[maxn];
void solve()
{
	rd(n);
	for(int i=1;i<=n;i++) rd(p[i]),rd(c[i]);
	for(int i=1;i<=n;i++)
	{
		if(p[i]<p[i-1]||c[i]<c[i-1]||p[i]<c[i]||c[i]-c[i-1]>p[i]-p[i-1])
		{
			puts("NO");
			return;
		}
	}
	puts("YES");
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("stdin.in","r",stdin);
	//freopen("stdout.out","w",stdout);
	#endif

	ll T;
    rd(T);
    while(T--)

	solve();
    return 0;
}

B

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> pll;
template<class T>inline void rd(T &x){x=0;char o,f=1;while(o=getchar(),o<48)if(o==45)f=-f;do x=(x<<3)+(x<<1)+(o^48);while(o=getchar(),o>47);x*=f;}
const int inf=~0u>>2; //1073741823
const ll INF=~0ull>>2;//4611686018427387903
const int maxn=1e5+10;
ll n,x,a[maxn];
void solve()
{
	ll sum=0,fin=0;
	rd(n),rd(x);
	for(ll i=1;i<=n;i++) rd(a[i]),sum+=a[i];
	sort(a+1,a+1+n);
	ll p=0;
	for(ll i=n;i>=1;i--)
	{
		if(sum/i>=x)
		{
			fin=i;
			break;
		}
		sum-=a[++p];
	}
	cout<<fin<<endl;
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("stdin.in","r",stdin);
	//freopen("stdout.out","w",stdout);
	#endif

	ll T;
    rd(T);
    while(T--)

	solve();
    return 0;
}

C

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> pll;
template<class T>inline void rd(T &x){x=0;char o,f=1;while(o=getchar(),o<48)if(o==45)f=-f;do x=(x<<3)+(x<<1)+(o^48);while(o=getchar(),o>47);x*=f;}
const int inf=~0u>>2; //1073741823
const ll INF=~0ull>>2;//4611686018427387903
const int maxn=300000+10;
ll n,a[maxn],b[maxn],c[maxn],temp,ans;
void solve()
{
	rd(n);
	for(ll i=1;i<=n;i++) rd(a[i]),rd(b[i]);
	for(ll i=2;i<=n;i++) c[i]=max(a[i]-b[i-1],0LL);
	c[1]=max(a[1]-b[n],0LL);
	temp=a[1];
	for(ll i=2;i<=n;i++) temp+=c[i];
	ans=temp;
	for(ll i=2;i<=n;i++)
	{
		temp-=(a[i-1]-c[i-1]+c[i]-a[i]);
		ans=min(ans,temp);
	}
	printf("%lld\n",ans);
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("stdin.in","r",stdin);
	//freopen("stdout.out","w",stdout);
	#endif

	ll T;
    rd(T);
    while(T--)

	solve();
    return 0;
}

D

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> pll;
template<class T>inline void rd(T &x){x=0;char o,f=1;while(o=getchar(),o<48)if(o==45)f=-f;do x=(x<<3)+(x<<1)+(o^48);while(o=getchar(),o>47);x*=f;}
const int inf=~0u>>2; //1073741823
const ll INF=~0ull>>2;//4611686018427387903
const int maxn=300000+10;
ll n,l,r,x,y,i;
void solve()
{
	rd(n),rd(l),rd(r);
	bool flag=l%2;
	x=i=1,y=2;
	while(i+2*(n-x)<l) i+=2*(n-x++);
	y=(l-i)/2+x+1;
	if(y>n) x=1;
	for(ll j=l;j<=r;j++)
	{
		if(flag) printf("%lld ",x);
		else
		{
			printf("%lld ",y++);
			if(y>n)
			{
				x++;
				y=x+1;
				if(x==n) x=1;
			}
		}
		flag=1-flag;
	}
	puts("");

}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("stdin.in","r",stdin);
	//freopen("stdout.out","w",stdout);
	#endif

	ll T;
    rd(T);
    while(T--)

	solve();
    return 0;
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值