1. 程式人生 > 其它 >2021 CCPC女生賽

2021 CCPC女生賽

newbie,A了五題銅牌收工
比賽時和隊友悠哉遊哉做題,想著乾飯,最後幸好沒滾出銅尾。
貼一下比賽過的程式碼

A題 簽到

隊友A的,判斷正反方向序列是否符合要求

/*** 
 * @Author: _Krill
 * @Date: 2021-10-31 09:00:34
 * @LastEditTime: 2021-10-31 09:54:36
 */
#include<bits/stdc++.h>
using namespace std;
#define IO_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int station[10];
int bussta[10];
int n,x,y,m;
int func(){

    bool flag1=true;
    bool flag2=true;
    for(int i=x+1,j=1;i<=x+m;i++,j++){
        if(bussta[j]!=station[i]){
            flag1=false;
            break;
        }
    }
    for(int i=x-1,j=1;i>=x-m;i--,j++){
        if(bussta[j]!=station[i]){
            flag2=false;
            break;
        }
    }
    if(flag1&&flag2){
        return 0;
    }
    else if(flag1&&!flag2)
        return 1;
    else
        return -1;
}
int main()
{
    // IO_fast
    cin>>n>>x>>y;
    for(int i=1;i<=n;i++){
        cin>>station[i];
    }
    cin>>m;
    if(m>abs(x-y)){
        cout<<"Wrong"<<endl;
        return 0;
    }
    for (int i = 1; i <= m; i++)
    {
        cin>>bussta[i];
    }
    int fu=func();
    if(fu==0)
        cout<<"Unsure"<<endl;
    else if(fu==1){
        if(x>y)
            cout<<"Wrong"<<endl;
        else
            cout<<"Right"<<endl;
    }
    else{
        if(x>y)
            cout<<"Right"<<endl;
        else{
            cout<<"Wrong"<<endl;
        }
    }
    return 0;
}

D題

剛看以為是最小生成樹,實際上毫無關係。
把所有村莊按費用從大到小排序,依次檢查是不是邊界,是邊界就加兩次,否則加一次。

/*** 
 * @Author: _Krill
 * @Date: 2021-10-31 09:13:24
 * @LastEditTime: 2021-10-31 09:54:45
 */
#include<bits/stdc++.h>
using namespace std;
#define IO_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
struct node {
    int num, e;
};
node arr[200005];
bool cmp(const node& a, const node& b) {
    return a.num > b.num;
}
int vis[200005];
int main()
{
    IO_fast
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> arr[i].num;
        arr[i].e = i + 1;
    }
    ll sum = 0;
    int cnt = 0;
    sort(arr, arr + n, cmp);
    for(int i = 0; i < n && cnt < n; i++ ) {
        vis[arr[i].e] = 1;
        if(arr[i].e - 1 >= 1) {
            if(!vis[arr[i].e - 1]) {
                sum += arr[i].num;
                cnt++;
            }
        }
        if(arr[i].e + 1 <= n) {
            if(!vis[arr[i].e + 1]) {
                sum += arr[i].num;
                cnt++;
            }
        }
    }
    cout << sum << '\n';
    return 0;
}

G題 簽到

隊友A的,求 1 / n

/*** 
 * @Author: _Krill
 * @Date: 2021-10-31 10:08:07
 * @LastEditTime: 2021-10-31 10:17:15
 */
#include<bits/stdc++.h>
using namespace std;
#define IO_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
int main()
{
    int n;
    cin>>n;
   for(int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
    }
    double ans;
    ans=1.0/n;
    printf("%16f",ans)
}

I題 模擬題

debug了好久,恰好飯點,也就飯後甜點解決了~
開始隊友提供思路左轉右轉45度就是三角函式的變化,but腦子短路,也沒寫對。
最後是用dx,dy方向陣列,+1表示右轉,-1表示左轉,開始是向前的,狀態為 (-1, 0)。

/*** 
 * @Author: _Krill
 * @Date: 2021-10-31 10:05:05
 * @LastEditTime: 2021-10-31 12:48:36
 */
#include<bits/stdc++.h>
using namespace std;
#define IO_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
typedef pair<int, int> pp;
int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
int n, m;
char arr[55][55];
int curV = 0;
int dire = 0;

bool judge(int xx, int yy) {
    if(dx[dire] != 0 && dy[dire] != 0) {
        int t1 = (dire - 1 + 8) % 8, t2 = (dire + 1) % 8; 
        if(arr[xx + dx[t1]][yy + dy[t1]] == '#' && arr[xx + dx[t2]][yy + dy[t2]] == '#') return false;
    }
    return true;
}

pp move(pp st) {
    int xx = st.first, yy = st.second;
    for(int i = 0; i < curV; i++) {
        xx += dx[dire], yy += dy[dire];
        if(xx <= 0 || xx > n || yy <= 0 || yy > m || arr[xx][yy] == '#' || !judge(st.first, st.second)) {
            cout << "Crash! ";
            curV = 0;
            return st;
        }
        st = pp(xx, yy);
    }
    return st;
}
int main()
{
    int q;
    pp st;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> arr[i][j];
            if(arr[i][j] == '*') {
                st = pp(i, j);
                arr[i][j] = '.';
            }
        }
    }
    string op;
    cin >> q >> op;
    for(int i = 0; i < q; i++) {
        if(op[i] == 'L') {
            dire = (dire - 1 + 8) % 8;
        }
        else if(op[i] == 'R') {
            dire = (dire + 1) % 8;
        }
        else if(op[i] == 'U') {
            curV += 1;
        }
        else {
            curV = max(curV - 1, 0);
        }
        st = move(st);
        cout << st.first << ' ' << st.second << '\n';
    }
    return 0;
}

K題 統計 '-' 的個數,簽到。

/***
 * @Author: _Krill
 * @Date: 2021-10-31 09:02:15
 * @LastEditTime: 2021-10-31 18:06:19
 */
#include<bits/stdc++.h>
using namespace std;
#define IO_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int main()
{
    IO_fast
    int n;
    cin >> n;
    int cnt = 0;
    char ch;
    while(cin >> ch) {
        if(ch == '-') cnt++;
    }
    cout << cnt << '\n';
    return 0;
}

之後還開了 B 題和 C 題,B 題題目意思真難懂,猜了一下沒通過樣例,時間還剩半個小時,隊友建議轉向 C 題。C 題資料範圍很小,想了下用 DFS 回溯,剛寫的時候毒奶自己每次寫回溯都會有 bug,果不其然,到最後兩分鐘,樣例還是沒過,隨終。
隊裡都沒時間準備,所以拿到銅還是挺滿意的,如果做題時沒那麼悠哉閒聊,感覺還是可以把 C 調出來
補題了

本文來自部落格園,作者:_krill,轉載請註明原文連結:https://www.cnblogs.com/krill/p/15490348.html