好吧 我调试一下,修改了一句,楼主也贴一下我的代码
程序代码:
#include <vector>
using namespace std;
void de(vector<pair<int,int>>& data,int i)
{
int ii = 0;
vector<pair<int,int>>::iterator it = data.begin();
while(data.end()!=it)
{
if(ii++ == i){data.erase(it);break;}
it++;
}
}
int ca(vector<pair<int,int>>& data,int d)
{
unsigned int ret = -1;
int index = 0;
for (int i = 0; i < data.size(); i++)
{
int r = data[i].first + abs(data[i].second - d);
if(r<ret)
{
ret = r;
index = i;
}
}
return index;
}
int ss(vector<pair<int,int>> data,int last,int time)
{
if(data.size()<=0)return 0;
int i = ca(data,last);
int a = data[i].second;
int t = time - data[i].first - abs(data[i].second - last);
if(t<0) return data.size();
de(data,i);
if(t==0) return data.size();
return ss(data,a,t);
}
int s(int* d,int* t,int nums,int time)
{
unsigned int ret = -1;
vector<pair<int,int>> datar;
for (int i = 0; i < nums; i++)
datar.push_back(make_pair(d[i],t[i]));
for (int i = 0; i < nums; i++)
{
vector<pair<int,int>> data = datar;
int pa1 = data[i].second;
int pa2 = time-data[i].first;
de(data,i);
int retss = ss(data,pa1,pa2);
ret = retss<ret?retss:ret;
}
return ret;
}
int main()
{
int d[16];
int t[16];
int tl;
int n;
while(scanf("%d",&n))
{
for(int i=0;i<n;i++)
scanf("%d",&d[i]);
for(int i=0;i<n;i++)
scanf("%d",&t[i]);
scanf("%d",&tl);
printf("%d",n-s(d,t,n,tl));
}
}