总之就是 | CF 1535 AB 题解

截至到我写这篇文章前,我的做法还没被 Hack 掉,因此我就先在这里写一写

UPD:没有 fst

声明

我菜的一笔,只能做出来简单的题 A 和 B ,还都是 BF 拿分(

希望大家能把我瞎搞的做法 Hack 掉。

A Fair Playoff

洛谷 | CF1535A CF | 1535A

这个 A 一看就非常之......水。

题意简述

现有四个人比赛,他们的能力值分别为 \(a_1,a_2,a_3,a_4\)

比赛的顺序是前两个和后两个分别决出胜者,然后再进行比较。

能力值是决定输赢的唯一判断依据,现在需要判断给出的比赛队列是否公平(fair)。

比赛顺序公平,当且仅当最后决赛的两个人是能力值最高的和次高的人,否则比赛是不公平的,

现在有多组数据,让你判断比赛顺序是否公平。

思路简述

这个题实际上题面相当露骨,做法肯定多种多样,我在这里说一下个人拙见。

我是无脑暴力做的。

读入这四个人的能力之后,将前两个进行比较得到前一组的胜利者的能力值 mx1 ,同样的方法将后两个比较得出后一组的能力值 mx2 ,

然后我们 sort 一下,比较一下 mx1 和 mx2 是否分别对应最大值和次大值即可。

Code

可能有 亿 点长,因为我缺省源确实太长了。

#include <bits/stdc++.h>
#define Heriko return
#define Deltana 0
#define Romano 1
#define S signed
#define U unsigned
#define LL long long
#define R register
#define I inline
#define D double
#define LD long double
#define mst(a, b) memset(a, b, sizeof(a))
#define ON std::ios::sync_with_stdio(false)
using namespace std;
I void fr(LL & x)
{
    LL f = 1;
    char c = getchar();
    x = 0;
    while (c < '0' || c > '9') 
    {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') 
    {
        x = (x << 3) + (x << 1) + c - '0';
        c = getchar();
    }
    x *= f;
}
LL t;
I bool cmp(LL x,LL y)
{
    Heriko x>y;
}
S main()
{
    fr(t);
    while(t--)
    {
        LL a[5],mx1,mx2;
        fr(a[1]),fr(a[2]),fr(a[3]),fr(a[4]);
        if(a[1]>a[2]) mx1=a[1];
        else mx1=a[2];
        if(a[3]>a[4]) mx2=a[3];
        else mx2=a[4];
        sort(a+1,a+5,cmp);
        if((mx1==a[1] and mx2==a[2]) or (mx2==a[1] and mx1==a[2])) puts("YES");
        else puts("NO");
    }
    Heriko Deltana;
}

B Array Reodering

洛谷 | CF1535B CF | 1535B

这个题没想到是暴力能过......何老师看题少看了最后一行痛失 B 题。

题意简述

给你一个长度为 n 的序列 a ,定义 "好数对" 如下:

若有 i 和 j 满足

\[1 \le i < j \le n \ , \ gcd(a_i,2a_j) > 1 \]

那么则称 \((i,j)\) 是一对好数对。

现在给你这个序列 a ,并且这个序列你可以随意排序,求在你排序之后的 a 中有多少好数对。

思路简述

我个人是用的一种瞎搞的做法,咱也不知道是怎么想到的。

大约就是能被 2 整除的放在队首,否则放在队尾,

根据我自己口胡,这样做原因大概是是二的倍数的放在前面能够有效的增加好数对的个数?

可能是数据太水了吧,这完全瞎搞的做法能过( 249ms ),下面贴上代码。

Code

#include <bits/stdc++.h>
#define Heriko return
#define Deltana 0
#define Romano 1
#define S signed
#define U unsigned
#define LL long long
#define R register
#define I inline
#define D double
#define LD long double
#define mst(a, b) memset(a, b, sizeof(a))
#define ON std::ios::sync_with_stdio(false)
using namespace std;
I void fr(LL & x)
{
    LL f = 1;
    char c = getchar();
    x = 0;
    while (c < '0' || c > '9') 
    {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') 
    {
        x = (x << 3) + (x << 1) + c - '0';
        c = getchar();
    }
    x *= f;
}
I void fw(LL x)
{
    if(x<0) putchar('-'),x=-x;
    static LL stak[35];
    LL top=0;
    do
    {
        stak[top++]=x%10;
        x/=10;
    }
    while(x);
    while(top) putchar(stak[--top]+'0');
    putchar('\n');
}
LL gcd(LL x,LL y)
{
    Heriko ! y ? x : gcd(y,x%y);
}
LL t;
S main()
{
    fr(t);
    while(t--)
    {
        LL n,a[2001],b[2001],hd=0,tl,ans=0;
        fr(n);
        tl=n+1;
        for(R LL i=1;i<=n;++i) fr(a[i]);
        for(R LL i=1;i<=n;++i)
        {
            if(a[i]&1) b[--tl]=a[i];
            else b[++hd]=a[i];
        }
        for(R LL i=1;i<=n;++i)
            for(R LL j=i+1;j<=n;j++)
                if(gcd(b[i],b[j]*2)!=1) ans++;
        fw(ans);
    }
    Heriko Deltana;
}

还是那个巨长无比的缺省源(

End

不会真的有人觉得我还做了其他题吧......

posted @ 2021-06-11 18:49  HerikoDeltana  阅读(65)  评论(0编辑  收藏  举报