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;
    }

     
     
     
  • 相关阅读:
    APMServ5.2.6 无法启动Apache的一个问题
    【转】流媒体技术笔记(视频编码相关)
    用APMServ一键快速搭建Apache+PHP+MySQL+Nginx+Memcached+ASP运行平台
    java swing 基础
    python class 类
    python 经验
    python 导入(转)
    kernel ipv4/ip_output.c
    python+正则表达式(转)
    Eclipse中如何快速添加、删除jar包
  • 原文地址:https://www.cnblogs.com/unclejelly/p/4082151.html
Copyright © 2011-2022 走看看