CSU-ACM2017暑假集训比赛1 TD POJ3111
2017-07-27 21:10
423 查看
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxl 100010
#define inf 2000000001
#define eps 1e-7
using namespace std;
int n,k;
double ans;
double v[maxl],w[maxl];
struct node{double num;int pos;} a[maxl];
void prework()
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
scanf("%lf%lf",&v[i],&w[i]);
}
bool cmp(const node &x,const node &y)
{
return x.num>y.num;
}
bool jug(double x)
{
for(int i=1;i<=n;i++)
a[i].num=v[i]-w[i]*x,a[i].pos=i;
sort(a+1,a+1+n,cmp);
double sum=0;
for(int i=1;i<=k;i++)
sum+=a[i].num;
if(sum>eps)
return true;
else
return false;
}
void mainwork()
{
double l=eps,r=inf-eps,mid;
while(l+eps<r)
{
mid=(l+r)/2.0;
if(jug(mid))
l=mid;
else
r=mid;
}
ans=l;
}
void print()
{
jug(ans);
for(int i=1;i<=k;i++)
printf("%d ",a[i].pos);
}
int main()
{
prework();
mainwork();
print();
return 0;
}
Demy has n jewels. Each of her jewels has some value vi and weight wi.
Since her husband John got broke after recent financial crises, Demy has decided to sell some jewels. She has decided that she would keep k best jewels for herself. She decided to keep such
jewels that their specific value is as large as possible. That is, denote the specific value of some set of jewels S = {i1, i2, …, ik} as
![](https://odzkskevi.qnssl.com/0389497dbaae925e36b0db87a8ec2f48?v=1500951832)
.
Demy would like to select such k jewels that their specific value is maximal possible. Help her to do so.
选出能使上式最大的k个珠子、
选出vi/wi最大的珠子无法满足vi之和/wi之和最大。于是我们二分这个最大值为x
然后 求一组(vi+vj....)/(wi+wj..)=x,移项得 (vi+vj...)-(wi+wj..)*x=0,而我们要求最大的x,所以只要(vi+vj...)-(wi+wj..)*x >= 0,这个x就是满足的。
#include<cstring>
#include<algorithm>
#define maxl 100010
#define inf 2000000001
#define eps 1e-7
using namespace std;
int n,k;
double ans;
double v[maxl],w[maxl];
struct node{double num;int pos;} a[maxl];
void prework()
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
scanf("%lf%lf",&v[i],&w[i]);
}
bool cmp(const node &x,const node &y)
{
return x.num>y.num;
}
bool jug(double x)
{
for(int i=1;i<=n;i++)
a[i].num=v[i]-w[i]*x,a[i].pos=i;
sort(a+1,a+1+n,cmp);
double sum=0;
for(int i=1;i<=k;i++)
sum+=a[i].num;
if(sum>eps)
return true;
else
return false;
}
void mainwork()
{
double l=eps,r=inf-eps,mid;
while(l+eps<r)
{
mid=(l+r)/2.0;
if(jug(mid))
l=mid;
else
r=mid;
}
ans=l;
}
void print()
{
jug(ans);
for(int i=1;i<=k;i++)
printf("%d ",a[i].pos);
}
int main()
{
prework();
mainwork();
print();
return 0;
}
Demy has n jewels. Each of her jewels has some value vi and weight wi.
Since her husband John got broke after recent financial crises, Demy has decided to sell some jewels. She has decided that she would keep k best jewels for herself. She decided to keep such
jewels that their specific value is as large as possible. That is, denote the specific value of some set of jewels S = {i1, i2, …, ik} as
.
Demy would like to select such k jewels that their specific value is maximal possible. Help her to do so.
选出能使上式最大的k个珠子、
选出vi/wi最大的珠子无法满足vi之和/wi之和最大。于是我们二分这个最大值为x
然后 求一组(vi+vj....)/(wi+wj..)=x,移项得 (vi+vj...)-(wi+wj..)*x=0,而我们要求最大的x,所以只要(vi+vj...)-(wi+wj..)*x >= 0,这个x就是满足的。
相关文章推荐
- CSU-ACM2017暑假集训比赛8 - A - Xor Sum - HDU - 4825
- CSU-ACM2017暑假集训比赛2 E - ( ̄▽ ̄)/
- CSU-ACM2017暑假集训比赛2 CodeForces - 724D
- CSU-ACM2017暑假集训比赛8 - B - The Two Routes - CodeForces - 601A
- CSU-ACM2017暑假集训比赛1 B - R2D2 and Droid Army
- CSU-ACM2017暑假集训比赛7 A - Equivalent Strings - CodeForces - 560D
- CSU-ACM2017暑假集训比赛2 C - (╯°口°)╯(┴—┴
- CSU-ACM2017暑假集训比赛8 - C - GCD Table - CodeForces - 582A
- CSU-ACM2017暑假集训比赛1 A - I Can Guess the Data Structure! -uva111995
- CSU-ACM2017暑假集训比赛2 HDU - 1597 find the nth digit
- CSU-ACM2017暑假集训比赛7 C - Pasha and Tea - CodeForces - 557B
- CSU-ACM2017暑假集训比赛2 D - ^(●゚∀゚○)ノ
- CSU-ACM2017暑假集训比赛1 C - Gourmet and Banquet CodeForces - 589F
- CSU-ACM2017暑假集训比赛1 C - Gourmet and Banquet
- CSU-ACM2017暑假集训比赛7 - D - Bicoloring - UVA - 10004
- CSU-ACM2017暑假集训比赛2 B - : )
- CSU-ACM2017暑假集训比赛3D - D CodeForces - 557C
- CSU-ACM2017暑假集训比赛7 - E - Courses - HDU - 1083
- CSU-ACM2017暑假集训比赛2 A - _(:з」∠)_
- CSU-ACM2017暑假集训比赛8 - E - Escape - HDU - 3605