POJ3617_Best Cow Line

别再为RK3588 NPU环境头疼了!手把手教你用Conda搞定rknn-toolkit2安装(附国内源加速) 本文详细介绍了如何通过Conda虚拟环境高效配置RK3588 NPU开发环境,解决rknn-toolkit2安装中的常见问题。从Python版本选择到国内镜像源加速,再到模型转换与部署优化,手把手教你避开环境配置的坑,快速搭建稳定的NPU开发环境。 阅读详情
Best Cow Line
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 20402 Accepted: 5599

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

Source


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

char ch[2100] = { 0 }, ans[2100] = { 0 };

void main()
{
	int n, i, up, down, p, x, y,t;
	while (scanf("%d", &n) != EOF)
	{
		getchar();
		for (i = 0;i < n;i++)
		{
			scanf("%c", &ch[i]);
			getchar();
		}
		up = n - 1;
		down = 0;
		p = 0;
		while (up > down)
		{
			if (ch[up] > ch[down])
				ans[p++] = ch[down++];
			else
			{
				if (ch[up] < ch[down])
					ans[p++] = ch[up--];
				else
				{
					x =down+ 1;
					y = up- 1;
					while (x < y && ch[x] == ch[y])
					{
						x++;y--;
					}
					if (ch[x] < ch[y])
						ans[p++] = ch[down++];
					else
						ans[p++] = ch[up--];
				}
			}
		}
		ans[n - 1] = ch[down];
		t = 0;
		for (i = 0; i < n; i++)
		{
			printf("%c", ans[i]);
			t++;
			if (t % 80 == 0 && i < n - 1)
				printf("\n");
		}
	}
}


【题解】POJ 3617 Best Cow Line(贪心) POJ 3617 Best Cow Line 原题 https://vjudge.net/problem/POJ-3617 FJ准备带他的N(1≤N≤2000)头奶牛参加一年一度的“年度农民”比赛。在这场比赛中,每个农民把他的奶牛排成一排,并把它们赶过裁判。 比赛的组织者今年采用了一种新的登记方案:只要按照每头奶牛出现的顺序登记它们的首字母即可。,如果FJ按此顺序接收贝西、西尔维娅和朵拉,他... 阅读详情

相关推荐

【SABRE 3D, SABRE 3DxT,LAM设备】2025年9月10日

前文:SABRE 3D系列机台简介本章节详细阐述了在维护期间锁定电气、机械、热力学及重力组件以及化学管线输入的锁定操作流程,旨在降低人员受伤风险。p42~p55。

weixin_46735260的博客 1619

POJ3617 Best Cow Line Greedy

给你一个字符串,每次两种操作将字符串重组,字典序最小。 将第一个字符加在新字符串尾部 将最后一个字符加在新串尾部 从前从后比较两个字符串字典序,选择小的第一个字符添加到新串尾部,反复如此。相同时随便选一个。不能够简单比较第一个字符。 Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K

1412

新手必看!用FFmpeg一键合并ts文件的5种方法(含Windows/Mac终端命令)

本文详细介绍了使用FFmpeg合并TS视频文件的5种实用方法,涵盖Windows和Mac终端命令操作。从基础安装到进阶技巧,包括处理音频不同步、批量处理多个视频等场景,帮助用户轻松将m3u8分片视频合并为完整mp4文件,提升视频处理效率。

weixin_29065959的博客 564

RKNN-Toolkit2 v2.3.2安装

介绍了在Docker环境下安装rknn-toolkit2 v2.3.2的步骤:首先下载并解压工具包,使用Dockerfile构建Ubuntu 20.04镜像;然后安装Python 3.8、编译工具和PyTorch 1.10.1;最后安装rknn_toolkit2核心包并启动容器。成功启动后即可进入RKNN官方编译环境进行开发。整个过程包括镜像构建、依赖安装和容器运行三个主要阶段。

anandzw的博客 453

sysbench测试系统内存

系统内存读写测试方法,报告解读

m0_61066945的博客 3019

MWORKS赋能蓝桥杯智能装备数字化建模大赛:技术解析与实战指南

本文深入解析了如何利用MWORKS平台参加蓝桥杯智能装备数字化建模大赛。文章从认识MWORKS这一多领域统一建模仿真平台入手,详细阐述了构建包含控制算法与数字样机的动态系统模型的核心方法,并提供了从软件入门、分层建模到作品打磨的完整实战指南,助力参赛者掌握智能装备数字化设计的关键技能。

weixin_29279101的博客 383

POJ3617--Best Cow Line(贪心水题)

POJ3617–Best Cow Line(贪心水题) 原题链接: POJ3617. 题目简述 给定长度为N的字符串S,要构造一个长度为N的字符串T。起初,T是一个空串,随后反复进行如下任意操作。 从S的头部删除一个字符,加到T的尾部 从S的尾部删除一个字符,加到T的尾部 标准输入: 第1行:单个整数:N 第2行:输入长度为N的字符串。 标准输出: 输出最小的字典串,每行80个。 示例输入: 6 A C D B C B 示例输出: ABCBCD 贪心思路: 目的是要构造字典序尽量小的字符串T 从

m0_51155633的博客 579

ENVI5.6+SARscape实战:基于哨兵一号的PS与SBAS时序InSAR地表形变监测全流程解析

本文详细解析了使用ENVI5.6和SARscape软件基于哨兵一号数据进行PS与SBAS时序InSAR地表形变监测的全流程。从数据获取、预处理到PS-InSAR和SBAS-InSAR处理,提供了实用技巧和优化建议,帮助用户高效完成地表形变监测任务。

weixin_29245767的博客 1157

POJ 3617-字典序列

