2024/3/7

B. Sifid and Strange Subsequences

原题链接:Problem - 1529B - Codeforces

题目大意:

给一个序列,要求找一个最长的子序列,子序列中每一对值的差的绝对值要比子序列中的最大值要大于等于,求这个最长子序列的长度。

题目做法:

可想而知的是,如果是两个正数的差,一定不会大于其中一个正数。

然后有个想法就这个最大值要尽可能地小,然后就想到排序,从最小的开始,记录相邻元素的差,如果最小的差小于当前最大值,则无法再取了,贪心吧。

AC代码:

#include<bits/stdc++.h>
#define pb(element) push_back(element)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
//#define ll long long
//Cara's templet version 1.20
//2024/3/7 13:54 UTC+8
//Kids' with no fire in their eyes
//Whose life ended when flame faded away
//And u mf plz hear my admonish
//Don't be that kind of kid
//Plz keep ur unique flame
//I wanna see ur blaze
using namespace std;
const int maxn=1e9+7;
void solve()
{
    int n,i;
    cin>>n;
    int ar[n];
    int mindiv=1e18+10;
    for(i=0;i<n;i++) cin>>ar[i];
    sort(ar,ar+n);
    // for(i=0;i<n;i++) cout<<ar[i]<<" ";
    // cout<<'\n';
    for(i=1;i<n;i++)
    {
        mindiv=min(mindiv,ar[i]-ar[i-1]);
        if(ar[i]>mindiv) break;
    }
    cout<<i<<'\n';
}
signed main()
{
    fast int casen=1;
	cin>>casen;
	while(casen--) solve();
}
B. High School: Become Human

原题链接:Problem - 987B - Codeforces

题目大意:

朴素的问题 x^{y} 和 y^{x} 之间的大小关系

题目做法:

统一底数用log统一,然后比较指数,需要注意的是log(1)这个为0,这个细节很重要。

AC代码:

#include<bits/stdc++.h>
#define pb(element) push_back(element)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
//#define ll long long
//Cara's templet version 1.20
//2024/3/7 13:54 UTC+8
//Kids' with no fire in their eyes
//Whose life ended when flame faded away
//And u mf plz hear my admonish
//Don't be that kind of kid
//Plz keep ur unique flame
//I wanna see ur blaze
using namespace std;
const int maxn=1e9+7;
void solve()
{
    double x,y;
    cin>>x>>y;
    double t=log(y)/log(x);
    if(x==1)
    {
        if(y==1)
        {
            cout<<"="<<'\n';
            return ;
        }
        else
        {
            cout<<"<"<<'\n';
            return ;
        }
    }
    if(y/t==x)
    {
        cout<<"="<<'\n';
        return ;
    }
    else if(y/t>x)
    {
        cout<<">"<<'\n';
    }
    else
    {
        cout<<"<"<<'\n';
    }
}
signed main()
{
    fast int casen=1;
	//cin>>casen;
	while(casen--) solve();
}
B. The Festive Evening

原题链接:Problem - 834B - Codeforces

题目大意:

有26个入口,k个守卫,n个客人。

要求在门开启的时候,必须要有一个守卫守着。

题目做法:

模拟,把开关门序列构造出来就好了。

AC代码:

#include<bits/stdc++.h>
#define pb(element) push_back(element)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
//#define ll long long
//Cara's templet version 1.20
//2024/3/7 13:54 UTC+8
//Kids' with no fire in their eyes
//Whose life ended when flame faded away
//And u mf plz hear my admonish
//Don't be that kind of kid
//Plz keep ur unique flame
//I wanna see ur blaze
using namespace std;
const int maxn=1e9+7;
struct node
{
    int type;
    int time;
};
bool cmp(node x,node y)
{
    if(x.time!=y.time) return x.time<y.time;
    else return x.type>y.type;
}
void solve()
{
    map<char,int> close,open;
    int n,k;
    cin>>n>>k;
    string str;
    cin>>str;
    vector<node> tc;
    for(int i=0;i<str.length();i++)
    {
        close[str[i]]=i;
        open[str[str.length()-1-i]]=str.length()-1-i;
    }
    for(auto its:close)
    {
        node t;
        t.type=0;
        t.time=its.second;
        tc.pb(t);
    }
    for(auto its:open)
    {
        node t;
        t.type=1;
        t.time=its.second;
        tc.pb(t);
    }
    sort(tc.begin(),tc.end(),cmp);
    int cur=0;
    // for(int i=0;i<tc.size();i++)
    // {
    //     cout<<tc[i].time<<" "<<tc[i].type<<'\n';
    // }
    for(int i=0;i<tc.size();i++)
    {
        if(tc[i].type==1) cur+=1;
        else cur-=1;
        if(cur>k)
        {
           cout<<"YES"<<'\n';
           return ;
        }
    }
    cout<<"NO"<<'\n';
}
signed main()
{
    fast int casen=1;
	//cin>>casen;
	while(casen--) solve();
}
C. Parity Shuffle Sorting

 原题链接:Problem - C - Codeforces

题目大意:

题目做法:

AC代码:

C. Yet Another Card Deck

原题链接:Problem - 1511C - Codeforces

题目大意:

题目做法:

AC代码:

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值