牛客:浙江農(nóng)林大學(xué)2022年新生杯程序設(shè)計(jì)競賽(同步賽)VP題解-創(chuàng)新互聯(lián)

五個(gè)小時(shí)真是折磨,寫完直接痿了,站不起來了(bushi 題目鏈接

在這里插入圖片描述

元氏網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,元氏網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為元氏上1000家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的元氏做網(wǎng)站的公司定做!

1.png

A 打印煎餅(1x)

直接輸出

php代碼?
|       _ ____   _____  _____  |
|      | |  _ \ / ____|/ ____| |
|      | | |_) | |  __| |  __  |
|  _   | |  _<| | |_ | | |_ | |
| | |__| | |_) | |__| | |__| | |
|  \____/|____/ \_____|\_____| |

B 打印煎餅(2x)

將原矩陣的每個(gè)字符輸出兩次,同時(shí)每行也輸出兩次

#includeusing namespace std;

using i64 = long long;

int main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int n,m;
    std::cin >>n >>m;
    for (int i = 0; i< n; i ++) {string s;
        std::cin >>s;
        for (int u = 0; u< 2; u ++) {for (int j = 0; j< m; j ++) {for (int k = 0; k< 2; k ++) {std::cout<< s[j];
                }
            }
            std::cout<< "\n";
        }
    }
    return 0;    
}

C 這個(gè)彬彬打起電動(dòng)超勇的

由于題目數(shù)據(jù)小,不搞一些花哨操作,直接判斷每組尋問中是否有被抓的可能

#includeusing namespace std;

using i64 = long long;

void solve()
{int a,b,c,d;
    std::cin >>a >>b >>c >>d;

    int q;
    std::cin >>q;

    bool ok = false;
    while (q -- ) {int x;
        std::cin >>x;
        if ((x >= a and x<= b) or (x >= c and x<= d)) ok = true;
    }
    if (ok) std::cout<< "Y\n";
    else std::cout<< "N\n";
}

int main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int T;
    std::cin >>T;
    while (T -- ) {solve();
    }
    return 0;    
}

D jbgg爆金幣咯 題解

1.png

#includeusing namespace std;

#define int long long

void solve()
{int n,m,x;
    std::cin >>n >>m >>x;

    std::vectora(n + 10),b(m + 10),A(x + 10),S(x + 10);

    for (int i = 1; i<= n; i ++) {std::cin >>a[i];
    }

    for (int j = 1; j<= m; j ++) {std::cin >>b[j];
    }

    for (int i = 1; i<= x; i ++) {for (int j = 1; j<= n; j ++) {if (i<= a[j] or S[i - a[j]] == 0) {A[i] = 1;
            }
        }

        for (int j = 1; j<= m; j ++) {if (i<= b[j] or A[i - b[j]] == 0) {S[i] = 1;
            }
        }
    }

    
    if (A[x]) std::cout<< "AsindE\n";
    else std::cout<< "slwang\n";
}

signed main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int T;
    std::cin >>T;
    while (T -- ) {solve();
    }
    return 0;    
}

E 視力不好的yyjj

bi為a中下標(biāo)為i的倍數(shù)的元素和,即b1 = a(1-n),b2 = a(2,4…).所以b1包含了a數(shù)組的所有元素。 我們可以通過
消除其他項(xiàng)與b1共有的數(shù)。如圖
6.jpg
要消去b4中的a8,b3中的a6,b2中的a4,a6,a8.最后通過b1便可得出a1

#includeusing namespace std;

#define int long long

signed main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int n;
    std::cin >>n;
    std::vectorb(n + 1);

    for (int i = 1; i<= n; i ++) {std::cin >>b[i];
    }

    for (int i = n; i >= 1; i --) {//逆序消
        for (int j = i + i; j<= n; j += i) {b[i] -= b[j];
        }
    }

    std::cout<< b[1]<< "\n";
    return 0;    
}
小細(xì)節(jié):枚舉bi的時(shí)候要逆序枚舉,這樣消可以省去很多麻煩,附圖:

2.png

因慣性思維,沒有逆序枚舉,導(dǎo)致少考慮一些情況(如消多了)而多WA了3發(fā)。以此為誡
F 楊神的命名法

按照題意模擬即可

#includeusing namespace std;

using i64 = long long;

void solve()
{string s;
    std::cin >>s;

    int n = s.size();

    for (int i = 0; i< n; i ++) {if (!i) {s[i] = tolower(s[i]);
            continue;
        }
        if (s[i] >= 'A' and s[i]<= 'Z') {s[i] = tolower(s[i]);
            s[i - 1] = toupper(s[i - 1]);
        }
    }
    s[n - 1] = toupper(s[n - 1]);
    std::cout<< s<< "\n";
}

int main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int T;
    std::cin >>T;
    while (T -- ) {solve();
    }
    return 0;    
}

G 汽車人變形

