张友帆8月26日总结

· · 个人记录

一、比赛基本情况

比赛日期:8月26日 比赛时长:1:30 比赛得分:147 比赛排名:1

二、比赛整体回顾

简要记录本场比赛的做题顺序、时间安排、比赛状态以及整体感受。

三、题目复盘

T1:座位

本题得分:30分 开始时间:2:00 结束时间:2:20 总用时:20分

初始思路

记录看到题目后的第一反应、观察到的性质,以及最初准备采用的解法。 用数组模拟。

考场解题过程

记录考场上思路的发展、调整和最终采用的做法。 从1到n枚举列,在里面判断是奇数行还是偶数行,奇数从小到大,偶数从大到小,如果碰到数等于小R的分数就输出列和行。

考场代码

// 在此粘贴考场代码

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1e6 + 5;

int n, m, a[1005][1005], b[MAXN];

int cmp(int x, int y){
    return x > y;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("seat.in", "r", stdin);
    //freopen("seat.out", "w", stdout);
    cin >> n >> m;
    cin >> b[1];
    int chengji = b[1];
    for(int i = 2; i <= n * m; i ++){
        cin >> b[i];
    }
    sort(b + 1, b + n * m + 1, cmp);
    int cnt = 0;
    for(int i = n; i >= 1; i --){
        if(i % 2 == 1){
            for(int j = 1; j <= m; j ++){
                cnt ++;
                a[i][j] = b[cnt];
                if(b[cnt] == chengji){
                    cout << j << " " << i;
                    return 0;
                }
            }
        }
        else{
            for(int j = m; j >= 1; j --){
                cnt ++;
                a[i][j] = b[cnt];
                if(b[cnt] == chengji){
                    cout << j << " " << i;
                    return 0;
                }
            }
        }
    }
    return 0;
}

赛后题解

用自己的语言整理本题的正确思路、关键结论和算法流程。 可以把自己的排名求出来,初始先把排名设成1,然后从2枚举到n*m,如果a[i]<a[1]排名++,然后列就是(排名 - 1) / n + 1接着看列如果是奇数那就判断如果排名%n==0,那行就是n,否则就输出排名%n;如果是偶数那就还是判断排名%n如果==0,那就输出1,否则就输出n-(排名%n)+1。

补题代码

// 在此粘贴考场代码

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1000005;
int n, m, a[MAXN]; 
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    cin >> n >> m;
    for(int i = 1; i <= n * m; i ++){
        cin >> a[i];
    }
    int paiming = 1;
    for(int i = 2; i <= n * m; i ++){
        if(a[i] > a[1]){
            paiming ++;
        }
    }
    int lie = (paiming - 1) / n + 1;
    cout << lie << " ";
    if(lie % 2 == 1){
        if(paiming % n == 0){
            cout << n;
        }
        else{
            cout << paiming % n;
        }
    }
    else{
        if(paiming % n == 0){
            cout << 1;
        }
        else{
            cout << n - (paiming % n) + 1;
        }
    }
    return 0;
}

复杂度

时间复杂度:n*m 空间复杂度: 本题总结 记录本题出现的问题、值得保留的做法以及赛后的主要收获。

T2:异或和

本题得分:5分 开始时间:2:11 结束时间:2:31 总用时:20分

初始思路

用前缀和。

考场解题过程

考场代码

// 在此粘贴考场代码

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1e6 + 5;

int n, k, a[MAXN], pre[MAXN];

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("xor.in", "r", stdin);
    //freopen("xor.out", "w", stdout);
    cin >> n >> k;
    int cnt = 0;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
        cnt ^= a[i];
        pre[i] = cnt;
    }
    int ans = 0;
    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= n; j ++){
            if(abs(pre[j] - pre[i - 1]) == k){
                ans ++; 
            }
        }
    }
    cout << ans;
    return 0;
}

赛后题解

可以用一个vis数组来记录前缀和的位置,开始先做一遍前缀和,vis记得初始化为-1,然后vis[0] = 1,然后枚举后面的下标1到n如果vis[pre[zhong] ^ k] > shang的话ans ++,并把shang设为zhong最后在把vis[pre[zhong]] 设成zhong + 1,最后输出ans。

补题代码

// 在此粘贴考场代码

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 2e6 + 5;
int n, k, a[MAXN], pre[MAXN], vis[MAXN], ans = 0;
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    cin >> n >> k;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
        pre[i] = pre[i - 1] ^ a[i];
    }
    int shang = 0;
    memset(vis, -1, sizeof(vis));
    vis[0] = 1;
    for(int zhong = 1; zhong <= n; zhong ++){
        if(vis[pre[zhong] ^ k] > shang){
            ans ++;
            shang = zhong;
        }
        vis[pre[zhong]] = zhong + 1;
    }
    cout << ans;
    return 0;
}

复杂度

时间复杂度:on 空间复杂度: 本题总结

T3:多边形

本题得分:12分 开始时间:2:35 结束时间:3:30 总用时:55分

初始思路

用dfs()。

考场解题过程

用dfs(),来一个选和不选。

考场代码

// 在此粘贴考场代码

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1e6 + 5;

int n, a[MAXN], ans[MAXN], total = 0, maxi = -1e9, cnt = 0, sum = 0;

void dfs(int x){
    if(sum >= 3 && a[ans[x - 1]] * 2 < cnt){
        total ++;
    }
    if(x > n){
        return ;
    }
    for(int i = ans[x - 1] + 1; i <= n; i ++){
        ans[x] = i;
        sum ++;
        cnt += a[i];
        dfs(x + 1);
        cnt -= a[i];
        ans[x] = 0;
        sum --;
        dfs(x + 1);
    }
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("polygon.in", "r", stdin);
    //freopen("polygon.out", "w", stdout);
    cin >> n;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    dfs(1);
    cout << total % 998244353;
    return 0;
}

赛后题解

可以从大到小排个序,用ans和sum来记录,定义dp[0] = 1,然后就枚举1到n将a[i]作为最长的,因为题目的范围是5000所以枚举从a[i]+1到5001,把ans+=dp[j]然后ans%=mod,再把所有值都加到5001上记得要%=mod,最后就从大到小枚举5000到a[i],dp[j]+=dp[j - a[i]],dp[j] %=mod,输出ans。

补题代码

// 在此粘贴考场代码

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 3e6 + 5;
const int mod = 998244353;
int n, a[MAXN], dp[MAXN];

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    cin >> n;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    int sum = 0, ans = 0;
    dp[0] = 1;
    for(int i = 1; i <= n; i ++){
        for(int j = a[i] + 1; j <= 5001; j ++){
            ans += dp[j];
            ans %= mod;
        }
        for(int j = 5001; j >= 5001 - a[i]; j --){
            dp[5001] += dp[j];
            dp[5001] %= mod;
        }
        for(int j = 5000; j >= a[i]; j --){
            dp[j] += dp[j - a[i]]; 
            dp[j] %= mod;
        } 
    }
    cout << ans;
    return 0;
}

复杂度

时间复杂度:n 50005000 空间复杂度:

本题总结

T4:____

本题得分: 开始时间: 结束时间: 总用时:

初始思路

考场解题过程

考场代码

// 在此粘贴考场代码

赛后题解

补题代码

// 在此粘贴考场代码

复杂度

时间复杂度:

本题总结

四、整体反思

做得较好的地方:想到了点子上。

需要改进的地方:要多想想办法。

时间安排总结: