牛客2022年七夕节比赛

整活场,所以整体的氛围也比较轻松

A 宝藏

答案就是在题目的答案上面,当时我打开后不知道为什么,魔方只打乱了一次,然后就我把那一下拨回去就还原了用时 1s

得到答案后截图,在用取色工具取色,然后输出RGB 码就好

#include<bits/stdc++.h>
using namespace std;
int main(){
    printf("17,69,20");
}

B 小红的孑串查询

可以发现1847/13/27/37/77*31*20.114514114514循环的,所以每 6 个位置就会出现一个开头的,所以当 n==11时期望个数就是 1,此后n每增加一,期望就会增加\(\frac{1}{6}\)

#include<bits/stdc++.h>
#define int long long
using namespace std;

const int mod = 1e9+7;

int power( int x , int y ){
    int ans = 1;
    while( y ){
        if( y & 1 ) ans = ( ans * x )% mod;
        y >>= 1;
        x = x * x % mod;
    }
    return ans;
}

int inv( int x ) {
    return power( x , mod - 2 ) % mod;
}

int32_t main() {
    int k;
    cin >> k;
    int cnt = k / 6 , cnt2 = max( 0ll , cnt - 1 ) , c = k % 6 + 1;
    int res = ( cnt * c + cnt2 * ( 6 - c ) ) % mod * inv(6) % mod;
    cout << res << endl;
    return 0;
}

D 潮or先辈

我选择程序题

起初是想通过暴力枚举的方法找到答案,分块发现自己 sb,最后在 b 题里面找到了 seed,自己复制输出就好了

#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    mt19937 rnd(1145141919810);
    cin >> n;
    for (int i = 1; i < n; ++i) {
        rnd();
    }
    cout << 2 <<' '<< rnd() << endl;
    return 0;
}

G 心有灵犀一点通

和出题人没有心有灵犀,于是随机过了

#include<bits/stdc++.h>
using namespace std;

int main(){
    mt19937 rnd(time(0));
    int a[12];
    a[1] = rnd()%6;
    a[2] = rnd()%6;
    a[3] = rnd()%4;
    a[4] = rnd()%7;
    a[5] = rnd()%4;
    a[6] = rnd()%4;
    a[7] = rnd()%4;
    a[8] = rnd()%4;
    a[9] = rnd()%4;
    a[10] = rnd()%4;
    for( int i =1 ; i <= 10 ; i ++ )
        cout << (char)('A'+a[i]);
}

J K 温温的那些年

经典的Havel-Hakimi定理。

  1. Havel-Hakimi定理主要用来判定一个给定的序列是否是可简单图化的。
  2. 首先介绍一下度序列:若把图 G 所有顶点的度数排成一个序列 S,则称 S 为图 G 的度序列。
  3. 一个非负整数组成的有限序列如果是某个无向图的序列,则称该序列是可简单图化的。
  4. 判定过程:
    1. 对当前数列排序,使其呈递减
    2. 从S[2]开始对其后S[1]个数字-1
    3. 一直循环直到当前序列出现负数(即不可简单图化的情况)或者当前序列全为0 (可简单图化)时退出。

对于 easy版本,每次暴力删除就好了

#include<bits/stdc++.h>
using namespace std;


int main(){
	int n ;
    vector<int> a , b;
	cin >> n;
	for( int i = 1 , x ; i <= n ; i ++ ){
        cin >> x;
        if( x >= n ){
            cout << "NO\n";
            return 0;
        } 
        a.push_back(x);
    }
    while(1){
        sort( a.begin() , a.end() , greater<int>() );
        int x = a[0];
        if( x == 0 ){
            cout << "YES\n";
            return 0;
        }
        for( int i = 1 ; i <= x ; i ++ ){
            if( a[i] > 0 ) b.push_back( a[i] - 1 );
            else{
                cout << "NO\n";
                return 0;
            }
        }
        for( int i = x + 1 ; i < a.size() ; i ++ )
            b.push_back( a[i] );
        a = b , b.clear();
    }
	return 0;
}

对于 hard版本,我赛场的做法是随机答案

#include<bits/stdc++.h>
using namespace std;

int main(){
	int n ;
    vector<int> a , b;
	cin >> n;
    
    if( n > 1000 ){
       mt19937 rnd(time(0));
        cout << ( rnd() & 1 ? "YES" : "NO" );
        return 0;
    }
	for( int i = 1 , x ; i <= n ; i ++ ){
        cin >> x;
        if( x >= n ){
            cout << "NO\n";
            return 0;
        } 
        a.push_back(x);
    }
    while(1){
        sort( a.begin() , a.end() , greater<int>() );
        int x = a[0];
        if( x == 0 ){
            cout << "YES\n";
            return 0;
        }
        for( int i = 1 ; i <= x ; i ++ ){
            if( a[i] > 0 ) b.push_back( a[i] - 1 );
            else{
                cout << "NO\n";
                return 0;
            }
        }
        for( int i = x + 1 ; i < a.size() ; i ++ )
            b.push_back( a[i] );
        a = b , b.clear();
    }
	return 0;
}

