HDOJ 1157 HDU 1157 Who's in the Middle ACM 1157 IN HDU

news/2024/9/21 8:27:29

MiYu原创, 转帖请注明 : 转载自 ______________白白の屋    

 

题目地址:

http://acm.hdu.edu.cn/showproblem.php?pid=1157 

题目描述:

Who's in the Middle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2451    Accepted Submission(s): 1204


Problem Description
FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'median' cow gives: half of the cows give as much or more than the median; half give as much or less. 

Given an odd number of cows N (1 <= N < 10,000) and their milk output (1..1,000,000), find the median amount of milk given such that at least half the cows give the same amount of milk or more and at least half give the same or less.

Input
* Line 1: A single integer N 

* Lines 2..N+1: Each line contains a single integer that is the milk output of one cow.

Output
* Line 1: A single integer that is the median milk output.

Sample Input
5 2 4 1 3 5

Sample Output
3
Hint
INPUT DETAILS: Five cows with milk outputs of 1..5 OUTPUT DETAILS: 1 and 2 are below 3; 4 and 5 are above 3.

 

水题,  直接代码 :

 

/*

MiYuÔ­´´, תÌûÇë×¢Ã÷ : תÔØ×Ô ______________°×°×¤ÎÎÝ

          http://www.cnblog.com/MiYu

Author By : MiYu

Test      : 1

Program   : 1157

*/


#include <iostream>

#include <algorithm>

using namespace std;           

int cow[10010];

int main ()

{

    int N;

    while ( cin >> N ){

           for ( int i = 0; i < N; ++ i ) cin >> cow[i];

           sort ( cow, cow + N );      

           cout << cow[N/2] << endl;

    }

    return 0;

}


 

 

 

转载于:https://www.cnblogs.com/MiYu/archive/2010/09/04/1818237.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.pgtn.cn/news/17648.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

机器学习基本概念

文章目录绪论二&#xff1a;基本术语数据算法得到模型有监督学习无监督学习进行预测三&#xff1a;假设空间四&#xff1a;归纳偏好二&#xff1a;模型评估与选择一种训练集一种算法机器学习&#xff08;Machine Learning&#xff09;是一门涉及统计学、系统辨识、逼近理论、神…

数据结构--双链表

双链表 /*L x&#xff0c;表示在链表的最左端插入数 x。 R x&#xff0c;表示在链表的最右端插入数 x。 D k&#xff0c;表示将第 k 个插入的数删除。 IL k x&#xff0c;表示在第 k 个插入的数左侧插入一个数。 IR k x&#xff0c;表示在第 k 个插入的数右侧插入一个数。*/ #…

数据结构--栈

文章目录栈基本操作栈 栈是限定仅在表尾进行插入或者删除的线性表。对于栈来说&#xff0c;表尾端称为栈顶&#xff0c;表头端称为栈低。不含元素的空表称为空栈。因为栈限定在表尾进行插入或者删除&#xff0c;所以栈又被称为后进先出的线性表 基本操作 栈的初始化 判断是否…

使用Python,OpenCV执行视觉显著性检测(Visual Saliency Detection)

使用Python,OpenCV执行视觉显著性检测(Visual Saliency Detection) 这篇博客将介绍如何使用Python,OpenCV执行显著性检测,这是一个应用图像处理和计算机视觉算法来自动定位图像中最“显著”区域的过程。 通常显著性检测器分为三类算法: 静态显著性运动显著性对象显著性O…

5. 使用PyTorch预先训练的模型执行目标检测

5. 使用PyTorch预先训练的网络执行目标检测 PyTorch是什么&#xff1f;使用PyTorch训练第一个神经网络使用PyTorch训练第一个卷积神经网络使用预训练网络进行PyTorch图像分类使用预训练网络进行PyTorch目标检测&#xff08;今天的博客&#xff09; 这篇博客将介绍如何使用PyT…

机器学习二

文章目录线性回归线性回归 # -*- coding utf-8 -*- # Author : 墙缝里的草 # File : demo1004.py # Software : PyCharmimport numpy as np import random # 线性回归 的函数构造input_data 训练数据集 realresult 训练结果集 theta 参数# 线性回归函数 def _init_(self…

与ObjectDataSource共舞

4&#xff0c;ORM组件XCode&#xff08;与ObjectDataSource共舞&#xff09; XCode为了能更方便的解决大部分问题&#xff0c;不得不“屈身”于ObjectDataSource。 先上一个经典例子&#xff08;ObjectDataSourceGridView&#xff09;&#xff08;ObjectDataSource&#xff09;…

size mismatch for roi_heads.box_predictor.cls_score.weight: copying a param with shape torch.Size([9

1. 报错 RuntimeError: Error(s) in loading state_dict for FasterRCNN: size mismatch for roi_heads.box_predictor.cls_score.weight: copying a param with shape torch.Size([91, 1024]) from checkpoint, the shape in current model is torch.Size([80, 1024]). pytor…