Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求测试数据,thanks写了个代码,WA 求测试数据 代码如下: #include<iostream> using namespace std; struct village { long long pri; long long dis; long long profit;//per kilo int index;//存储village所能得到的利润的排名 }; struct pig { long long weight; int num; }; struct village V[1002]; struct pig P[1002]; void sortpigs(int n)//重的排在前面 { int i,j; struct pig temp; for(i=1;i<n;i++) { for(j=i+1;j<=n;j++) { if(P[i].weight<=P[j].weight) { temp=P[i]; P[i]=P[j]; P[j]=temp; } } } return ; } void sortvillage(int n) { long long max=0; long long pre; int i,j; for(i=1;i<=n;i++)//获得最大利润的值 { if(max<V[i].profit) max=V[i].profit; } for(i=1;i<=n;i++) { pre=max; max=0; for(j=1;j<=n;j++) { if(V[j].profit<pre) { V[j].index=V[j].index+1; if(max<V[j].profit) max=V[j].profit; } } } return ; } int main() { int n,i; long long t; cin>>n>>t; for(i=1;i<=n;i++) { cin>>P[i].weight; P[i].num=i; } for(i=1;i<=n;i++) { cin>>V[i].dis; } for(i=1;i<=n;i++) { cin>>V[i].pri; V[i].profit=V[i].pri-t*V[i].dis;//profit per kilo meat V[i].index=1; } sortpigs(n);//按照猪的重量排序 sortvillage(n); //根据profit给出每头猪所占的体重的大小顺序存于index中 cout<<P[V[1].index].num; for(i=2;i<=n;i++) { cout<<" "<<P[V[i].index].num; } cout<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator