# hdu 4128 Running relay ——2011ACM福州赛区H题

step 1：排序，状态好的情况的速度记为 x，状态差的速度记为 y，以x为主y为辅排序；

step 2：删点，若某个 yi<yj ，则删去 j 这个点；

step 3: 让每个人都先跑 d 的距离；

step 4：贪心，让x最小的点先跑完全程，然后所得到的 s 如果小于w则这种结果是最优的，若大于w则 goto step 5；

step 5：算 ex/ey ，和这个x最小的点交换，看len*y[?]是否小于 w，小于的话则可以计算出结果，否则 goto step 4；

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
using namespace std;

#ifdef _WIN32
#define i64 __int64
#define out64 "%I64d\n"
#define in64 "%I64d"
#else
#define i64 long long
#define out64 "%lld\n"
#define in64 "%lld"
#endif

#define FOR(i,a,b)      for( int i = (a) ; i <= (b) ; i ++)
#define FF(i,a)         for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a)        for( int i = (a)-1 ; i >= 0 ; i --)
#define S64(a)          scanf(in64,&a)
#define SS(a)           scanf("%d",&a)
#define LL(a)           ((a)<<1)
#define RR(a)           (((a)<<1)+1)
#define SZ(a)           ((int)a.size())
#define PP(n,m,a)       puts("---");FF(i,n){FF(j,m)cout << a[i][j] << ' ';puts("");}
#define pb              push_back
#define CL(Q)           while(!Q.empty())Q.pop()
#define MM(name,what)   memset(name,what,sizeof(name))
#define write           freopen("out1.txt","w",stdout)

const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-10;
const double pi = acos(-1.0);
const int maxn = 11234;
struct zz
{
i64 x;
i64 y;
bool operator < (const zz & cmp) const
{
if(x!=cmp.x)
{
return x<cmp.x;
}
else
{
return y<cmp.y;
}
}
}zx;

int t;
i64 n,d,len,w,mm;
i64 y[maxn];
i64 x[maxn];
vector<zz>vc;
vector<zz>v;
double c[maxn];

double start()
{
double nowx = v[0].x * len;
double nowy = v[0].y * len;
i64 nb = v[0].y *len;
if(nb <= w)
{
return nowx;
}
i64 tx=0;
double have = len;
double temp;
double to;

while(true)
{
int ti;
double tc=oo;
for(int i=tx+1;i<v.size();i++)
{
ex = v[i].x - v[tx].x;
ey = v[tx].y - v[i].y;
c[i] = ex/ey;
if(c[i]<tc)
{
ti = i;
tc = c[i];
}
}
if( (v[ti].y * len) <= w )
{
to = (nowy - w)/double(v[tx].y - v[ti].y) * double(v[ti].x - v[tx].x);
nowx += to;
return nowx;
}
else
{
nowx = len*v[ti].x;
nowy = len*v[ti].y;
tx = ti;
}
continue;
}
}

int main()
{
cin>>t;
while(t--)
{
mm=inf;
v.clear();
vc.clear();
cin>>n>>d>>len>>w;
for(int i=1;i<=n;i++)
{
cin>>y[i]>>x[i];
mm=min(mm,y[i]);
zx.x=x[i];
zx.y=y[i];
vc.push_back(zx);
}
sort(vc.begin(),vc.end());
i64 ty=vc[0].y;

v.push_back(vc[0]);
for(int i=1;i<vc.size();i++)
{
if(vc[i].y >= ty)
{
continue;
}
else
{
ty = vc[i].y;
v.push_back(vc[i]);
}
}
if(n*d > len)
{
cout<<"No solution"<<endl;
continue;
}
i64 temp=0;
FOR(i,1,n)
{
temp += y[i]*d;
}
w -= temp;
if(w < 0)
{
cout<<"No solution"<<endl;
continue;
}
len -= n*d;
if(mm*len > w)
{
cout<<"No solution"<<endl;
continue;
}
}
return 0;
}



• 本文已收录于以下专栏：

举报原因： 您举报文章：hdu 4128 Running relay ——2011ACM福州赛区H题 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)