以下是引用C_printf在2014-1-10 09:41:04的发言:
我每天还在被老板压着赶进度呢。就冲这1000分,速度来个网址。我先贴代码!!!
我每天还在被老板压着赶进度呢。就冲这1000分,速度来个网址。我先贴代码!!!
贴啊。
→ →。让楼主去提交然后贴出提交记录就是了。
#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); 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 _tmain(int argc, _TCHAR* argv[]) { int d[] = {9,5,2,5,5,1}; int t[] = {8,7,1,3,3,3}; int tl = 15; getchar(); printf("%d",sizeof(d)/sizeof(int)-s(d,t,sizeof(d)/sizeof(int),tl)); getchar(); return 0; }
#include <vector> #include<cstdio> #include<algorithm> 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); 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",sizeof(d)/sizeof(int)-s(d,t,sizeof(d)/sizeof(int),tl)); return 0; } }
#include<cstdio> #include<algorithm> #include<cstring> #include<iostream> using namespace std; struct lx { int a,b; } l[20]; int t,n,ans; bool vis[20]; void dfs(int k,int s,int deep) { if(deep>ans)ans=deep; int i,j; for(j=0; j<n; j++) { if(k==-1)i=j; else i=k; if(!vis[j]) { if(l[i].b==l[j].b) { if(s+l[i].a<=t) { vis[j]=1; dfs(i,s+l[i].a,deep+1); vis[j]=0; } } else { int tmp=abs(l[i].b-l[j].b); if(s+tmp+l[j].a<=t) { vis[j]=1; dfs(j,s+tmp+l[j].a,deep+1); vis[j]=0; } } } } } int main() { while(cin>>n) { int i; ans=0; for(i=0; i<n; i++) cin>>l[i].a; for(i=0; i<n; i++) cin>>l[i].b; cin>>t; ans=0; dfs(-1,0,0); cout<<ans<<endl; } }