跳到正文

个人记录

# AtCoder 408 赛后整理

weberzcm约 3 分钟
原文
文章信息与版本

文章信息

发布
2025年5月31日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 3 分钟

版本

  1. v1当前

A.Timeout

题目

思路分析

模拟,计算每次间隔的时间是否大于SS,然后判断输出。

Tips:水题一道

代码:

C++
#include<bits/stdc++.h>
#define N 105
#define M 100005
#define int long long
using namespace std;
int n,k,a[N],f; 
signed main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]-a[i-1]>k)//判断间隔时间是否大于
		{
			f=1;//标记
		}
	}
	if(f)
	{
		cout<<"No";
	}
	else
	{
		cout<<"Yes";
	}//判断输出
  return 0;
}

B.Compression

题目

思路分析

简单去重,没啥好说的。

Tips:比第一题还水

代码:

C++
#include<bits/stdc++.h>
#define N 105
#define M 100005
#define int long long
using namespace std;
int n,a[N],s[N],cnt,b[N]; 
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(s[a[i]]==0)
		{
			s[a[i]]=1;//标记
			b[++cnt]=a[i];//存进答案数组
		}
	}
	sort(b+1,b+1+cnt);
	cout<<cnt<<endl;
	for(int i=1;i<=cnt;i++)
	{
		cout<<b[i]<<" ";
	}
  return 0;
}
//拿到这个题我是真无语了

C.Not All Covered

题目

思路分析

每次覆盖一段区间,容易想到差分,求出所有城堡节点的防御值,求个最小值就完事了。

Tips:海星,微水

代码:

C++
#include<bits/stdc++.h>
#define N 1000005
#define M 100005
#define int long long
using namespace std;
int n,m,l,r,s[N],ans=N+10;
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>l>>r;
		s[l]++;
		s[r+1]--;
    //差分板子
	}
	for(int i=1;i<=n;i++)
	{
		s[i]+=s[i-1];//求差分原数组
		ans=min(ans,s[i]);//求最小值
	}
	cout<<ans;
  return 0;
}

以上就是本次ABC中做出的三道题了。剩余题目较难,本篇文章中不做讲解。

原文