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;
}