zoukankan      html  css  js  c++  java
  • nyoj 811-变态最大值 (max)

    811-变态最大值


    内存限制:64MB 时间限制:1000ms 特判: No
    通过数:6 提交数:15 难度:1

    题目描述:

    Yougth讲课的时候考察了一下求三个数最大值这个问题,没想到大家掌握的这么烂,幸好在他的帮助下大家算是解决了这个问题,但是问题又来了。

    他想在一组数中找一个数,这个数可以不是这组数中的最大的,但是要是相对比较大的,但是满足这个条件的数太多了,怎么办呢?他想到了一个办法,把这一组数从开始把每相邻三个数分成一组(组数是从1开始),奇数组的求最大值,偶数组的求最小值,然后找出这些值中的最大值。

    输入描述:

    有多组测试数据,以文件结束符为标志。
    每组测试数据首先一个N,是数组中数的个数。(0<N<10000,为降低题目难度,N是3的倍数)
    然后是数组中的这些数。

    输出描述:

    输出包括一行,就是其中的最大值。

    样例输入:

    3
    4 5 6
    6
    1 2 3 7 9 5
    

    样例输出:

    6
    5

    C/C++ :

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    #include <stack>
    #include <set>
    #include <map>
    #include <queue>
    #include <climits>
    #include <bitset>
    #define PI 3.1415926
    
    using namespace std;
    
    int main()
    {
        int n;
        while (cin >>n)
        {
            int ans = -INT_MAX, a, b, c;
    
            for (int i = 1, j = 1; i <= n; i += 3, ++ j)
            {
                cin >>a >>b >>c;
                if (j & 1)
                {
                    int temp = a;
                    if (temp < b)
                        temp = b;
                    if (temp < c)
                        temp = c;
                    ans = max(temp, ans);
                }
                else
                {
                    int temp = a;
                    if (temp > b)
                        temp = b;
                    if (temp > c)
                        temp = c;
                    ans = max(ans, temp);
                }
            }
    
            printf("%d
    ", ans);
        }
    
        return 0;
    }
  • 相关阅读:
    神经网络(2)---neurons and the brain
    P2P system:How Chord tackles failures
    如何成为更好的自己
    P2P system: Chord
    P2P system: FastTrack and BitTorrent
    P2P system: GNUTELLA
    P2P system: Napster
    P2P system: Introduction
    幸福公开课(2)
    MTV与MVC 多对多表的创建方式 前后端传输数据编码格式 ajax 批量插入数据 自定义分页器
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/9354129.html
Copyright © 2011-2022 走看看