HDU 4493 Tutor (控制精度)

题意:给定12个数,求平均数。

析:这个题就是精度控制问题,如果控制精度,最好的办法就是用整型了。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 2e5 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n, m;
inline bool is_in(int r, int c){
    return r >= 0 && r < n && c >= 0 && c < m;
}
int a[maxn];

int main(){
    int T;  cin >> T;
    while(T--){
        double sum = 0;
        double x;
        for(int i = 0; i < 12; ++i){
            cin >> x;
            sum += x;
        }
        int ans = (int)round(sum * 100.0/12.0);
        printf("$");
        printf("%d", ans/100);
        int y = ans % 100;
        if(!y);
        else{
            printf(".%d", y /10);
            y = y % 10;
            if(!y) ;
            else  printf("%d", y %10);
        }
        printf("\n");
    }
    return 0;
}
时间: 2024-10-12 02:28:26

HDU 4493 Tutor (控制精度)的相关文章

hdu 4493 Tutor(简单处理题)

http://acm.hdu.edu.cn/showproblem.php?pid=4493 题意是输入12个数据,让你求平均值,但是要去除尾零,就像100.00只要输出100 其实这题有点不严密,像这组数据 2 100.995 100.995 100.995 100.995 100.995 100.995 100.995 100.995 100.995 100.995 100.995 100.995 输出100,其他可以过的输出100.10以及101都可以 用自己的方法死活不可以过,上网搜了一

hdu 4493 Tutor

Tutor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 1981    Accepted Submission(s): 552 Problem Description Lilin was a student of Tonghua Normal University. She is studying at University of

HDU 4493 Tutor(精度处理)

题目 #include<stdio.h> int main() { int t; double a,s; scanf("%d",&t); while(t--) { s=0; for(int i=0;i<12;i++) { scanf("%lf",&a); s+=a; } //1.注意案例的输出格式 //2.rounded to the nearest penny int ss=s/12.0+0.005; printf("$

HDU 4493 Tutor(数学啊 )

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4493 Problem Description Lilin was a student of Tonghua Normal University. She is studying at University of Chicago now. Besides studying, she worked as a tutor teaching Chinese to Americans. So, she can

hdu 4493 Tutor 水题

Tutor Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4493 Description Lilin was a student of Tonghua Normal University. She is studying at University of Chicago now. Besides studying, she worked as a tutor tea

hdu 4493 Tutor (水 精度)

题意: 思路: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int fa[150]; int fin(int x) { return fa[x]==x?x:fin(fa[x]); } void unionn(int x,int y) { int fx=fin(x); int fy=fin(y); if(fx

Hdu 4493

题目链接 注意四舍五入,保留到小数点后两位(如果存在的话). 附上代码: 1 /************************************************************************* 2 > File Name: 4493.cpp 3 > Author: Stomach_ache 4 > Mail: [email protected] 5 > Created Time: 2014年05月19日 星期一 22时39分19秒 6 > P

poj 1064 (二分+控制精度) &amp;&amp; hdu 1551

链接:http://poj.org/problem?id=1064 Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23896   Accepted: 5118 Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Committee ha

hdu 4923 Room and Moor (单调栈+思维)

题意: 给一个0和1组成的序列a,要构造一个同样长度的序列b.b要满足非严格单调,且 值为0到1的实数.最后使得  sum((ai-bi)^2)最小. 算法: 首先a序列开始的连续0和末尾的连续1是可以不考虑的.因为只要b序列对应开头为0. 末尾为1,既不影响单调性又能使对应的(ai-bi)^2=0. 然后, 先找111100.11100.10这样以1开始以0结束的序列块.每一块对应的b值相等且均为 这一块的平均值,即1的个数/0和1的总个数. 但是要满足b的单调性,则我们用栈来维护,如果后面一