dfs; 明顯可以看出答案是一條鏈,我們應(yīng)該找到一個(gè)入度為0的點(diǎn)進(jìn)行搜,取搜到的大值即可。
這里直接以每一個(gè)點(diǎn)作為根節(jié)點(diǎn)搜了起來

#includeusing namespace std;

#define int long long
const int N = 5e3 + 10;
std::vectora(N);
std::vector>>g(N);
std::vectorf(N);
int res = 0;
void dfs(int u,int fa)
{int ans = 0;
    for (auto [k,v] : g[u]) {if (k == fa) continue;
        dfs(k,u);
        res = std::max(res,ans + a[u] + v + f[k]);
        ans = std::max(ans,f[k] + v);
        f[u] = std::max(f[u],ans);
    }

    f[u] += a[u];
    res = std::max(res,f[u]);
}

signed main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int n;
    std::cin >>n;


    for (int i = 1; i<= n; i ++) {std::cin >>a[i];
    }
    for (int i = 1; i< n; i ++) {int a,b,c;
        std::cin >>a >>b >>c;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }

    dfs(1,1);

    std::cout<< res<< "\n";
    return 0;    
}
匿名函數(shù)dfs寫完一直報(bào)錯(cuò),調(diào)了半小時(shí),所幸直接仍外邊了,不知道為啥。很煩!
H 車車的愛之矩陣

一種簡單的解法:直接用1和-1構(gòu)造這個(gè)矩陣,容易知道,只有當(dāng)1和-1交替出現(xiàn)時(shí)才能滿足題意

#includeusing namespace std;

#define int long long

void solve()
{int n,m;
    std::cin >>n >>m;
    
    for (int i = 1; i<= n; i ++) {for (int j = 1; j<= m; j ++) {std::cout<< ((i + j) % 2 ? "1" : "-1")<< " \n"[j == m];
        }
    }
}

signed main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int T;
    std::cin >>T;
    while (T -- ) {solve();
    }
    return 0;    
}
這里起初是用異或?qū)懙?,奈何某些地方?jīng)]有被賦上值。最后沒時(shí)間了,改了改
I 異或和

I題最后沒時(shí)間寫了,有空再補(bǔ)


J 磊神的慈悲

考慮使用并查集,最后輸出每個(gè)的祖先

#includeusing namespace std;

#define int long long

const int N = 2e5 + 10;

int pre[N];

int find(int x)
{return x == pre[x] ? pre[x] : pre[x] = find(pre[x]);
}

signed main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int n,m;
    std::cin >>n >>m;

    std::vectora(n + 1);

    for (int i = 1; i< N; i ++) {pre[i] = i;
    }
    for (int i = 1; i<= n; i ++) {std::cin >>a[i];
    }

    while (m --) {int a,b;
        std::cin >>a >>b;
        int fa = find(a);
        int fb = find(b);
        if (fa != fb) {pre[fa] = fb;
        }
    }

    for (int i = 1; i<= n; i ++) {std::cout<< find(a[i])<< " \n"[i == n];
    }
    return 0;    
}
最后輸出是一定要再查一下祖先,否則會(huì)出現(xiàn)一些點(diǎn)的祖先沒有更新過來
K 楊神の簽到

數(shù)學(xué)題,a與a + x互質(zhì)等價(jià)于x 與 a 互質(zhì),所以暴力找與x互質(zhì)的數(shù)即可

#includeusing namespace std;

using i64 = long long;

void solve()
{int n;
    std::cin >>n;

    for (int i = 2; ; i ++) {if (__gcd(i,n) == 1) {std::cout<< i<< " "<< i + n<< "\n";
            return;
        }
    }
}

int main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int T;
    std::cin >>T;
    while (T -- ) {solve();
    }
    return 0;    
}

L jbgg想要n

將n拼起來,取模找大值,枚舉到m與p的最小值

#includeusing namespace std;

#define int long long

//a^b%p
templateT qmi(T a, int b,T p) {T res = 1 % p;
    while (b)
    {if (b & 1) res = res * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return res;
}

signed main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int n,m,p;
    std::cin >>n >>m >>p;

    int t = n,c = 0;
    while (t) {t /= 10;
        c ++;
    }
    int w = qmi(1ll * 10,c,p),res = 0;
    for (int i = 1; i<= std::min(m,p); i ++) {t = (t * w + n) % p;
        res = std::max(res,t);
    }

    std::cout<< res<< "\n";
    return 0;    
}

M yyjj 與可惡的工圖課

幾何題能不能死一死


你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購,新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧

當(dāng)前文章:??停赫憬r(nóng)林大學(xué)2022年新生杯程序設(shè)計(jì)競賽(同步賽)VP題解-創(chuàng)新互聯(lián)
文章轉(zhuǎn)載:http://muchs.cn/article42/dsiohc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、網(wǎng)站收錄企業(yè)網(wǎng)站制作、自適應(yīng)網(wǎng)站、手機(jī)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)