一、Java: import java.util.Scanner; public class Main{ //采用的是翻转字符串进行比较的方法,所以来说这个方法更加简单地比较字符串 public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); StringBuilder ss = new String

ଳxin的博客 338

Anthropic API接入指南:连接失败、403鉴权与Claude Code集成排查

在AI应用开发中,API接入与鉴权机制是开发者绕不开的基础工程问题。无论是调用云端模型服务还是自建网关,网络连通性、HTTP状态码语义、模型路由映射都会直接影响服务可用性。本文从通用的网络诊断与鉴权原理出发,梳理了从TCP连接失败到403权限拒绝的典型链路,并深入解析网关模型路由匹配机制。在此基础上,进一步说明如何通过环境变量完成Claude Code与VS Code的本地集成,以及一套基于Python的可复现接入方案。内容涵盖Anthropic API高频报错定位、curl冒烟测试、SDK工程化实践,适合

weixin_28743405的博客 470

使用 Tesseract 在 C# 中进行光学字符识别(OCR)

你可以根据需要对 Tesseract 进行自定义配置,例如设置识别的分辨率、识别模式等。// 只识别数字// 设置自定义变量本文只讲述了简单的使用方法,未涉及字库训练,识别的准确率与训练的字库有关。

仰望星空的博客 4735

【POJ 3617 --- Best Cow Line】

【POJ 2376 --- Cleaning Shifts】 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 he...

来日浅谈的博客 471

fanuc机器人KAREL程序间参数的传递

之前的课程中讲述过KAREL程序中函数参数的传递,而控制工业机器人的动作只能通过控制TP程序来实现,所以在实际应用中就会出现在不同程序间进行参数的传递。尤其是对于有模块化编程的思想的设计者,更有这种迫切的要求。所以本次课程来讲解一下如何实现在不同程序之间进行参数的传递。 本次课程分为两个部分,以讲解在不同类型程序间进行参数传递的实现方式。 1、TP程序之间传递参数; 2、TP与PC程序之间传递参数。

haier123888的博客 2697

POJ 3617 Best Cow Line 贪心算法

题目链接:Best Cow Line 贪心策略是:一直从S字串两侧寻找小的字符,特殊情况是:如果两侧字符一样,向内侧比较并获取答案。(不过感觉这步做了很多无用功,尤其是回文串的情况) 代码如下: View on Github #include #include #include #include using namespace std; vector S; bool operat

Kiritow的学园 565

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

POJ3617 Best Cow Line

题目链接:POJ3617 Best Cow Line Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 46695 Accepted: 11881 Description FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Yea...

cutlery1137的博客 264

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

POJ3617 Best Cow Line【水题】

Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27635   Accepted: 7438 Description FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the an

海岛Blog 1970

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

POJ 3617——Best Cow Line

链接:http://poj.org/problem?id=3617 题解 #include<iostream> using namespace std; const int MAX_N=2e3+50; int N; //输入字符串的字符个数 int count; //记录字符个数,满足换行要求 char S[MAX_N]; //存放字符串的数组...

SmallProgramer3121的博客 263

poj 3617 Best Cow Line 贪心

poj 3617 Best Cow Line 题目链接: http://poj.org/problem?id=3617 思路: 贪心 第一个字母和最后一个字母比较字典序,果如大小相同,左边指针++,右边指针--,继续比较 最后注意输出格式:每80个字母换一次行 代码: #include <iostream> #include <stdio.h> using n...

ddqb3235的博客 263

【贪心】POJ 3617:Best Cow Line

一、题目内容 POJ 3617 原题地址 二、题意解释 给定一个字符串,重排,每次从头或尾取较小值放到新序列的末尾。 题目要求是每80个为一行输出。 三、代码及注释 #include<cstdio> using namespace std; int n; char S[2001]; int main() { scanf("%d",&n); for(int j=0; j<n; j++) { scanf(" %c",&S[j]);

szy_fasheng的博客 1040

Best Cow Line(POJ 3617)

原题链接:http://poj.org/problem?id=3617 字典序最小问题(贪心算法) 基本思想:不断取S的开头和末尾中较小的一个字符放到T的末尾 难点:开头和末尾的字符相同的情形如何解决 修正算法:按照字典序比较S和S反转后的字符串S’ #include &lt;iostream&gt; #include&lt;cstdio&gt; using namespace std...

种花家的奋斗兔的博客 749

POJ——3617 Best Cow Line

题目链接:http://poj.org/problem?id=3617 题目大意: FJ要参加“年度农场主”这个比赛,每个农场主要把他们的牛排成一条直线,将每头牛名称的首字母合成作为注册名,例如,FJ带了Bessie, Sylvia, 和Dora三头牛,则注册名就叫做BSD。注册名字典序靠...

chiweiluo5790的博客 195

Best Cow Line(POJ - 3617)

Best Cow Line POJ - 3617 FJ is about to take hisN(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 blog of Lee 331

Best Cow Line(POJ 3617) 贪心

来自《挑战程序设计竞赛》 1.题目原文 http://poj.org/problem?id=3617 Best Cow Line Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19765   Accepted: 5457 Description

相思作坊半世离殇的博客 476

POJ 3617 Best Cow Line

Best Cow Line Time Limit: 1000MS Memory Limit: 65536K 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 h...

忘梦心的博客 238

POJ 3617 Best Cow Line

Language:Default Best Cow Line Time Limit:1000MS Memory Limit:65536K Total Submissions:37317 Accepted:9665 Description FJ is about to take his...

Y_AOZHEN的博客 281
上一篇: CodeForces515C_Drazil and Factorial
下一篇: POJ1503_Integer Inquiry
ZayneHuang
博客等级 码龄10年 5粉丝 116原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值