zoukankan      html  css  js  c++  java
  • shǎ崽 OrOrOrOrz

    shǎ崽 OrOrOrOrz

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 5395    Accepted Submission(s): 2555

    Problem Description
    Acmer in HDU-ACM team are ambitious, especially shǎ崽, he can spend time in Internet bar doing problems overnight. So many girls want to meet and Orz him. But Orz him is not that easy.You must solve this problem first.
    The problem is :
    Give you a sequence of distinct integers, choose numbers as following : first choose the biggest, then smallest, then second biggest, second smallest etc. Until all the numbers was chosen .
    For example, give you 1 2 3 4 5, you should output 5 1 4 2 3

    Input
    There are multiple test cases, each case begins with one integer N(1 <= N <= 10000), following N distinct integers.

    Output
    Output a sequence of distinct integers described above.

    Sample Input
    5 1 2 3 4 5
     

    Sample Output
    5 1 4 2 3
    第一次用的好一点的STL吧。纪念一下,虽然用法也是比较简单的。以前我总是不希望自己直接使用STL这一偷懒的捷径。。。总有一种负罪感。所以以前有意抵触STL。其实我错了,学习不应该固步自封。。我不应该想着等我可以自己实现STL的核心算法的时候再去学习使用STL。。。西方有句谚语:不需要重复制造轮子!!!或许我应该先学会使用STL再去探究其内部实现。学习就是如此有时需要从下到上,但有时也需要从上到下。
     
    #include <iostream>
    #include <algorithm>
    #include <vector>
    using namespace std;
    int n;
    vector<int> a;
    int main()
    {
    	int t;
    	while(scanf("%d",&n)!=EOF)
    	{
    		for(int i=0;i<n;i++)
    			{
    				scanf("%d",&t);
    				a.push_back(t);
    		}
    		sort(a.begin(),a.end());
    		vector<int>::iterator itb=a.begin();
    		vector<int>::iterator ite=a.end()-1;
    		while(1)
    		{
    			printf("%d ",*ite);
    			ite--;
    			if(ite==itb)
    			{
    				printf("%d
    ",*ite);
    				break;
    			}
    			printf("%d ",*itb);
    			itb++;
    			if(ite==itb)
    			{
    				printf("%d
    ",*ite);
    				break;
    			}
    		}
    		a.clear();
    	}
    	return 0;
    }

     
     
     
  • 相关阅读:
    Kruskal
    克鲁斯卡尔
    克鲁斯卡尔
    实践是检验真理的唯一标准 脱壳篇02
    Kruskal
    克鲁斯卡尔算法讲解
    实践是检验真理的唯一标准 脱壳篇02
    最小生成树(普里姆算法) 数据结构和算法62
    克鲁斯卡尔算法讲解
    最小生成树(普里姆算法) 数据结构和算法62
  • 原文地址:https://www.cnblogs.com/unclejelly/p/4082151.html
Copyright © 2011-2022 走看看