Not Sitting(不坐)

Rahul and Tina are looking forward to starting their new year at college. As they enter their new classroom, they observe the seats of students are arranged in a n×m grid. The seat in row r and column c is denoted by (r, c), and the distance between two seats (a,b)and (c,d) is |a-c| + |b-d|.

As the class president, Tina has access to exactly kk buckets of pink paint. The following process occurs.

First, Tina chooses exactly k seats in the classroom to paint with pink paint. One bucket of paint can paint exactly one seat.
After Tina has painted k seats in the previous step, Rahul chooses where he sits. He will not choose a seat that has been painted pink due to his hatred of the colour pink.
After Rahul has chosen his seat, Tina chooses a seat for herself. She can choose any of the seats, painted or not, other than the one chosen by Rahul.
Rahul wants to choose a seat such that he sits as close to Tina as possible. However, Tina wants to sit as far away from Rahul as possible due to some complicated relationship history that we couldn’t fit into the statement!

Now, Rahul wonders for k=0,1,…,n⋅m−1, if Tina has k buckets of paint, how close can Rahul sit to Tina, if both Rahul and Tina are aware of each other’s intentions and they both act as strategically as possible? Please help satisfy Rahul’s curiosity!
Input
The input consists of multiple test cases. The first line contains an integer t (1≤t≤5⋅10 ^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers n, m (2≤n⋅m≤10 ^5 ) — the number of rows and columns of seats in the classroom.

The sum of n⋅m across all test cases does not exceed 10^5.

Output
For each test case, output n⋅m ordered integers — the distance between Rahul and Tina if both of them act optimally for every k∈[0,n⋅m−1].

Example
input
2
4 3
1 2
output
3 3 4 4 4 4 4 4 5 5 5 5
1 1
Note
One possible sequence of choices for the first testcase where Tina has k=3 buckets of paints is as follows.
在第一个测试用例中,Tina有k=3桶油漆,一个可能的选择序列如下。

Tina paints the seats at positions (1,2), (2,2), (3,2) with pink paint. Rahul chooses the seat at (3,1) after which Tina chooses to sit at (1,3).
Tina用粉红色油漆位置(1,2),(2,2),(3,2)的座位。Rahul选择(3,1)的位置,蒂娜选择(1,3)的位置。

Therefore, the distance between Tina and Rahul is |3?1|+|1?3|=4, and we can prove that this is indeed the minimum possible distance under the given constraints. There may be other choices of seats which lead to the same answer as well.
因此,Tina与Rahul之间的距离为|3?1|+|1?3|=4,我们可以证明这确实是给定约束条件下可能的最小距离。可能还有其他的座位选择,也会得到相同的答案。

For k=0 in the first test case, Rahul can decide to sit at (2,2) and Tina can decide to sit at (4,3) so the distance between them would be |2?4|+|2?3|=3.
对于k=0,在第一个测试样例中,Rahul可以选择坐在(2,2),Tina可以选择坐在(4,3)。所以他们之间的距离是|2 - 4|+|2 - 3|=3。

Below are pictorial representations of the k=3 and k=0 cases for the first test case .
在这里插入图片描述
A possible seating arrangement for k=3.
在这里插入图片描述
A possible seating arrangement for k=0.
翻译
拉胡尔和蒂娜期待着在大学开始新的一年。当他们进入新教室时,他们观察到学生的座位以n×m的网格排列。r行和c列中的座位用(r,c)表示,两个座位(a,b)和(c,d)之间的距离为| a-c |+| b-d |。

作为班长,蒂娜可以接触到整整kk桶的粉红色油漆。发生以下过程。

首先,蒂娜选择了教室里的k个座位,用粉红色油漆。一桶油漆正好能油漆一个座位。

蒂娜在上一步画完k座后,拉胡尔选择了他坐的地方。他不会选择漆成粉红色的座位,因为他讨厌粉红色。

拉胡尔选好座位后,蒂娜为自己选了一个座位。除了拉胡尔选的座位外,她可以选择任何一个座位,不管是否涂漆。

拉胡尔想选择一个座位,让他坐得尽可能靠近蒂娜。然而,蒂娜想坐在离拉胡尔尽可能远的地方,因为一些复杂的关系史,我们无法融入到声明中!

现在,Rahul想知道k=0,1,…,n⋅ M−1、如果蒂娜有k桶油漆,如果拉胡尔和蒂娜都知道对方的意图,并且都尽可能从战略上行动,那么拉胡尔能和蒂娜坐得多近?请帮助满足Rahul的好奇心!

思路
开始Rahul 不知道Tina的位置,所以为了在任意情况下都最近,他会选择更加靠近中间的位置,而刷油漆的位置也会优先选择靠中间的位置;
所以当Tina开始选位置时,Rahul已经坐在了能坐的位置中最靠近中间的地方,而Tina自然就会选择最远离Rahul的角落。
因为两人都是最优解,且油漆也会优先涂在靠中间的位置确保距离可以加大。所以随着k的增大,两人的距离会越来越远。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t,n,m,i,j,p,f;
int main()
{
	cin>>t;
	while(t--){
		priority_queue<int,vector<int>,greater<int> >q;
		cin>>n>>m;
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				p=max(i,n-i-1)+max(j,m-j-1);
				q.push(p);
			}
		}
		f=0;
		while(q.size()){
			f++;
			if(f!=1) cout<<" ";
			cout<<q.top();
			q.pop(); 
		}
		cout<<endl;
	}
}
由于openpose官方提供了python API接口,因此我们可以使用Python来实现基于openpose的学生上课不认真听课姿识别。 代码如下: ``` import cv2 import numpy as np import math import time import argparse # 加载OpenPose模型 net = cv2.dnn.readNetFromTensorflow("models/graph_opt.pb") # 人体关键点连接的索引 POSE_PAIRS = [ [0, 1], [1, 2], [2, 3], [3, 4], # 身体连接 [1, 5], [5, 6], [6, 7], [1, 8], [8, 9], [9, 10], # 左臂连接 [1, 11], [11, 12], [12, 13], [1, 0], [0, 14], [14, 15], # 右臂连接 [14, 16], [0, 17], [17, 18], [18, 19], [19, 20] # 身体连接 ] # 姿的关键点索引 SITTING_POINTS = [8, 9, 10, 11, 12, 13] # 计算两个关键点之间的距离 def get_distance(p1, p2): return math.sqrt((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2) # 判断学生是否姿不正确 def is_not_sitting(points): # 计算左右膝盖之间的距离 knee_distance = get_distance(points[9], points[10]) # 计算左右脚踝到左右膝盖之间的距离 left_leg_distance = get_distance(points[9], points[11]) + get_distance(points[11], points[13]) right_leg_distance = get_distance(points[10], points[12]) + get_distance(points[12], points[14]) # 计算左右脚踝到左右膝盖之间的距离与膝盖之间的距离的比值 left_leg_ratio = left_leg_distance / knee_distance right_leg_ratio = right_leg_distance / knee_distance # 如果比值小于1.5,说明姿不正确 if left_leg_ratio < 1.5 or right_leg_ratio < 1.5: return True return False # 绘制关键点和连接线 def draw_keypoints(frame, points): for i, point in enumerate(points): x, y = point cv2.circle(frame, (x, y), 3, (0, 0, 255), thickness=-1, lineType=cv2.FILLED) cv2.putText(frame, "{}".format(i), (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 1, lineType=cv2.LINE_AA) for pair in POSE_PAIRS: partA = pair[0] partB = pair[1] if points[partA] and points[partB]: cv2.line(frame, points[partA], points[partB], (0, 255, 255), 2, lineType=cv2.LINE_AA) # 识别学生姿 def detect_sitting(frame): # 转换帧为blob blob = cv2.dnn.blobFromImage(frame, 1.0 / 255, (368, 368), (0, 0, 0), swapRB=False, crop=False) # 通过网络进行前向传播 net.setInput(blob) output = net.forward() # 提取关键点标 points = [] for i in range(len(SITTING_POINTS)): prob_map = output[0, SITTING_POINTS[i], :, :] min_val, prob, min_loc, point = cv2.minMaxLoc(prob_map) x = int(frame.shape[1] * point[0] / output.shape[3]) y = int(frame.shape[0] * point[1] / output.shape[2]) if prob > 0.1: points.append((x, y)) else: points.append(None) # 绘制关键点和连接线 draw_keypoints(frame, points) # 判断学生是否姿不正确 if is_not_sitting(points): cv2.putText(frame, "Sitting position is not correct!", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, lineType=cv2.LINE_AA) # 主函数 if __name__ == "__main__": # 解析命令行参数 parser = argparse.ArgumentParser() parser.add_argument("--input", type=str, default="", help="Path to input video file. If empty, camera's stream will be used") args = parser.parse_args() # 打开视频文件或启动摄像头 cap = cv2.VideoCapture(args.input if args.input else 0) # 逐帧处理视频 while True: # 读取帧 ret, frame = cap.read() if not ret: break # 识别学生姿 detect_sitting(frame) # 显示帧 cv2.imshow("Video", frame) # 按下q键退出 if cv2.waitKey(1) & 0xFF == ord('q'): break # 释放资源 cap.release() cv2.destroyAllWindows() ``` 运行代码后,程序会识别视频中学生的姿,如果学生姿不正确,程序会在视频中显示警告信息。可以通过命令行参数指定输入的视频文件路径,如果不指定,则程序将启动摄像头并获取实时视频流。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值