2025.01.04模拟赛

今天也是……他的生日

拖着个不清醒的脑子就来打了。开局奶龙暴击。

T1本来想的贪心,结果发现贪心的复杂度只能拿10分(且貌似假了)。然后开始思考。想到区间,想到 cnt 数组双指针。然后脑子抽抽想不出来了。问了下sxht大巨,恍然大明白写出来了。嘻嘻

然后打暴力。那种脑子被封印的感觉又来了,明明保持清醒但难以深入思考。T2暴力打死了,没调;T3打了个暴力;T4感觉可暴力,但脑子被封印了……

最后T1 100分,T3 15分,总分115,没挂分

作业小链接


【T1 奶龙与薯片】

题目大意:

忘了

解题思路:

不知道咋就想到放数轴上了。然后双指针就行

阿西代码
#incIude <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+5;
const int inf=0x3f3f3f3f3f3f3f3f;
int T,k;
struct node { int col,x; }a[N];
int cnt[N];//每个颜色出现情况
int tol,ans;

bool cmp(node x,node y){ return x.x<y.x; }
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);

	cin>>T;
	while (T--)
	{
		tol=0,ans=inf;
		cin>>k;
		for (int i=1,c;i<=k;i++)
		{
			cnt[i]=0;
			cin>>c;
			for (int j=1,x;j<=c;j++)
			{
				cin>>x;
				a[++tol]={i,x};
			}
		}
		sort(a+1,a+1+tol,cmp);

		int l=1,r=0,cntt=0;//当前窗口出现颜色数量
		while (r<=tol)
		{
			if (cntt<k)//补后
			{
				r++;
				if (cnt[a[r].col]++==0) cntt++;
				continue;
			}
			while (cntt==k&&l<=r)//删前
			{
				if (cnt[a[l].col]==1) break;
				cnt[a[l].col]--,l++;
			}
			ans=min(ans,a[r].x-a[l].x);
			r++,cnt[a[r].col]++;
		}
		cout<<ans<<"\n";
	}
	return 0;
}

posted @   还是沄沄沄  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示