然后正解做法用线段树,我认为很麻烦。我用小根堆来维护序列,每次删掉堆顶,从堆中取出堆顶个元素,全部减一然后重新插入回堆中,如果取出负数就不可以,取出零就可以

#include<bits/stdc++.h>

using namespace std;

int read() {
    int x = 0, f = 1, ch = getchar();
    while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') f = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x * f;
}

int32_t main() {
    int n = read();
    priority_queue<int> q;
    vector<int> ve;
    for( int i = 1 , x ; i <= n ; i ++ ){
        x = read() , q.push(x);
        if( x >= n ){
            cout << "NO\n";
            return 0;
        }
    }

    while( 1 ){
        int k = q.top(); q.pop();
        if( k == 0 ){
            cout << "YES\n";
            return 0;
        }
        ve.clear();
        for( int x ; k ; k -- ){
            x = q.top() - 1 , q.pop();
            if( x < 0 ){
                cout << "NO\n";
                return 0;
            }
            ve.push_back(x);
        }
        for( auto it : ve )
            q.push(it);
    }
    return 0;
}

C 小红的情侣系统

挨个百度喽

#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s=="kirito")cout<<"asuna";
    if(s=="asuna")cout<<"kirito";
    if(s=="jiangly")cout<<"heltion";
    if(s=="heltion")cout<<"jiangly";
    if(s=="setsuna")cout<<"haruki";
    if(s=="haruki")cout<<"setsuna";
    if(s=="kazusa")cout<<"haruki";
    if(s=="haruhiko")cout<<"saki";
    if(s=="saki")cout<<"haruhiko";
    if(s=="takurou")cout<<"chizuru";
    if(s=="chizuru")cout<<"takurou";
    if(s=="yuzu")cout<<"mei";
    if(s=="mei")cout<<"yuzu";
    if(s=="izumi")cout<<"kyoko";
    if(s=="kyoko")cout<<"izumi";
    if(s=="kakeru")cout<<"remi";
    if(s=="remi")cout<<"kakeru";
    if(s=="rito")cout<<"lala";
    if(s=="lala")cout<<"rito";
    if(s=="momo")cout<<"rito";
    if(s=="nana")cout<<"rito";
    if(s=="yami")cout<<"rito";
    if(s=="mikan")cout<<"rito";
    if(s=="tomoya")cout<<"nagisa";
    if(s=="nagisa")cout<<"tomoya";
    if(s=="kyou")cout<<"tomoya";
    if(s=="sekai")cout<<"makoto";
    if(s=="kotonoha")cout<<"makoto";
    if(s=="makoto")cout<<"kotonoha";
    if(s=="sora")cout<<"haruka";
    if(s=="haruka")cout<<"sora";
}

E 七夕心动

\(t\ge8192\)时,一定会出现某一段的异或和为 0,那么结果一定是零

#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1e5+5 , mod = 1777777777;
int a[N] , res = 1;
int read() {
    int x = 0, f = 1, ch = getchar();
    while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') f = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x * f;
}

int32_t main() {
    int n = read();
    if( n >= 8192 ) cout << "0\n" , exit(0);
    for( int i = 1 ; i <= n ; i ++ ) a[i] = a[i-1] ^ read();
    for( int l = 1 ; l <= n ; l ++ )
        for( int r = l ; r <= n ; r ++ ){
            res = ( res * (a[r] ^ a[l-1]) ) % mod ;
            if( res == 0 ) cout << "0\n" , exit(0);
        }
    cout << res << "\n";
    return 0;
}

H 过了这道题你就能找到对象

当短边为 2 时,一直重复样例就好了

边长是\(3\times3\)时有

4 1 4
1 5 1
4 1 4

其他情况无解

#include<bits/stdc++.h>
using namespace std;

int32_t main() {
    int n , m ;
    cin >> n >> m;
    if( n == m && m == 3 ){
        cout << "4 1 4 \n 1 5 1 \n 4 1 4\n";
        return 0;
    }
    if(  n == 2 ){
        for( int i = 1 ; i <= m ; i ++ )
            if( i % 3 == 1 ) cout << "1 ";
            else if( i % 3 == 2 ) cout << "1 ";
            else if( i % 3 == 0 ) cout <<"4 ";
        cout << "\n";
        for( int i = 1 ; i <= m ; i ++ )
            if( i % 3 == 1 ) cout << "5 ";
            else if( i % 3 == 2 ) cout << "1 ";
            else if( i % 3 == 0 ) cout <<"4 ";
        return 0;
    }
    if( m == 2 ){
        for( int i = 1 ; i <= n ; i ++ )
            if( i % 3 == 1 ) cout << "1 1\n";
            else if( i % 3 == 2 ) cout << "4 5\n";
            else cout << "1 4\n";
        return 0;
    }
    cout << "heng heng heng, aaaa~\n";
    return 0;
}
posted @ 2022-08-09 15:21  PHarr  阅读(55)  评论(0编辑  收藏  举报