跳到正文

个人记录

比赛

Tommyy约 3 分钟
原文

这是 2026年4月13日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年4月10日
收录
2026年4月13日
更新
2026年11月15日
篇幅
约 3 分钟

版本

  1. v2当前
  2. v1

P1693 [USACO19FEB] Sleepy Cow Herding B

这题原本要找规律的,我最小找对了,最大没找对; 最大是差最大的减一,最小就是如果相邻两个差是2,那么就输出一,如果本来相邻就输出0和0;

代码

C++
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    int x=a[1]-a[0],y=a[2]-a[1];
    if(a[1]-a[0] == 1 and a[2]-a[1] == 1) 
    {
        cout <<0<< endl;
        cout <<0<< endl;
        return 0;
    }
    if(a[2]-a[1]==2 or a[1]-a[0]==2)
    {
        cout<<1<< endl;
    }
    else
    {
        cout<<2<< endl;
    }
    cout<<max(a[1]-a[0],a[2]-a[1]) - 1;
    return 0;
}

P1628 合并序列

这道题其实应该是代码最短的,就是要用find;

代码

C++
#include <iostream>
#include <algorithm>
using namespace std;
int n;
string k,a[1000005]; 
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
	cin>>k;
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++) 
    {
        if(a[i].find(k)==0)
       {
           cout<<a[i]<<endl;
       }
    }
	   
       
	return 0;
}

T750196 月色的花园绿化

这道题要用队列写要用小根堆来,1就是q.push(),2就是循环一下如果大于等于就q.pop(),否则break,每次都要输出q.size();

代码

C++
#include <bits/stdc++.h>
using namespace std;
priority_queue<int,vector<int>,greater<int>>q;
int T,x;
int main()
{
	cin>>T;
	while(T--)
	{
		int y;
		cin>>y;
		cin>>x;
		if(y==1)
		{
			q.push(x);
		}
		else
		{
			while(q.size()>0)
            {
                if(q.top()<=x)
                {
                    q.pop();
                }
                else
                {
                    break;
                }
            }
		}
		cout<<q.size()<<endl;
	}
	return 0;
}