题目http://codeforces.com/contest/1186/problem/D

题意:给定一个大小为$n$的浮点序列,这$n$个数的和为0.

现在对这个序列中的每个数,进行向上取整或向下取整的操作,使得得到的整数序列之和也是0.

思路:假设我们现在的某一种取法得到的和是$ans$,那么改变其中一个数的取法对$ans$的改变可能是+1或是-1

所以我们想随便按照某种方法得到一个结果,再进行调整就可以了。

最简单的就是我们全部先取整数部分,如果此时的$ans>0$说明负数都太小了,那么我们就找$ans$个负数,让他们改成取下整。

如果$ans<0$说明正数都太小了,我们就找$ans$个正数,让他们改成取上整于是答案就会相应增加$ans$变成了0.

 #include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<iostream> #define inf 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef pair<int, int> pr; int n;
const int maxn = 1e5 + ;
float num[maxn]; int main()
{
scanf("%d", &n);
int ans = ;
for(int i = ; i < n; i++){
scanf("%f", &num[i]);
ans += (int)num[i];
} //printf("%d\n", ans);
if(ans > ){
for(int i = ; i < n; i++){
if(num[i] > || (int)num[i] == num[i] || ans <= )printf("%d\n", (int)num[i]);
else {
printf("%d\n",(int)(num[i] - ));
ans--;
}
}
}
else{
for(int i = ; i < n; i++){
if(num[i] < || (int)num[i] == num[i] || ans >= )printf("%d\n", (int)num[i]);
else{
printf("%d\n", (int)(num[i] + ));
ans++;
}
}
} return ;
}

codeforces#571Div2 D---Vus the Cossack and Numbers【贪心】的更多相关文章

  1. Codeforces F. Vus the Cossack and Numbers(贪心)

    题目描述: D. Vus the Cossack and Numbers Vus the Cossack has nn real numbers aiai. It is known that the ...

  2. Codeforces Round #571 (Div. 2)-D. Vus the Cossack and Numbers

    Vus the Cossack has nn real numbers aiai. It is known that the sum of all numbers is equal to 00. He ...

  3. CodeForces - 1186 C. Vus the Cossack and Strings (异或)

    Vus the Cossack has two binary strings, that is, strings that consist only of "0" and &quo ...

  4. 『Codeforces 1186E 』Vus the Cossack and a Field (性质+大力讨论)

    Description 给出一个$n\times m$的$01$矩阵$A$. 记矩阵$X$每一个元素取反以后的矩阵为$X'$,(每一个cell 都01倒置) 定义对$n \times m$的矩阵$A$ ...

  5. Vus the Cossack and Strings(Codeforces Round #571 (Div. 2))(大佬的位运算实在是太强了!)

    C. Vus the Cossack and Strings Vus the Cossack has two binary strings, that is, strings that consist ...

  6. 构造 Codeforces Round #107 (Div. 2) B. Phone Numbers

    题目传送门 /* 构造:结构体排个序,写的有些啰嗦,主要想用用流,少些了判断条件WA好几次:( */ #include <cstdio> #include <algorithm> ...

  7. E. Vus the Cossack and a Field (求一有规律矩形区域值) (有一结论待证)

    E. Vus the Cossack and a Field (求一有规律矩形区域值) 题意:给出一个原01矩阵,它按照以下规则拓展:向右和下拓展一个相同大小的 0 1 分别和原矩阵对应位置相反的矩阵 ...

  8. codeforces 1186C Vus the Cossack and Strings

    题目链接:https://codeforc.es/contest/1186/problem/C 题目大意:xxxxx(自认为讲不清.for instance) 例如:a="01100010& ...

  9. Codeforces 1186F - Vus the Cossack and a Graph 模拟乱搞/欧拉回路

    题意:给你一张无向图,要求对这张图进行删边操作,要求删边之后的图的总边数 >= ceil((n + m) / 2), 每个点的度数 >= ceil(deg[i] / 2).(deg[i]是 ...

随机推荐

  1. java8中常用的新功能

    Lambda表达式的用法,并行流.Optional.循环.线程池等

  2. [ClickOnce] - Win10 管理员模式下无法安装 ClickOnce 之解决

    Issue Windows 10 管理员模式下,点击 ClickOnce 安装程序无反应. 解决 1. 按 WIN+R 键打开“运行”窗口,输入 “gpedit.msc" 打开组策略.2.  ...

  3. CF731E Funny Game

    题目描述 一个长度为 N 的序列 ai ,双方轮流操作 每次的操作是选择一个长度大于 1 的前缀,计算它的和 s ,然后 用 s 替换它的前缀,同时当前玩家获得 s 的分数. 当只剩下一个元素,游戏结 ...

  4. centos 6.10 oracle 19c安装

    centos 7以下版本安装oracle 19c 问题较多,centos 以上版本没有任何问题.记录如下. hosts文件,否则图形界面无法启动 127.0.0.1 localhost localho ...

  5. golang 切片使用注意事项

    // list 默认值为nil,可以直接append值,有值后json后为数组对象,但如果没有初始化空间的话,json编码后为null var list []*Pepole // list 初始化空间 ...

  6. 模板模式(Template Pattern)

    模板模式(Template Pattern) -- 定义一个操作中的算法的骨架,而将一些步骤延迟到子类中.Template Method使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤. ...

  7. 怎样输出Hello World

    方法一: 进入python交互模式, 然后使用: print()函数输出 方法二:  新建一个.py文件, 然后写入print()函数, 再使用python命令执行输出:

  8. Asp.Net 加载不同项目程序集

    我们做项目时有时候不想添加别的项目的引用,但是那个项目又必须在 Global 中进行注册 最常见的就是插件机制,参考: https://shazwazza.com/post/Developing-a- ...

  9. C# DataGridView 动态添加列和行

    https://blog.csdn.net/alisa525/article/details/7350471 dataGridView1.ReadOnly = true ;      //禁用编辑功能 ...

  10. ubuntu环境下pycharm编译程序import包出错:ImportError: dynamic module does not define init function (init_caffe)

    出错原因是因为pycharm中的python版本不对,比如程序为2.7版本,但是pycharm编解释器为python3,导致出错,去setting改一下版本就行:pycharm>file> ...