Codeforces Round #237 Div.2 B
来源:互联网 发布:几比几的比例怎么算法 编辑:程序博客网 时间:2024/05/16 11:12
题目链接:http://codeforces.com/contest/404/problem/B
模拟题,但是数据很大,可能会溢出。所以要使用一些防止溢出。
刚开始写没有注意防止溢出,结果过不了后面的数据,下面是没有通过的代码:
///2014.3.19///Codeforces Round #237 Div.2///B#include <iostream>#include <cstdio>using namespace std;int main(){ // freopen("in","r",stdin); // freopen("out","w",stdout); double a,d; cin>>a>>d; double n; cin>>n; double zero = 0.0; for(int i=1 ; i<=n ; i++){ double l = i*d-int(i*d/(4*a))*4*a; if( l<=a ){ printf("%.10lf %.10lf\n",l,zero ); } else if( l<=2*a ){ printf("%.10lf %.10lf\n",a,l-a ); } else if( l<=3*a ){ printf("%.10lf %.10lf\n",3*a-l,a ); } else{ printf("%.10lf %.10lf\n",zero,4*a-l ); } } return 0;}
///2014.3.19///Codeforces Round #237 Div.2///B#include <iostream>#include <cstdio>using namespace std;int main(){ // freopen("in","r",stdin); // freopen("out","w",stdout); double a,d; cin>>a>>d; int n; cin>>n; double zero = 0.0; double x,y; x = d; y = 0; int nn = 0; while( x>=a ){ x -= a; nn++; } int t = 0; for(int i=1 ; i<=n ; i++){ y += x; t += nn; while( y>=a ){ y -= a; t++; } switch( t%4 ){ case 0: printf("%.10lf %.10lf\n",y,zero ); break; case 1: printf("%.10lf %.10lf\n",a,y); break; case 2: printf("%.10lf %.10lf\n",a-y,a ); break; case 3: printf("%.10lf %.10lf\n",zero,a-y ); break; } } return 0;}
codeforces比赛结束了可以看别人的代码,还有题解,挺不错的。就是比赛时间太坑了,上海时间11:30到凌晨1:30 (>﹏<)。等到下学期回到石河子就好啦,^_^
0 0
- Codeforces Round #237 (Div. 2) A & B
- Codeforces Round #237 Div.2 B
- Codeforces Round #237 (Div. 2) B
- Codeforces Round #237 (Div. 2) B. Marathon
- Codeforces Round #147 (Div. 2) / 237B Young Table (搜索)
- Codeforces Round #237 (Div. 2)B. Marathon解题报告
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #134 (Div. 2)B. Airport
- Codeforces Round #170 (Div. 2) problem B
- Codeforces Round #173 (Div. 2) Problem B
- Codeforces Round #181 (Div. 2) B. Coach
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #171 (Div. 2) B
- Codeforces Round #169 (Div. 2) B题
- Codeforces Round #188 (Div. 2) B题
- Codeforces Round #192 (Div. 2) B
- Codeforces Round #203 (Div. 2) B. Resort
- Codeforces Round #206 (Div. 2) - b
- OCP 1Z0 051 12
- Hibernate Annotation(注解)
- JQuery中2个等号与3个等号的区别
- 【Android数据存储】- File
- UML的关系
- Codeforces Round #237 Div.2 B
- UItabelView-实例化一个表格视图
- iftop和iostat安装和简单使用
- 【Python学习笔记】《和孩子一起学编程》第2章 记住内存和变量
- Android EditView属性详细介绍
- poj3009 Curling 2.0 dfs+剪枝 编程不是想当然,要严谨,滴水不漏
- 图论-最小生成树-并查集-Kruskal
- 怎么判断对象是否与仪器连接?
- VS提示找不到xx.exe 找不到生成的exe文件