666 RE是如此重要
  • 板块灌水区
  • 楼主fluhang_
  • 当前回复1
  • 已保存回复1
  • 发布时间2025/1/17 21:06
  • 上次更新2025/1/18 10:02:25
查看原帖
666 RE是如此重要
1072112
fluhang_楼主2025/1/17 21:06

刚才的赛时H题没过,百思不得其解,然后没想通,直到我把 85分

#include<bits/stdc++.h>
#define int long long
#define fast register int

using namespace std;

const int N=1e3+100;

int n,m,k,a[N][N],cnt[N],b[N];

bool qwq[N];

bool cmp(int a,int b){
	return a>b;
}

signed main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	cin>>n>>m>>k;
	
	for (fast i=1;i<=n;i++) {
		for (fast j=1;j<=m;j++) {
			cin>>a[i][j];
		}
	}
	
	for (fast q=1;q<=k;q++){
		memset(b,0,sizeof b);
		memset(qwq,false,sizeof qwq);
		memset(cnt,0,sizeof cnt);
		for (fast i=1;i<=n;i++) {
			for (fast j=1;j<=m;j++) {
				cnt[j]+=a[i][j];
			}
		}
		int ansmin=0x7f7f7f7f7f7f7f7f,ansmax=-0x7f7f7f7f7f7f7f7f;
		for (fast i=1;i<=m;i++){
			ansmin=min(cnt[i],ansmin);
			ansmax=max(cnt[i],ansmax);
		}
		int x=0;
		for (fast i=1;i<=m;i++){
			if (cnt[i]==ansmin||cnt[i]==ansmax){
				for (fast j=1;j<=n;j++){
					x++;
					b[x]=a[j][i];
				}
				qwq[i]=true;
			}
		}
		sort(b+1,b+x+1,cmp);
		int z=0;
		for (fast i=1;i<=n;i++){
			if (i%2==0){
				for (fast j=m;j>=1;j--){
					if (qwq[j]==true){
						z++;
						a[i][j]=b[z];
					}
				}
			}
			else{
				for (fast j=1;j<=m;j++){
					if (qwq[j]==true){
						z++;
						a[i][j]=b[z];
					}
				}
			}
		}
	}
	
	for (fast i=1;i<=n;i++){
		for (fast j=1;j<=m;j++){
			cout<<a[i][j]<<" ";
		}
		cout<<"\n";
	}

	return 0;
}

改了一个数字 100

#include<bits/stdc++.h>
#define int long long
#define fast register int

using namespace std;

const int N=3e3+100;

int n,m,k,a[N][N],cnt[N],b[N];

bool qwq[N];

bool cmp(int a,int b){
	return a>b;
}

signed main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	cin>>n>>m>>k;
	
	for (fast i=1;i<=n;i++) {
		for (fast j=1;j<=m;j++) {
			cin>>a[i][j];
		}
	}
	
	for (fast q=1;q<=k;q++){
		memset(b,0,sizeof b);
		memset(qwq,false,sizeof qwq);
		memset(cnt,0,sizeof cnt);
		for (fast i=1;i<=n;i++) {
			for (fast j=1;j<=m;j++) {
				cnt[j]+=a[i][j];
			}
		}
		int ansmin=0x7f7f7f7f7f7f7f7f,ansmax=-0x7f7f7f7f7f7f7f7f;
		for (fast i=1;i<=m;i++){
			ansmin=min(cnt[i],ansmin);
			ansmax=max(cnt[i],ansmax);
		}
		int x=0;
		for (fast i=1;i<=m;i++){
			if (cnt[i]==ansmin||cnt[i]==ansmax){
				for (fast j=1;j<=n;j++){
					x++;
					b[x]=a[j][i];
				}
				qwq[i]=true;
			}
		}
		sort(b+1,b+x+1,cmp);
		int z=0;
		for (fast i=1;i<=n;i++){
			if (i%2==0){
				for (fast j=m;j>=1;j--){
					if (qwq[j]==true){
						z++;
						a[i][j]=b[z];
					}
				}
			}
			else{
				for (fast j=1;j<=m;j++){
					if (qwq[j]==true){
						z++;
						a[i][j]=b[z];
					}
				}
			}
		}
	}
	
	for (fast i=1;i<=n;i++){
		for (fast j=1;j<=m;j++){
			cout<<a[i][j]<<" ";
		}
		cout<<"\n";
	}

	return 0;
}

原来是数组开小了

2025/1/17 21:06
加载中...