codeforces#571Div2 D---Vus the Cossack and Numbers【贪心】
题目: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【贪心】的更多相关文章
- 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 ...
 - 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 ...
 - 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 ...
 - 『Codeforces 1186E 』Vus the Cossack and a Field (性质+大力讨论)
		
Description 给出一个$n\times m$的$01$矩阵$A$. 记矩阵$X$每一个元素取反以后的矩阵为$X'$,(每一个cell 都01倒置) 定义对$n \times m$的矩阵$A$ ...
 - 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 ...
 - 构造 Codeforces Round #107 (Div. 2) B. Phone Numbers
		
题目传送门 /* 构造:结构体排个序,写的有些啰嗦,主要想用用流,少些了判断条件WA好几次:( */ #include <cstdio> #include <algorithm> ...
 - E. Vus the Cossack and a Field (求一有规律矩形区域值)  (有一结论待证)
		
E. Vus the Cossack and a Field (求一有规律矩形区域值) 题意:给出一个原01矩阵,它按照以下规则拓展:向右和下拓展一个相同大小的 0 1 分别和原矩阵对应位置相反的矩阵 ...
 - codeforces 1186C Vus the Cossack and Strings
		
题目链接:https://codeforc.es/contest/1186/problem/C 题目大意:xxxxx(自认为讲不清.for instance) 例如:a="01100010& ...
 - Codeforces 1186F - Vus the Cossack and a Graph 模拟乱搞/欧拉回路
		
题意:给你一张无向图,要求对这张图进行删边操作,要求删边之后的图的总边数 >= ceil((n + m) / 2), 每个点的度数 >= ceil(deg[i] / 2).(deg[i]是 ...
 
随机推荐
- Word 域代码使用方法
			
插入域「Crtl+F9」 更新域「F9」 切换域代码「Alt+F9」 批量删除域 打开 Word 文档,全选,按下「Alt+F9」键,将 Word 中所有的域结果切换为域代码的形式. 调出" ...
 - scrapy框架3——请求传参
			
当使用scrapy爬取的数据不在同一张页面中(一次请求与数据后解析无法获得想要的全部数据),需要请求传参,在第一次解析时实例化item,将item传递,再次将请求到的数据解析后,封装在item中. 关 ...
 - ~jmeter解决csrftoken登录问题
			
一.登录接口 url:http://192.168.163.128:/user/login/ 请求方法:post 请求参数: account:用户名 password:登录密码 remember:是否 ...
 - 基本数据类型和string的转换
 - 【并发】7、借助redis 实现多线程生产消费队列
			
1.这是第一个简单的初始化版本,看起来比使用fqueue似乎更好用 package queue.redisQueue; import queue.fqueue.vo.TempVo; import re ...
 - Jira是什么
			
JIRA这个工具接触有好几年了,在多个海外项目上都用过这个工具.去年又在项目上深度使用后就有点爱不释手了,回国后也在找机会推荐给其它项目上用.最近正好有新项目需要用,借这个机会把JIRA的配置学习的过 ...
 - puppet工作原理之模块使用
			
一.模块介绍 1.什么是模块 通常情况把manifest文件分解成易于理解得结构,例如类文件,配置文件分类存放,并通过某种机制整合使用,这种机制就是模块,有助于结构化.层次化的方式使用puppet,p ...
 - 在论坛中出现的比较难的sql问题:16(取一个字段中的数字)
			
原文:在论坛中出现的比较难的sql问题:16(取一个字段中的数字) 所以,觉得有必要记录下来,这样以后再次碰到这类问题,也能从中获取解答的思路. 问题:取一个字段中的数字http://bbs.csdn ...
 - linux高频操作: host,用户管理,免密登陆,管道,文件权限,脚本,防火墙,查找
			
1. 修改hosts和hostname 2. 用户管理 3. 免秘登陆 4. 文件末尾添加 >> 5. 设置可执行文件 6. 任何地方调用 7. Centos6 永久关闭防火墙 8. Ce ...
 - Html5知识精粹纪录
			
1. HTML5文档的正文结构及新元素 正文结构: <header> <nav> <section> <aside> <footer> 深入 ...