Codeforces Round #237 (Div. 2)B. Marathon解题报告
来源:互联网 发布:银行从业资格考试软件 编辑:程序博客网 时间:2024/05/16 15:03
地址:http://codeforces.com/contest/404/problem/B
题意:运动员在一个a*a的正方形跑道沿着逆时针跑,每隔d米就喝一瓶水,求每次喝水的坐标,题目不难,模拟题一道
开始挂在了第八组上了,代码如下
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;void prin(double s,double len){ int m=(int)floor(s/len); int t=m; double r=s-m*len; t=t%4; switch(t) { case 0: { printf("%.10lf 0.0000000000\n",r);break; } case 1: { printf("%.10lf %.10lf\n",len,r);break; } case 2: { printf("%.10lf %.10lf\n",len-r,len);break; } case 3: { printf("0.0000000000 %.10lf\n",len-r);break; } }}int main(){ double a,d; int n,i; scanf("%lf%lf",&a,&d);scanf("%d",&n); for(i=1;i<=n;i++) prin(i*d,a);return 0;}
错误数据:1 100000100000原因:int造成的精度损失,改成long long 即可正确代码:#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;void prin(double s,double len){ long long m=(long long)floor(s/len); long long t=m; double r=s-m*len; t=t%4; switch(t) { case 0: { printf("%.10lf 0.0000000000\n",r);break; } case 1: { printf("%.10lf %.10lf\n",len,r);break; } case 2: { printf("%.10lf %.10lf\n",len-r,len);break; } case 3: { printf("0.0000000000 %.10lf\n",len-r);break; } }}int main(){ double a,d; long n,i; scanf("%lf%lf",&a,&d);scanf("%d",&n); for(i=1;i<=n;i++) prin(i*d,a);return 0;}
0 0
- Codeforces Round #237 (Div. 2)B. Marathon解题报告
- Codeforces Round #237 (Div. 2) B. Marathon
- Codeforces Round #226 (Div. 2) B、C解题报告
- Codeforces Round #277 (Div. 2) 解题报告(B C)
- Codeforces Round #283 (Div. 2) 解题报告(A B C)
- Codeforces Round #284(Div.2) A,B,C解题报告
- Codeforces Round #285(Div.2) A,B,C 解题报告
- Codeforces Round #338 (Div. 2)B. Longtail Hedgehog解题报告
- Codeforces Round #149 (Div. 2)解题报告
- Codeforces Round #180 (Div. 2) 解题报告
- Codeforces Round #190 (Div. 2) 解题报告
- Codeforces Round #191 (Div. 2) 解题报告
- Codeforces Round #189 (Div. 2) 解题报告
- Codeforces Round #142 (Div. 2) 解题报告
- Codeforces Round #229 (Div. 2) 解题报告
- Codeforces Round #241 (Div. 2) 解题报告
- Codeforces Round #262 (Div. 2)解题报告
- Codeforces Round #267 (Div. 2) 解题报告
- 一些工具的安装(git,clapack)
- 《ios零基础教程》--scanf函数、基本运算
- Codeforces Round #136 (Div. 2) A. Little Elephant and Function
- PostgreSQL 保留关键字添加方法之一,不带参数的函数
- RED HAT 系统使用yum网络源
- Codeforces Round #237 (Div. 2)B. Marathon解题报告
- 移动4G的前景不容乐观
- GridPanel之DataView使用
- JSON数据格式
- Android中定时器的3种实现方法
- 在jsp页面上几种取action传入值得几种方法
- ASA5520远程配置 telnet,ssh
- 今天开始写博客了,好的开始!
- HTML中的特殊符号