Chef Sereja and Sorting 2

我的想法是:先排序,从开头到结尾不断找到对应位置的值,交换[l,r]。那么l位置就是已经排好序的了。只有0.67分

优化了下find() 0.725


#include<cstdio>
#include<algorithm>
using namespace std;
const int N=10002;
int n,a[N],b[N],left[N],right[N];

int find(int b,int val){
	if(a[b]==val) return b;
	for(int i=n;i>b;i--)
		if(a[i]==val)
			return i;
}
void swap(int l,int r){
	while(l<r){
		int t=a[l];
		a[l]=a[r];
		a[r]=t;
		l++,r--;
	}
}
int main(){
	while(~scanf("%d",&n)){
		for(int i=1;i<=n;i++){
			scanf("%d",a+i);
			b[i]=a[i];
		}
		sort(b+1,b+n+1);
		int cnt=0,l=1,r=1;
		for(int i=1;i<=n;i++){
			r=find(l,b[i]);
			if(r>l){
				left[cnt]=l;
				right[cnt]=r;
				swap(l,r);
				cnt++;
			}
			l++;
		}
		printf("%d\n",cnt);
		for(int i=0;i<cnt;i++)
			printf("%d %d\n",left[i],right[i]);
	}
	return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Chef: Powerful Infrastructure Automation by John Ewart English | 16 May 2017 | ASIN: B0716YXM1N | 726 Pages | AZW3 | 5.09 MB Learn Chef Provisioning like a boss and discover how to deploy software and manage hosts, along with engaging recipes to automate your cloud and server infrastructure with Chef. About This Book Leverage the power of Chef to transform your infrastructure into code to deploy new features in minutes Get step-by-step instructions to configure, deploy, and scale your applications Master specific Chef techniques to run an entire fleet of machines without breaking a sweat. Who This Book Is For If you are a system administrator, Linux administrator, a cloud developer, or someone who just wants to learn and apply Chef automation to your existing or new infrastructure, then this learning path will show you all you need to know. In order to get the most out of this learning path, some experience of programming or scripting languages would be useful. What You Will Learn Install Chef server on your own hosts Integrate Chef with cloud services Debug your cookbooks and Chef runs using the numerous inspection and logging facilities of Chef Extend Chef to meet your advanced needs by creating custom plugins for Knife and Ohai Create a perfect model system Use the best test-driven development methodologies In Detail Chef is a configuration management tool that turns IT infrastructure into code. Chef provides tools to manage systems at scale. This learning path takes you on a comprehensive tour of Chef's functionality, ranging from its core features to advanced development. You will be brought up to speed with what's new in Chef and how to set up your own Chef infrastructure for individuals, or small or large teams. You will learn to use the basic Chef command-line tools. We will also take you through the core concepts of managing users, applications, and your entire cloud infrastructure. You will learn the techniques of the pros by walking you through a host of step-by-step guides to solve real-world infrastructure automation challenges.You will learn to automate and document every aspect of your network, from the hardware to software, middleware, and all your containers. You will become familiar with the Chef'sProvisioning tool. By the end of this course, you will be confident in how to manage your infrastructure, scale using the cloud, and extend the built-in functionality of Chef itself.The books used in this Learning Path are: 1) Chef Essentials 2) Chef Infrastructure Automation Cookbook – Second Edition 3) Mastering Chef Provisioning Style and approach This fast-paced guide covers the many facets of Chef and will teach administrators to use Chef as a birds-eye lens for their entire system. This book takes you through a host of step-by-step guides to solve real-world infrastructure automation challenges and offers elegant, time-saving solutions for a perfectly described and automated network.
无水印。 Mastering Chef Provisioning. Key Features This is the first Chef book focused on provisioning infrastructure as its sole task. The book offers a clear solution to a specific pain point: learn to make your system work faster. Learning better approaches to load balancing and parallelization with this book will save you time By mastering the techniques in this book, you will know how to run an entire fleet of machines without breaking a sweat This book is more helpful than the documentation ( https://docs.chef.io/provisioning.html), with a stronger guiding voice and clearer explanations and use cases Book Description This book will show you the best practices to describe your entire infrastructure as code. With the help of this book you can expand your knowledge of Chef because and implement robust and scalable automation solutions. You can automate and document every aspect of your network, from the hardware to software, middleware, and all your containers. You will become familiar with the Chef's Chef Provisioning tool. You will be able to make a perfect model system where everything is represented as code beneath your fingertips. Make the best possible use of your resources, and deliver infrastructure as code, making it as versionable, testable and repeatable as application software What you will learn Use best practices to describe your entire infrastructure as code Automate and document every aspect of your network, from the hardware of individual nodes to software, middleware, and all containers and clouds Create a perfect model system Make the best possible use of your resources and avoid redundancy Deliver on the promise of Infrastructure as Code Scale with ease by properly provisioning their infrastructure Use the best Test Driven Development methodologies About the Author Earl Waud is a virtualization development professional with more than 10 years of focused industry experience, creating innovative solutions for hypervisor provisioning, management, and automation. He is an expert in aligning engineering strategy with organizational vision and goals, and delivering highly scalable and user friendly virtualization environments. With more than 20 years of experience developing customer-facing and corporate IT software solutions, he has a proven track record of delivering high-caliber and on-time technology solutions that significantly impact business results. Earl lives in San Diego, California. He is blessed with a beautiful wife, Patti, and three amazing daughters, Alexis, Daniella, and Madison. Currently, Earl is a senior software engineer with Intuit Inc., a company that creates business and financial management solutions that simplify the business of life for small businesses, consumers, and accounting professionals. Earl can be found online at http://sandiegoearl.com. Table of Contents Setting Up a Development Environment on Your Workstation Knife Tooling and Plugins Leveraging Roles, Environments, and Policies Custom Resources Provisioning in the Traditional Data Center Provisioning in the Cloud Test-Driven Development Using Chef Provisioning

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值