题目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. 获取spring上下文 - applicationContext

    前言 spring上下文是spring容器抽象的一种实现.将你需spring帮你管理的对象放入容器的一种对象,ApplicationContext是一维护Bean定义以及对象之间协作关第的高级接口. ...

  2. Mkdown常用语法

    这篇笔记停了两天,今天开始整理, 写这篇笔记主要是加强下自己的mkdown语法知识, 也当作练手之作. Mkdown 语法简介 标题 [h1 - h6] # ~ ###### 一般# 作为标题, 只有 ...

  3. MRR,BKA,ICP相关

    MRR Multi-Range Read,多范围读,5.6以上版本开始支持 工作原理&优化效果: 将查询到的辅助索引结果放在一个缓冲(read_rnd_buffer_size = 4M)中 将 ...

  4. Python yield 使用浅析【转】

    Python yield 使用浅析 IBM developerWorks 中国 : Open source IBM 开源 - IBM Developer 中国 (原 developerWorks 中国 ...

  5. SAS学习笔记53 RTF单个字符标记设置

    如何设置RTF中某一个字斜体而之后的字不斜体.下图中第一个P值都斜体并且加粗,第二个P值只有P进行了斜体和加粗

  6. docker 宿主机与容器直接文件移动命令

    1.将容器中的文件复制到宿主机 我们把容器中的 nginx 目录整个复制到  宿主机/usr/local/nginx 目录下,使用如下命令: docker cp nginx_test: /etc/ng ...

  7. SpinWait 第二篇

    SpinWait 提供了两个方法和两个只读属性. 方法: SpinWait.Reset() : 重置自旋计数器,将计数器置 0.效果就好像没调用过SpinOnce一样.SpinWait.Once() ...

  8. 天梯赛 L3-002. 堆栈

    思路:这里的线段树维护一个区间里面出现数的个数,对于Pop,push单点更新一下就好. #include<stdio.h> #include<iostream> #includ ...

  9. ABP 基于DDD的.NET开发框架 学习(一)

    ABP总体介绍 ABP是ASP.NET Boilerplate Project,ASP.NET样板项目. ABP框架定位于快速开发 ABP是一个用于最快实践和流行开发现代Web应用程序的新起点,旨在成 ...

  10. for_each使用方法详解

    for_each使用方法详解[转]   Abstract之前在(原創) 如何使用for_each() algorithm? (C/C++) (STL)曾經討論過for_each(),不過當時功力尚淺, ...