codeforces 1186d D. Vus the Cossack and Numbers
题意:和为0的n个double数。上下取整后和还为0的构造一个。
首先都下取整,结果肯定<=0。和加起来再取绝对值num。则有num个数要上取整。那么小数部分为0的不变,不为0的挑num个上取整,其他的下取整。另外floor,ceil,round有可能丢失精度,不过这题没事。
(
PS:用强制转换是直接丢去小数,(int)1.1=1 ,(int)-1.1=-1。floor(1.1)=1.0 ,floor(-1.1)=-2.0。本题的num需从double转为int,最好全算完再转。要视num的正负决定+EPS还是-EPS。
//#pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <iomanip> #include <cstring> #include <map> #include <queue> #include <set> #include <cassert> #include <stack> #include <bitset> #include <unordered_set> #define mkp make_pair #define err cout<<"err"<<endl #define gmin(x,y) x=min(x,y) #define gmax(x,y) x=max(x,y) #define lss ll,mid,rt*2 #define rss mid+1,rr,rt*2+1 using namespace std; const double EPS=1e-10; typedef long long lon; typedef pair<lon,lon> pii; typedef unsigned long long ull; const lon SZ=1000010,SSZ=21,APB=26,one=93,INF=0x3fffffffffffffff,mod=1000000007; const int intINF=0x3f3f3f3f; double PI=acos(-1); lon n; int tim; double arr[SZ]; double ans[SZ];void init() {cin>>n;memset(ans,0x3f,sizeof(ans));lon num=0;//num+=-1.7;//cout<<num<<endl;for(int i=1;i<=n;++i){cin>>arr[i];double tmp=num+floor(arr[i]);num=tmp>EPS?tmp+EPS:tmp-EPS;//lon a=5;//a+=-3.1;//cout<<"a: "<<a<<endl;//cout<<"i: "<<i<<" "<<num<<" "<<tmp-EPS<<endl; }num*=-1;//cout<<num<<endl;for(int i=1,j=0;i<=n;++i){if(fabs(arr[i]-round(arr[i]))<EPS)ans[i]=round(arr[i]);else if(arr[i]>EPS){if(num==0||j>=abs(num))ans[i]=floor(arr[i]);else if(num>0){ans[i]=ceil(arr[i]);++j;}else ans[i]=floor(arr[i]),++j;}else{if(num==0||j>=abs(num))ans[i]=floor(arr[i]);else if(num>0)ans[i]=ceil(arr[i]),++j;else ans[i]=floor(arr[i]),++j;}}for(int i=1;i<=n;++i){if(fabs(ans[i])<EPS)ans[i]=EPS;cout<<fixed<<setprecision(0)<<ans[i]<<endl;} }void work() {}int main() {std::ios::sync_with_stdio(0);//freopen("d:\\1.txt","r",stdin); lon casenum;//cin>>casenum;//for(tim=1;tim<=casenum;++tim)//for(tim=1;cin>>n>>m;++tim) {//cout<<"Case "<<tim<<": ";//if(tim>=14)for(;;)cout<<"a"; init();work();}return 0; }
)
转载于:https://www.cnblogs.com/gaudar/p/11522961.html
codeforces 1186d D. Vus the Cossack and Numbers相关推荐
- 【 CF1186D,E,F】Vus the Cossack and Numbers/Vus the Cossack and a Field/Vus the Cossack and a Graph
太ex了,哭了哭了orz 后面两道平均一道花了我一天啊! 文章目录 D:Vus the Cossack and Numbers 题意翻译 题解 代码实现 E:Vus the Cossack and a ...
- Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力
C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...
- Codeforces Round #112 (Div. 2) E. Compatible Numbers sosdp
传送门 文章目录 题意: 思路: 题意: 思路: 以下假设all=1<<22all=1<<22all=1<<22. 转化问题,对于每个aia_iai我们都计算x= ...
- Codeforces Round #828 (Div. 3) E1. Divisible Numbers (easy version) 解题报告
原题链接: Problem - E1 - Codeforces 题目描述: This is an easy version of the problem. The only difference be ...
- 【Codeforces 851D Arpa and a list of numbers】
Arpa的数列要根据GCD变成好数列. ·英文题,述大意: 给出一个长度为n(n<=5000000)的序列,其中的元素a[i]<=106,然后输入两个数x,y(x,y<= ...
- Codeforces Round #828 (Div. 3) E2. Divisible Numbers (hard version)
翻译: 这是这道题的难解版.简单版本和硬版本之间的唯一区别是对
- Codeforces Round #673 (Div. 2) C. k-Amazing Numbers
题目链接 题意: 给你两个数n,k,求从1~n之间的每一个i在长度为n的数组中的,所有连续的长度为i的数组的公共最小值,如果没有重复值则输出-1. 思路: 遍历求每个相同的数之间的距离,即求出i到达几 ...
- 南昌不翻车 Codeforces Round #571 (Div. 2) C,D
http://codeforces.com/contest/1186 C:(挺好的思维题) 题目大意:给俩串,A和B,然后A的每一个B子串,有一个价值,就是和B不同的数目,然后让统计偶数的代价有多少个 ...
- 2019/7/18ACM集训
2019-07-18 09:15:34 这个是练习刷的题 Vus the Cossack and Numbers Vus the Cossack has nn real numbers aiai. I ...
- 怎么获取codeforces的数据_原创 | codeforces 1417C,逆向思考的数据结构题
点击上方蓝字,关注并星标,和我一起学技术. 大家好,欢迎阅读周末算法题专题. 今天我们选择的是codeforces contest 1417的C题k-Amazing Numbers.这是一道经典的数据 ...
最新文章
- gitlab更改默认Nginx
- mysql sae_新浪SAE的mysql与百度SAE的代码区别?
- dr.web for android version 9,DrWeb安全防护
- node-webkit中使用sqlite3
- minAreaRect函数
- ProtoBuf中的编码
- CodeForces - 1498D Bananas in a Microwave(思维+dp)
- [z] 电子技术的老生常谈 —— 接地
- 周长相等的正方形面积一定相等_三年级下册数学期末重点——面积
- linux查看系统启动时间
- 3D应用开发中的欧拉角和旋转矩阵
- 软件开发生命周期中的设计阶段_什么是软件生命周期模型?软件测试和软件开发的关系分析!...
- 单表mysql分页查询语句怎么写_MySQL单表百万数据记录分页性能优化技巧
- Linux 硬盘读写测速
- 深圳保障性住房【公租房、安居房、人才房】简单说明
- 发送邮件被退回,提示: Helo command rejected: Invalid name 错误
- 蝴蝶效应,青蛙现象,鳄鱼法则,鲇鱼效应,羊群效...
- 用计算机刻录光盘,笔记本电脑刻录光盘 手把手教你刻录光盘
- Unreal Engine 4 渲染目标(Render Target)教程 之 实现雪地足迹(下)
- 第一章 android以及智能手机行业相关简介