CF1393C Pinkie Pie Eats Patty-cakes

题目传送门

歪解:

看到题目中的最小的最大,很容易想到二分,并且发现其满足单调性。时间复杂度 O ( n log ⁡ n ) O(n\log n) O(nlogn),可以通过。

正解:

数学题,我们想到循环着摆放相同的数字是最优的。将所有出现次数最多的数字合在一起,作为循环节,然后在每两个循环节之间插入出现次数非最多的数字,其实就是插空。

假设出现次数最多的数字有 k k k 个,出现了 c n t cnt cnt 次,那么答案就是 ⌊ n − c n t × k k − 1 ⌋ + c n t + 1 \lfloor\dfrac{n - cnt\times k}{k - 1}\rfloor+cnt+1 k1ncnt×k+cnt+1。时间复杂度 O ( n ) O(n) O(n),也是可以通过的。

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

using namespace std;
const int maxn = 1e6 + 10;

int n, mx, cnt;
int c[maxn];

void solve() 
{
	cin >> n;
	for (int i = 0; i <= n; ++i) c[i] = mx = cnt = 0;;
	for (int i = 1, x; i <= n; ++i) cin >> x, c[x]++, mx = max(mx, c[x]);
	for (int i = 1; i <= n; ++i) cnt += (c[i] == mx);
	cout << cnt - 1 + (n - cnt * mx) / (mx - 1) << '\n';
}

signed main() 
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int t;
	cin >> t;
	while (t--)
		solve();
}
  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是利用MediaPipe进行手掌关键点预测时,根据手腕、食指根部和小指根部的坐标确定左右手的Python代码: ```python import cv2 import mediapipe as mp mp_drawing = mp.solutions.drawing_utils mp_hands = mp.solutions.hands # 初始化MediaPipe Hands hands = mp_hands.Hands( static_image_mode=True, max_num_hands=1, min_detection_confidence=0.5) # 读取图片 image = cv2.imread('hand.jpg') image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # 处理图片,获取手掌关键点 results = hands.process(image) if not results.multi_hand_landmarks: print('No hands found.') exit() # 获取手掌关键点的坐标 landmarks = results.multi_hand_landmarks[0] landmark_coords = [] for landmark in landmarks.landmark: x = landmark.x * image.shape[1] y = landmark.y * image.shape[0] landmark_coords.append((x, y)) # 判断左右手 wrist = landmark_coords[0] index_finger_base = landmark_coords[5] pinkie_finger_base = landmark_coords[17] if wrist[0] < index_finger_base[0] and wrist[0] < pinkie_finger_base[0]: print('Left hand') else: print('Right hand') # 可视化结果 image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) mp_drawing.draw_landmarks( image, landmarks, mp_hands.HAND_CONNECTIONS) cv2.imshow('MediaPipe Hands', image) cv2.waitKey(0) # 释放资源 hands.close() cv2.destroyAllWindows() ``` 这段代码首先初始化了MediaPipe Hands,并读取了一张手掌图片。然后,它处理图片,获取手掌关键点的坐标。接着,它根据手腕、食指根部和小指根部的坐标判断左右手,并输出结果。最后,它可视化了结果,将手掌关键点和连接线绘制在图片上,并显示图片。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值