题意
       输入n个在[1.95,2.05]范围内的数。
       保证他们的平均数为2.00。
       现在要求把这些数调整出一个顺序,
       使得任意长度为K的子段和与2.00*K的差值的绝对值不超过0.01(K=1,2...,n)


Solution:

由于数的范围,和平均数为2,保证了有解。

对所有数-2,使得前缀和的绝对值不超过0.1即可。

由于数的范围在1.95~2.05之间,减去2后小于0的数一定等于大于0的数。

只要每两个位置放上一正一负即可

code

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
int n,m;
double s[6009];
int ans[6009],g[6009];
bool cmp(int a,int b){
return s[a]<s[b];
}
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>s[i],s[i]-=2,g[i]=i;
sort(g+1,g+1+n,cmp);
int i=1,j=n,t=0;
double tem=0;
while(t<n){
if(tem>=0){
tem+=s[g[i]];
ans[++t]=g[i++];
}
else{
tem+=s[g[j]];
ans[++t]=g[j--];
}
}
puts("yes");
for(int i=1;i<=n;i++)
cout<<ans[i]<<" ";
return 0;
}

  

SGU 165.Basketball的更多相关文章

  1. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

  2. SGU Volume 1

    SGU 解题报告(持续更新中...Ctrl+A可看题目类型): SGU101.Domino(多米诺骨牌)------------★★★type:图 SGU102.Coprimes(互质的数) SGU1 ...

  3. flash小游戏在Kongregate上线——BasketBall Master(篮球大师)

    小游戏地址,欢迎上去留言评论.游戏完成度没有达到期望水平,只能算完成了核心玩法吧,一些其他构想来不及实现. BasketBall Master(篮球大师) 这个小游戏很早之前就基本做好了,只因有些细节 ...

  4. [百度网盘]Xamarin for Visual Studio 3.7.165 Preview 最新版-介绍

    Xamarin 3.7.165 Preview 下载地址:http://download.xamarin.com/XamarinforVisualStudio/Windows/Xamarin.Visu ...

  5. SGU 495. Kids and Prizes

    水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...

  6. ACM: SGU 101 Domino- 欧拉回路-并查集

    sgu 101 - Domino Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Desc ...

  7. 【SGU】495. Kids and Prizes

    http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...

  8. SGU 455 Sequence analysis(Cycle detection,floyd判圈算法)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=455 Due to the slow 'mod' and 'div' operati ...

  9. SGU 422 Fast Typing(概率DP)

    题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...

随机推荐

  1. Delphi 编写的Web Service

      一编写服务程序 第一步:File----->New----->Other------>WebServices----->Soap Server Application选择I ...

  2. 4G来临 IT业转型之路当在不远

    摘 要:4G商用未启,品牌营销争夺已经展开.目前,除了中国移动推出全新4G品牌“andM”之外,中国电信和中国联通均选择继续沿用3G的品牌. 4G商用未启,品牌营销争夺已经展开.12月10日,中国电信 ...

  3. c++异常安全和copy and swap策略

    异常安全有两个目标: 不泄露任何资源.这个通过RAII可以做到. 不破坏数据结构.这是下文要讨论的事情 异常安全有三个级别: 基本安全:异常发生后对象和数据结构还有合法状态.实现简单,应该作为最低要求 ...

  4. A*寻路算法的探寻与改良(二)

    A*寻路算法的探寻与改良(二) by:田宇轩                                                     第二部分:这部分内容主要是使用C语言编程实现A*, ...

  5. Sicily1059-Exocenter of a Trian

    代码地址: https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1059.c 1059. Exocenter of a ...

  6. ContentProvider初阶Cookbook

    在Android世界里,ContentProvider将数据存储抽象成了类似SQL的形式,通过insert, delete, update, query等接口实现对数据的增删改查.通过ContentP ...

  7. jemalloc/jemalloc.h: No such file or directory

    Redis 2.6.9 安装报错,提示: zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directoryzmalloc.h ...

  8. Scrambled Polygon - POJ 2007(求凸包)

    给一些点,这些点都是一个凸包上的顶点,以第一个点为起点顺时针把别的点拍排一下序列. 分析:最简单的极坐标排序了..................... 代码如下: ----------------- ...

  9. Ehcache专栏

    http://www.iteye.com/blogs/subjects/ehcache

  10. hive UDAF源代码分析

    sss /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license a ...