Best_Cow_Line

本文深入探讨了排序算法、动态规划、哈希算法等在数据结构优化中的关键作用,通过实例展示了如何高效地处理数据,提高系统的性能。

Description

FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year" competition. In this contest every farmer arranges his cows in a line and herds them past the judges.

The contest organizers adopted a new registration scheme this year: simply register the initial letter of every cow in the order they will appear (i.e., If FJ takes Bessie, Sylvia, and Dora in that order he just registers BSD). After the registration phase ends, every group is judged in increasing lexicographic order according to the string of the initials of the cows' names.

FJ is very busy this year and has to hurry back to his farm, so he wants to be judged as early as possible. He decides to rearrange his cows, who have already lined up, before registering them.

FJ marks a location for a new line of the competing cows. He then proceeds to marshal the cows from the old line to the new one by repeatedly sending either the first or last cow in the (remainder of the) original line to the end of the new line. When he's finished, FJ takes his cows for registration in this new order.

Given the initial order of his cows, determine the least lexicographic string of initials he can make this way.

Input

* Line 1: A single integer: N
* Lines 2..N+1: Line i+1 contains a single initial ('A'..'Z') of the cow in the ith position in the original line

Output

The least lexicographic string he can make. Every line (except perhaps the last one) contains the initials of 80 cows ('A'..'Z') in the new line.

Sample Input

6
A
C
D
B
C
B

Sample Output

ABCBCD


#include "iostream"
#include "string"

using namespace std;

int N;
string S[2001];

void solve()
{
	int lo = 0;
	int hi = N - 1;
	int cnt = 0;

	while(lo <= hi)
	{
		bool leftishigh = false;
		for(int i = 0; lo + i <= hi - i; ++i)
		{
			if(S[lo + i] > S[hi - i])
			{
				leftishigh = true;
				break;
			}
			else if(S[lo + i] < S[hi - i])
			{
				leftishigh = false;
				break;
			}
		}

		if(leftishigh) cout << S[hi--];
		else cout << S[lo++];

		cnt++;

		if(cnt % 80 == 0) cout << endl;
	}

	
}



int main(int argc, char const *argv[])
{
	cin >> N;
	for(int i = 0; i < N; ++i)
	{
		cin >> S[i];
	}
	solve();
	return 0;
}
除了每行80个字符外没什么难度

(pp-ocr) dell@dell-Precision-7920-Tower:~/lbt/ppocr-cow$ conda run --live-stream --name pp-ocr python /home/dell/lbt/ppocr-cow/exchange.py /home/dell/.conda/envs/pp-ocr/lib/python3.9/site-packages/paddle/utils/cpp_extension/extension_utils.py:715: UserWarning: No ccache found. Please be aware that recompiling all source files may be required. You can download and install ccache from: https://github.com/ccache/ccache/blob/master/doc/INSTALL.md warnings.warn(warning_message) [2025/08/01 18:14:47] ppocr WARNING: Skipping import of the encryption module. �� 使用配置文件: /home/dell/lbt/ppocr-cow/configs/det/PP-OCRv5/PP-OCRv5_server_det.yml �� 使用权重文件: /home/dell/lbt/ppocr-cow/output-det/best_accuracy/best_accuracy.pdparams �� 模型将保存到: /home/dell/lbt/ppocr-cow/PP-OCRv5_server_det_infer_2 1. 加载配置文件... 2. 构建模型结构... W0801 18:14:47.337865 81452 gpu_resources.cc:114] Please NOTE: device: 0, GPU Compute Capability: 8.6, Driver API Version: 12.2, Runtime API Version: 11.7 3. 加载权重文件... ✅ 权重加载成功 4. 验证模型前向推理能力... W0801 18:14:49.002890 81452 gpu_resources.cc:243] WARNING: device: 0. The installed Paddle is compiled with CUDNN 8.9, but CUDNN version in your machine is 8.9, which may cause serious incompatible bug. Please recompile or reinstall Paddle with compatible CUDNN version. ❌ 前向推理失败: 'dict' object has no attribute 'shape' Traceback (most recent call last): File "/home/dell/lbt/ppocr-cow/exchange.py", line 102, in <module> export_inference_model(CONFIG_PATH, WEIGHT_PATH, SAVE_DIR, INPUT_SHAPE) File "/home/dell/lbt/ppocr-cow/exchange.py", line 66, in export_inference_model print("✅ 前向推理测试通过,输出形状:", output.shape) AttributeError: 'dict' object has no attribute 'shape' ERROR conda.cli.main_run:execute(47): `conda run python /home/dell/lbt/ppocr-cow/exchange.py` failed. (See above for error)运行上述代码出现错误,请给出解决方案
最新发布
08-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值