cf div2 round 688 題解

tiany7發表於2020-12-05

爆零了,自閉了

小張做專案入職位元組

小李ak wf入職ms

我比賽爆零月薪3k

我們都有光明的前途

好吧,這場感覺有一點難了,昨天差點卡死在B上,要不受O爺出手相救我就boom zero了

第一題,看上去很唬人,我覺得還得記錄變數什麼的,1分鐘後發現只要查出兩個集合的交集大小就行了,連變數增量都不用,拿一血,此時rk 1k6,我人沒了

#include <bits/stdc++.h>
using namespace std;
#define limit (315000 + 5)//防止溢位
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f
#define lowbit(i) i&(-i)//一步兩步
#define EPS 1e-6
#define FASTIO  ios::sync_with_stdio(false);cin.tie(0);
#define ff(a) printf("%d\n",a );
#define pi(a,b) pair<a,b>
#define rep(i, a, b) for(ll i = a; i <= b ; ++i)
#define per(i, a, b) for(ll i = b ; i >= a  ; --i)
#define MOD 998244353
#define traverse(u) for(int i = head[u]; ~i ; i = edge[i].next)
#define FOPEN freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\data.txt", "rt", stdin)
#define FOUT freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\dabiao.txt", "wt", stdout)
#define debug(x) cout<<x<<endl
typedef long long ll;
typedef unsigned long long ull;
inline ll read(){   
    ll sign = 1, x = 0;char s = getchar();
    while(s > '9' || s < '0' ){if(s == '-')sign = -1;s = getchar();}
    while(s >= '0' && s <= '9'){x = (x << 3) + (x << 1) + s - '0';s = getchar();}
    return x * sign;
}//快讀
void write(ll x){
    if(x < 0) putchar('-'),x = -x;
    if(x / 10) write(x / 10);
    putchar(x % 10 + '0');
}
int kase;
int n,m,k;
int a[limit];
void solve(){
    cin>>n>>m;
    set<int>s;
    rep(i,1,n){
        int x;
        cin>>x;
        s.insert(x);
    }
    int tot = 0;
    rep(i,1,m){
        int x;
        cin>>x;
        if(s.find(x) != s.end())++tot;
    }
    cout<<tot<<endl;
}
int main() {
#ifdef LOCAL
    FOPEN;
#endif
    cin>>kase;
    while (kase--){
        solve();
    }
    return 0;
}

 

B題,我現在其實沒太搞懂這個怎麼搞的,挖坑

#include <bits/stdc++.h>
using namespace std;
#define limit (3150000 + 5)//防止溢位
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f
#define lowbit(i) i&(-i)//一步兩步
#define EPS 1e-6
#define FASTIO  ios::sync_with_stdio(false);cin.tie(0);
#define ff(a) printf("%d\n",a );
#define pi(a,b) pair<a,b>
#define rep(i, a, b) for(ll i = a; i <= b ; ++i)
#define per(i, a, b) for(ll i = b ; i >= a  ; --i)
#define MOD 998244353
#define traverse(u) for(int i = head[u]; ~i ; i = edge[i].next)
#define FOPEN freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\data.txt", "rt", stdin)
#define FOUT freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\dabiao.txt", "wt", stdout)
#define debug(x) cout<<x<<endl
typedef long long ll;
typedef unsigned long long ull;
inline ll read(){   
    ll sign = 1, x = 0;char s = getchar();
    while(s > '9' || s < '0' ){if(s == '-')sign = -1;s = getchar();}
    while(s >= '0' && s <= '9'){x = (x << 3) + (x << 1) + s - '0';s = getchar();}
    return x * sign;
}//快讀
void write(ll x){
    if(x < 0) putchar('-'),x = -x;
    if(x / 10) write(x / 10);
    putchar(x % 10 + '0');
}
int kase;
int n,m,k;
ll a[limit];
ll dp2[limit],dp[limit];
void solve(){
    cin>>n;
    ll tot = 0,ans = 0x3f3f3f3f3f3f3f;
    rep(i,1,n){
        cin>>a[i];
        dp[i] = 0;
        dp2[i] = 0;
    }
    dp2[1] = max(dp2[1],llabs(a[2] - a[1]));
    rep(i,2,n){
        ll tmp = llabs(a[i] - a[i - 1]);
        tot += tmp;
        dp[i] = tmp;
    }
    rep(i,1,n){
        if(i == 1){
            ans = min(ans , tot - dp[2]);
        }else if(i == n){
            ans = min(ans,tot - dp[n]);
        }
        else if((a[i] <= a[i + 1] && a[i] <= a[i - 1])){
            ans = min(ans,tot + abs(a[i - 1] - a[i + 1]) - dp[i + 1 ] - dp[i]);
        }else if(a[i] >= a[i + 1] && a[i] >= a[i - 1]){
            ans = min(ans,tot + abs(a[i + 1] - a[i - 1]) - dp[i + 1] - dp[i]);
        }
    }
    cout<<ans<<endl;
}
int main() {
#ifdef LOCAL
    FOPEN;
#endif
    cin>>kase;
    while (kase--){
        solve();
    }
    return 0;
}

 

C這個思路很顯然,就是看每次(1)是否能選取到兩個端點,然後貪心去放第三個頂點,因為我們可以改變一個格子,所以肯定要頂著1或者n放

