1. 程式人生 > 其它 >總之就是 CF 1535 A & B

總之就是 CF 1535 A & B

截至到我寫這篇文章前,我的做法還沒被 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

不會真的有人覺得我還做了其他題吧......