刚才的赛时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;
}
原来是数组开小了