(2)我們只用一個端點到兩邊,看哪個底大,是否能構成更大的三角形,頂點是否存在

(3)同上,但這次只有一個頂點

(4)這一行沒頂點,拉閘

極不好寫,100+的大暴力,給人寫自閉了,不過好在1A,寫完一身汗

#include <bits/stdc++.h>
using namespace std;
#define limit (315000 + 5)//防止溢位
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f
#define lowbit(i) i&(-i)//一步兩步
#define EPS 1e-6
#define FASTIO  ios::sync_with_stdio(false);cin.tie(0);
#define ff(a) printf("%d\n",a );
#define pi(a,b) pair<a,b>
#define rep(i, a, b) for(ll i = a; i <= b ; ++i)
#define per(i, a, b) for(ll i = b ; i >= a  ; --i)
#define MOD 998244353
#define traverse(u) for(int i = head[u]; ~i ; i = edge[i].next)
#define FOPEN freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\data.txt", "rt", stdin)
#define FOUT freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\dabiao.txt", "wt", stdout)
#define debug(x) cout<<x<<endl
typedef long long ll;
typedef unsigned long long ull;
inline ll read(){
    ll sign = 1, x = 0;char s = getchar();
    while(s > '9' || s < '0' ){if(s == '-')sign = -1;s = getchar();}
    while(s >= '0' && s <= '9'){x = (x << 3) + (x << 1) + s - '0';s = getchar();}
    return x * sign;
}//快讀
void write(ll x){
    if(x < 0) putchar('-'),x = -x;
    if(x / 10) write(x / 10);
    putchar(x % 10 + '0');
}
int kase;
int n,m,k;
ll a[limit];
int mp[2005][2006];
int l[2005][11],r[2005][11],up[2005][11],down[2006][11];
void solve(){
    cin>>n;
    rep(i,0,9)a[i] = 0;
    rep(i,1,n){
        string str;
        cin>>str;
        rep(h,0,9)l[i][h] = r[i][h] =down[i][h] =up[i][h] =0;
        rep(j,1,n){
            mp[i][j] = str[j-1] - '0';
        }
    }
    rep(i,1,n){
        rep(p,0,9){
            rep(j,1,n){
                if(mp[i][j] == p){
                    r[i][p] = j;
                    break;
                }
            }
            per(j,1,n){
                if(mp[i][j] == p){
                    l[i][p] = j;
                    break;
                }
            }
        }
    }
    rep(j,1,n){
        rep(p,0,9){
            rep(i,1,n){
                if(mp[i][j] == p){
                    down[j][p] = i;
                    break;
                }
            }
            per(i,1,n){
                if(mp[i][j] == p){
                    up[j][p] = i;
                    break;
                }
            }
        }
    }
    rep(p,0,9){
        rep(i,1,n){
            if(l[i][p] != r[i][p]){
                int base = abs(l[i][p] - r[i][p]);
                a[p] = max({a[p],base * abs(1 - i), base * abs(n - i)});
                base = max(abs(l[i][p] - 1), abs(l[i][p] - n));
                rep(j,1,n){
                    if(up[j][p])a[p] = max({a[p], base * abs(up[j][p] - i), base* abs(down[j][p] - i)});
                }
                base = max(abs(r[i][p] - 1), abs(r[i][p] - n));
                rep(j,1,n){
                    if(up[j][p])a[p] = max({a[p], base * abs(up[j][p] - i), base* abs(down[j][p] - i)});
                }
            }else if(l[i][p]){
                int base = max(abs(1 - l[i][p]),abs(l[i][p] - n));
                rep(j,1,n){
                    if(up[j][p])a[p] = max({a[p], base * abs(up[j][p]- i),base * abs(down[j][p] - i)});
                }
            }
            if(up[i][p] != down[i][p]){
                int base = abs(up[i][p] - down[i][p]);
                a[p] = max({a[p],base * abs(1 - i), base * abs(n - i)});
                base = max(abs(up[i][p] - 1), abs(up[i][p] - n));
                rep(j,1,n){
                    if(l[j][p])a[p] = max({a[p],base * abs(l[j][p] - i), base * abs(r[j][p] - i)});
                }
                base = max(abs(down[i][p] - 1), abs(down[i][p] - n));
                rep(j,1,n){
                    if(l[j][p])a[p] = max({a[p],base * abs(l[j][p] - i), base * abs(r[j][p] - i)});
                }
            }else if(up[i][p]){
                int base = max(abs(1 - up[i][p]),abs(down[i][p] - n));
                rep(j,1,n){
                    if(l[j][p])a[p] = max({a[p], base * abs(l[j][p]- i),base * abs(r[j][p] - i)});
                }
            }
        }
    }
    rep(i,0,9){
        cout<<a[i]<<' ';
    }
    cout<<endl;
}
int main() {
#ifdef LOCAL
    FOPEN;
#endif
    cin>>kase;
    while (kase--){
        solve();
    }
    return 0;
}

 

D題沒時間搞了,但後來和Dxtst老哥討論了下似乎是當前位上0或1,如果是1對於答案的貢獻為2^k, 其他結論今晚再搞

奧裡給!

相關文章