题目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. dotnet core use RabbitMQ

    安装RabbitMQ 自从使用了Docker之后,发现Docker真的是比虚拟机好用啊, 因此我这里在Docker里面创建一个RabbitMQ容器. 这里注意获取镜像的时候要获取management版 ...

  2. Java后台面试之java基础

    经典类概念性问题 1.java支持的数据类型有哪些?什么是自动拆装箱? 12.Java有哪些特性,举个多态的例子. 14.请列举你所知道的Object类的方法. 15.重载和重写的区别?相同参数不同返 ...

  3. js取小数点后两位数的方法

    四舍五入以下处理结果会四舍五入:toFixed( ) var num =2.446242342; num = num.toFixed(2); // 输出结果为 2.45 不四舍五入以下处理结果不会四舍 ...

  4. 【转帖】2019年中国5G行业细分市场发展现状和市场前景分析 通信基站数量快速增长

    2019年中国5G行业细分市场发展现状和市场前景分析 通信基站数量快速增长 中国有 600多万个基站 平均每200个人 一个基站.. 一个基站十万块钱的话 相当于 每个人 需要分摊 500块钱. ht ...

  5. C#中的System.Web.HttpUtility.UrlEncode转码问题

    最近需要与JAVA程序对接口,其中遇到的URL转码问题: Java中URL编码所用的 URLEncoder.encode 产生的字符是大写且英文'(',')'是分别转成'%28'和 '%29' 而C# ...

  6. Tp5.1 管理后台开发纪要

    1. tp5.1 对网页是有缓存机制的 E:\phpStudy\PHPTutorial\WWW\NewAdmin\thinkphp\library\think\Template.php 下displa ...

  7. 《Mysql - 如何恢复和避免误删除?》

    一:误删数据 (如何恢复和避免误删除) - 使用 delete 语句误删数据行: - 使用 drop table 或者 truncate table 语句误删数据表: - 使用 drop databa ...

  8. Python 编程入门

    我喜欢直接了当, 这次主要是推荐蟒营大妈的 Python 入门课(https://py.101.camp), 还有不到一周就要开课了, 欢迎转发推荐~ 点击"夏日大作战:从小白到小能手的 P ...

  9. PAT(B) 1042 字符统计(Java)字符串 正则表达式 统计

    题目链接:1042 字符统计 (20 point(s)) 题目描述 请编写程序,找出一段给定文字中出现最频繁的那个英文字母. 输入格式 输入在一行中给出一个长度不超过 1000 的字符串.字符串由 A ...

  10. 机器学习之主成分分析PCA原理笔记

    1.    相关背景 在许多领域的研究与应用中,通常需要对含有多个变量的数据进行观测,收集大量数据后进行分析寻找规律.多变量大数据集无疑会为研究和应用提供丰富的信息,但是也在一定程度上增加了数据采集的 ...