社区讨论

有大佬能帮忙看一下吗?谢谢

P1005[NOIP 2007 提高组] 矩阵取数游戏参与者 4已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@mi6lf0dj
此快照首次捕获于
2025/11/20 06:47
4 个月前
此快照最后确认于
2025/11/20 06:47
4 个月前
查看原帖
CPP
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
long long int sumn=0;
long long int totn=0;
long long int cnt=1;
int a[85][85];
bool f[85][85];
int n,m;
int main(){
    memset(f,false,sizeof(f));
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    for(int i=1;i<=m;i++){
        cnt=cnt*2;
        for(int j=1;j<=n;j++){
            int l=1,r=m;
            totn=0;
            if(f[j][l]==true){
                l++;
            }
            if(f[j][r]==true){
                r--;
            }
            if(a[j][l]==a[j][r]&&l+1<=r-1){
                if(a[j][l+1]>a[j][r-1]&&f[j][r]!=true){
                    f[j][r]=1;
                    totn+=a[j][r];
                }
                else if(a[j][l+1]<=a[j][r-1]&&f[j][l]!=true){
                    f[j][l]=1;
                    totn+=a[j][l];
                }
            }
            else if(a[j][l]>a[j][r]&&f[j][r]!=true){
                f[j][r]=1;
                totn+=a[j][r];
            }
            else if(a[j][l]<a[j][r]&&f[j][l]!=true){
                f[j][l]=1;
                totn+=a[j][l];
            }
            sumn+=totn*cnt;
        }
    }
    cout<<sumn<<endl;
    return 0;
}

回复

4 条回复,欢迎继续交流。

正在加载回复...