1. 程式人生 > 其它 >【刷題】【cf】B. Not Sitting

【刷題】【cf】B. Not Sitting

由題面可以推出,Tina一定坐在教室四個角,而Rahul一定坐在可選擇的最中間的位置,

原本打算按照規律,算出從k=0到k=n*m-1中,每一圈的座位數

後來發現n*m<= 1e5,直接每個座位計算,與四個角最大的距離就好

在確定方法前,一定要再看一眼資料範圍啊

#include<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#include
<iostream> #define ll long long using namespace std; inline int read() { int x=0,f=1;char c=getchar(); while(c<'0' || c>'9' ) { if(c=='-' ) f=-1; c=getchar(); } while(c>='0'&&c<='9' ) x=(x<<3)+(x<<1)+c-'0',c=getchar(); return
x*f; } int t,n,m,k; const int N=60; bool mp[N][N]; int a[100010]; int main() { t=read(); while(t--) { n=read(),m=read(); int tot=0; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[tot++]=max(i-1,n-i)+max(j-1,m-j); sort(a,a
+tot); for(int i=0;i<=n*m-1;i++) cout<<a[i]<<" "; cout<<endl; } return 0; }
View Code