计蒜客 . D Fujiyama Thursday



题解:模拟
第二行是汽车到达目的地的时间,第三行包含4*c整数TJ(1≤TJ≤75),表示JTH团队成员完成进食所需的时间(以分钟为单位)。最短距离是汽车所需要的时间和进食速度的两部分之和,最好的搭配就是把汽车时间都从大到小排,进食速度是从小到大,每四个为一组,取两个方案的最大值。
样例解释如下:

代码:
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp1(int a,int b)
{
return a<b;
}
bool cmp2(int a,int b)
{
return a>b;
}
int main ()
{
int d[100],t[300],ans=0,i=0;
int n;
cin>>n;
while (n--)
{
int c;
cin>>c;
for(int j=0;j<c;j++)
{
cin>>d[j];
}
for(int j=0;j<4*c;j++)
{
cin>>t[j];
}
sort (d,d+c,cmp2);
sort(t,t+4*c,cmp1);//sort内部写三个部分,起始位置,结束位置,使用的什么方法排列
int ans=d[0]+t[3];
for(int j=1;j<c;j++)
{
if((d[j]+t[j*4+3])>ans)
ans=d[j]+t[j*4+3];
}
cout<<"Trip #"<<++i<<":"<<ans<<endl;//如果是i++的话,那就是从0开始,++i是从1开始
}
#include <algorithm>
using namespace std;
bool cmp1(int a,int b)
{
return a<b;
}
bool cmp2(int a,int b)
{
return a>b;
}
int main ()
{
int d[100],t[300],ans=0,i=0;
int n;
cin>>n;
while (n--)
{
int c;
cin>>c;
for(int j=0;j<c;j++)
{
cin>>d[j];
}
for(int j=0;j<4*c;j++)
{
cin>>t[j];
}
sort (d,d+c,cmp2);
sort(t,t+4*c,cmp1);//sort内部写三个部分,起始位置,结束位置,使用的什么方法排列
int ans=d[0]+t[3];
for(int j=1;j<c;j++)
{
if((d[j]+t[j*4+3])>ans)
ans=d[j]+t[j*4+3];
}
cout<<"Trip #"<<++i<<":"<<ans<<endl;//如果是i++的话,那就是从0开始,++i是从1开始
}
}
浙公网安备 33010602011771号