Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:有没有迭代做的啊?

Posted by TAdashi at 2018-01-19 10:17:50 on Problem 2976
In Reply To:有没有迭代做的啊? Posted by:TAdashi at 2018-01-19 10:08:26
> 有没有迭代做的啊?
自己搞了哈,没想到对了~~~
#include"iostream"
#include"algorithm"
#include"cstdio"
using namespace std;
const int maxn=1e3+5;
int a[maxn],b[maxn];
double c[maxn];
struct AAA
{
	double a,b,c;
};
AAA arr[maxn];
bool cmp(AAA a,AAA b)
{
	return a.c<b.c;
}
const double eps=1e-6;
int main()
{
	int N,K;
	while(cin>>N>>K&&(N+K))
	{
		for(int i=0;i<N;i++)cin>>arr[i].a;
		for(int i=0;i<N;i++)cin>>arr[i].b;
		double L=-1,R=0;
		while(R-L>eps)
		{
			L=R;
			for(int i=0;i<N;i++)arr[i].c=arr[i].a-L*arr[i].b;
			sort(arr,arr+N,cmp);
			double ax=0,bx=0;
			for(int i=K;i<N;i++)
			{
				ax+=arr[i].a;
				bx+=arr[i].b;
			}
			R=ax/bx*1.0;
//			cout<<"R="<<R<<"\n"; 
		}
		printf("%.0f\n",L*100);
	}
	
	
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator