hdu-4355

 4355 3/33 

扯淡的4355啊……交了33次…………为什么把函数改成内联函数inline就ac了呢???

orz inline内联函数啊~~~

我的三分:需要用gcc交才能ac。。。具体为什么可以用三分,我也不太清楚。

/*
收获:
*/
#include<iostream>
#include<cstdlib>
#include<vector>
#include<map>
#include<cstring>
#include<set>
#include<string>
#include<algorithm>
#include<sstream>
#include<ctype.h>
#include<fstream>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<stack>
#include<queue>
#include<ctime>
//#include<conio.h>
using namespace std;

const int INF_MAX=0x7FFFFFFF;
const int INF_MIN=-(1<<31);

const double eps=1e-1;
const double pi=acos(-1.0);

#define pb push_back   //a.pb( )
#define chmin(a,b) ((a)<(b)?(a):(b))
#define chmax(a,b) ((a)>(b)?(a):(b))


template<class T> inline T gcd(T a,T b)//NOTES:gcd(
  {if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<class T> inline T lcm(T a,T b)//NOTES:lcm(
  {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}


typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;
int dir_4[4][2]={{0,1},{-1,0},{0,-1},{1,0}};
int dir_8[8][2]={{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1},{1,0},{1,1}};
//下,左下,左,左上,上,右上,右,右下。

//******* WATER ****************************************************************

LL num;

struct node {
    double x;
    double w;
};

node a[50100];

inline double poww(double x) {
    return x * x * x;
}

inline double cal_one(double x, int j) {
    return poww(fabs(x - a[j].x)) * a[j].w;
}


inline double cal(double x) {
    double ret = 0;
    for(int i = 0; i < num; i++) {
        //cout << "here" << endl;
        ret += cal_one(x, i);
        //cout << "*   " << cal_one(x, i) << endl;
    }
    return ret;
}

inline double three_divide(double l, double r) {
    //while( fabs(l - r) > eps) {
    for(int i = 0; i < 100; i++) {
        double mid_l = l / 3 * 2 + r / 3;
        double mid_r = l / 3 + r / 3 * 2;
        if(cal(mid_l) < cal(mid_r)) r = mid_r;
        else l = mid_l;
        //cout << "*****   " << l << " " << r << endl;
    }
    //cout << "* " << cal(l) << endl;
    return cal(l);
}


int main() {
    LL T;
    double min_x, max_x;
    double ans = 0;
    scanf("%I64d",&T);
    for(LL cas = 1; cas <= T; cas++) {
        min_x = 1000100.0;
        max_x = -1000100.0;
        scanf("%I64d", &num);
        for(int i = 0; i < num; i++) {
            scanf("%lf%lf", &a[i].x, &a[i].w);
            min_x = chmin(a[i].x, min_x);
            max_x = chmax(a[i].x, max_x);
        }
        //cout << "*********  " << min_x << " " << max_x << endl;
        ans = three_divide(min_x, max_x);
        //cout << "&&& " << ans << endl;
        //printf("Case #%d: %lf\n", cas, (ans ));
        printf("Case #%I64d: %I64d\n", cas, (LL)(ans + 0.5));
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值