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]是 ...
随机推荐
- jenkins publish .net core application to linux server
最近学习Docker与Jenkins, 网上大部分都是关于Jenkins+Git+Docker进行持续远程部署, 我一直在考虑为什么Jenkins和Docker要绑定一块使用, 因为我想单独使用Jen ...
- LeetCode 108. 将有序数组转换为二叉搜索树(Convert Sorted Array to Binary Search Tree) 14
108. 将有序数组转换为二叉搜索树 108. Convert Sorted Array to Binary Search Tree 题目描述 将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索 ...
- Jenkins+maven+gitlab自动化部署之前端构建发布(六)
前端项目构建,需要在jenkins主机部署node服务,网上有说介绍说安装对应的nodejs插件进行前端项目构建,我这里是直接调用系统npm命令,进行前端打包.具体node部署参考:Centos7部署 ...
- 数组模拟循环队列(java实现)
1.front变量的含义:front就指向队列的第一个元素,也就是说arr[front]就是队列的第一个元素front的初始值=0. 2.rear变量的含义:rear指向队列的最后一个元素的后一个位置 ...
- Spring Security 官网文档学习
文章目录 通过`maven`向普通的`WEB`项目中引入`spring security` 配置 `spring security` `configure(HttpSecurity)` 方法 自定义U ...
- visio 绘图素材
1. 前言 visio是个绘图的好工具,可是自带图形元素有限,没有还要自己画. 推荐几个矢量图形素材库,里边有很多图形,很方便的导入到visio中,放大也不失真. 阿里巴巴矢量图库网 stockio ...
- centos7安装php7.3的redis扩展(不是redis服务!)
PHP其他扩展加装扩展也是一样的步骤~ PHP官网下载redis扩展: http://pecl.php.net/package/redis 稳定版吧: [root@wf ~]# wget http:/ ...
- TCP/IP协议图--网络层中的IP协议
IP(IPv4.IPv6)相当于 OSI 参考模型中的第3层--网络层.网络层的主要作用是"实现终端节点之间的通信".这种终端节点之间的通信也叫"点对点通信". ...
- 案例(1)-- OOM异常
问题描述: 1.系统在执行某个操作时,必现OOM异常. 问题的定位: 1.排查代码,未发现问题. 2.在虚拟机启动时,添加参数:-XX:+HeapDumpOnOutOfMemoryError(当发生o ...
- react组件懒加载
组件懒加载方式-:react新增的lazy const Alert = lazy(() => import('./components/alert')); export default func ...