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

     
     
     
  • 相关阅读:
    Java基础知识
    spring data jpa 表关联设置用户表关联角色表配置
    centos 服务器 nginx 负载均衡服务安装
    Java jdk 8 新特性
    个人收款支付系统-半自动化解决方案
    纯净版Windows7系统迅雷下载路径
    Centos里开机自启动Node 服务程序
    Centos 7将java jar包自定义开机启动服务
    安装zabbix-agent客户端
    Centos7系统安装Zabbix4.4(yum源安装)
  • 原文地址:https://www.cnblogs.com/unclejelly/p/4082151.html
Copyright © 2011-2022 走看看