`
Poechant
  • 浏览: 227550 次
博客专栏
Bebe66e7-3a30-3fc9-aeea-cfa3b474b591
Nginx高性能Web服务...
浏览量:24243
5738817b-23a1-3a32-86de-632d7da73b1e
Cumulus实时媒体服务...
浏览量:22051
社区版块
存档分类
最新评论

Overcome ACM POJ 2370 - Democracy in danger

 
阅读更多

Problem:2370
User:Poechant
Memory:728K
Time:16MS
Language:G++
Result:Accepted

    /*

    * 作者:柳大·Poechant

    * 博客:http://blog.csdn.net/poechant

    * 思路: 先按每组人数对n组进行快排,然后算出前(n/2+1)组各组人数(若为x)的x/2+1的和,即为结果。

    */

    #include<iostream>

    usingnamespace std;


    int partition(int* data,int l,int h);

    void quick_sort(int* data,int l,int h);


    int main(void)

    {

    int n;

    while (cin >> n)

    {

    int i;

    int *m =newint[n];

    int sum = 0;

    for (i = 0; i < n; ++i)

    {

    cin >> m[i];

    sum += m[i];

    }

    quick_sort(m, 0, n -1);


    int d = 0;

    i = 0;

    int l = n / 2 + 1;

    while (i < l)

    {

    d += m[i] / 2 + 1;

    ++i;

    }

    cout << d <<endl;

    }

    return 0;

    }


    // quick sort algorithm

    void quick_sort(int* data,int l,int h)

    {

    if (l < h)

    {

    int m = partition(data, l, h);

    quick_sort(data, l, m - 1);

    quick_sort(data, m + 1, h);

    }

    }


    // partition for quick sorting

    int partition(int* data,int l,int h)

    {

    int k = data[h];

    int j = l;

    for (int i = l; i <= h; ++i)

    {

    if (data[i] < k)

    {

    data[i] = data[i] + data[j] - (data[j] = data[i]);

    ++j;

    }

    }

    if (data[j] > k)

    {

    data[j] = data[j] + data[h] - (data[h] = data[j]);

    }

    elseif (j < h)

    {

    ++j;

    data[j] = data[j] + data[h] - (data[h] = data[j]);

    }

    return j;

    }



    分享到:
    评论

    相关推荐

      How-To-Overcome-Procrastination

      ### 如何克服拖延:全面解析与实用策略 #### 一、为什么需要克服拖延? 在《个人卓越博客》中,作者Celestine Chua探讨了一系列关于如何克服拖延的文章。本章节聚焦于“为什么需要克服拖延”这一核心问题。...

      Multi-Corner Multi-Mode Synthesis in Design Compiler

      tools Design Compiler®(**) (DC) and IC Compiler®(***) (ICC) is overcome now. Design Compiler® can handle multiple constraint sets and optimize for multiple corners (multi-mode multi-corner (MCMM))

      002001-Overcome

      002001-Overcome_Kernel_v4.0.0

      A-Robot-in-every-home家家都有机器人.doc

      porary: the emergence of robotics as a transformative force in society, much like the personal computer revolution did decades ago. Bill Gates, the visionary behind Microsoft, forecasts that robotics ...

      AI深度学习框架下基于隧道CCTV的事故检测的远距离限制克服_An overcome of far-distance limit

      在AI深度学习框架下,基于隧道CCTV的事故检测技术是交通安全监控的重要组成部分,尤其在隧道这样的封闭环境中,及时准确的事故识别至关重要。然而,现有的隧道CCTV系统由于安装高度低、间隔距离长,存在严重的透视...

      High Performance in-memory computing with Apache Ignite.pdf

      world scenario, the commonly occurring challenges in each scenario has also discussed, along with tips and tricks and best practices on how to overcome them. Every chapter is independent and a ...

      Blockchain Basics: A Non-Technical Introduction in 25 Steps

      Blockchain Basics: A Non-Technical Introduction in 25 Steps By 作者: Daniel Drescher ISBN-10 书号: 1484226038 ISBN-13 书号: 9781484226032 Edition 版本: 1st ed. 出版日期: 2017-03-16 pages 页数: (276 ) ...

      Overcome_Kernel_v2.1.6_OCUV_ODIN.tar

      Overcome_Kernel_v2.1.6_OCUV_ODIN.tar

      Spark: Big Data Cluster Computing in Production

      Overcome common problems encountered using Spark in production Spark works with other big data tools including MapReduce and Hadoop, and uses languages you already know like Java, Scala, Python, and ...

      OverCome2.3.3.zip.003

      这是我用过的P1000最好的系统(到目前为止),系统运行很流畅,相比之前上传的那个2.3.4的刷机包,overcome2.3.3更胜一筹.由于文件太大所以将文件压缩成了8个小的压缩包,大家下载的时候不要遗漏,压缩包中有安装教程,大家...

      OverCome2.3.3.zip.008

      这是我用过的P1000最好的系统(到目前为止),系统运行很流畅,相比之前上传的那个2.3.4的刷机包,overcome2.3.3更胜一筹.由于文件太大所以将文件压缩成了8个小的压缩包,大家下载的时候不要遗漏,压缩包中有安装教程,大家...

      内蒙古开鲁县蒙古族中学2017_2018学年高二英语下学期第四次周测试题无答案

      - in danger 处于危险之中 - in trouble 陷入困境 - in surprise 惊讶地 - in order 整齐,有序 - in short 简言之 9. 动词短语: - (1) die away 消失,逐渐减弱 - (2) die down 平息,减弱 - (3) die off...

      MATLAB远程仿真终端

      I often dream one day MATLAB will overcome its shortcomings--slow speed and large size and becomes a mainstream language. So I want to develop a MATLAB remoter to extend the flexibility of MATLAB. ...

      (正文)制约我国B2C电子商务发展的原因及对策-以京东为例.doc

      Through strategic partnerships, policy advancements, infrastructure investments, and continuous innovation, China's B2C e-commerce industry, including players like Jingdong Mall, can overcome these ...

      克服甲状腺功能减退「Overcome Hypothyroidism」-crx插件

      自然地、全面地治疗你的甲状腺。不要让你的甲状腺让你又胖又累。 女性甲状腺治疗致力于以自然,全面的方式帮助女性克服甲状腺疾病。 我们讨论减轻体重,增加甲状腺产量,改善睡眠和拥有更多能量的自然方法。...

      OverCome2.3.3.zip.002

      这是我用过的P1000最好的系统(到目前为止),系统运行很流畅,相比之前上传的那个2.3.4的刷机包,overcome2.3.3更胜一筹.由于文件太大所以将文件压缩成了8个小的压缩包,大家下载的时候不要遗漏,压缩包中有安装教程,大家...

      Episode-Based Prototype Generating Network for Zero-Shot Learnin

      Shot Learning (ZSL) has emerged as a promising approach to overcome this limitation by recognizing novel classes without requiring any labeled examples during training. Instead, ZSL leverages semantic...

    Global site tag (gtag.js) - Google Analytics