0
已解决
吕梓瑜
初级天翼
初级天翼
各位大佬,请问5548咋做?有个错误代码,感觉思路完全偏离路线
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
using namespace std;
int a[1005][1005];
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int n,m,k;
cin>>n>>m>>k;
int t=1,ht=1,hw=m,lt=1,lw=n;
while(t<=m*n){
for(int i=ht;i<=hw;i++) a[i][lw]=t++;
lw--;
for(int j=lw;j>=lt;j--) a[hw][j]=t++;
hw--;
for(int i=hw;i>=ht;i--) a[i][lt]=t++;
lt++;
for(int j=lt;j<=lw;j++) a[ht][j]=t++;
ht++;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]==k){
cout<<i+1<<" "<<j+1;
break;
}
}
}
//fclose(stdin);
//fclose(stdout);
return 0;
}
给个伪代码加思路像这样:
(别水,一旦发现,直接举报)
1
已采纳
李显晨
中级启示者
中级启示者
这题不是这么写的
核心代码:
int lt=1,lw=n,h=1;
while(cnt<=n*m){
for(int i=lt;i<=lw;i++) a[i][h]=++cnt;
h++;
for(int i=lw;i>=lt;i--) a[i][h]=++cnt;
h++;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]==s){
cout<<i<<" "<<j;
break;
}
}
}
0