More than 2019 cattle off summer school camp (seventh) Governing sand


Time limit: C / C ++ 3 seconds to 6 seconds in other languages

Space limitations: C / C ++ 65536K, other languages 131072K
64bit IO the Format:% LLD

Title Description

The Wow village is often hit by wind and sand,the sandstorm seriously hindered the economic development of the Wow village.
There is a forest in front of the Wowo village, this forest can prevent the invasion of wind and sand. But there is a rule that the number of tallest trees in the forest should be more than half of all trees, so that it can prevent the invasion of wind and sand. Cutting down a tree need to cost a certain amount of money. Different kinds of trees cost different amounts of money. Wow village is also poor.
There are n kinds of trees. The number of i-th kind of trees is PiP_iPi, the height of i-th kind of trees is HiH_iHi, the cost of cutting down one i-th kind of trees is CiC_iCi.
(Note: "cutting down a tree" means removing the tree from the forest, you can not cut the tree into another height.)

Enter a description:

The problem is multiple inputs (no more than 30 groups).
For each test case.
The first line contines one positive integers n(1≤n≤10^5),the kinds of trees.
Then followed n lines with each line three integers Hi(1≤Hi≤10^9)-the height of each tree, Ci(1≤Ci≤200)-the cost of cutting down each tree, and Pi(1≤Pi≤10^9)-the number of the tree.

Output Description:

For each test case, you should output the minimum cost.

Entry

2
5 1 1
1 10 1
2
5 1 2
3 2 3

Export

1 
2 

meaning of the questions: per number of trees have P-, H- height, C- cost to get rid of three properties, after seeking to clear some trees, so that the maximum number of trees in the forest should be more than half of all the trees of the minimum cost.

Solution: in accordance with the height of the sorting, enumeration height, greater than the current height of the tree to be fully removed, should be less than the current height of the trees left (the height of the tree of this number -1) tree, the other is removed (small takes priority the tree, in order to minimize the cost of the minimum). The number of orders w [i] cost for the removal of the i-th tree planting after all, sum [i] is the number of all the tree planting before the i, value [i] for the i it takes to clear the trees.

Code:
#include<bits/stdc++.h>
using namespace std;
const int maxn=100005;
struct node
{
  long long p,h,c;
  node(){}
  node(long long a,long long b,long long d)
  {p=a;h=b;c=d;}
  bool operator <(const node&n) const
  { return h<n.h; }
}v[maxn];
long long w[maxn],num[maxn],value[205];
int main()
{
  int i,j,n;
  long long h,c,p,t,cnt,ans,sum;
  while(~scanf("%d",&n))
  {
    ans=0x3f3f3f3f3f3f3f3f; w[n]=num[0]=0;
    fill(value,value+205,0);
    for(i=1;i<=n;i++) 
     {
      scanf("%lld%lld%lld",&h,&c,&p);
      v[i]=node(p,h,c);
     }
    sort(v+1,v+1+n);
    
    for(i=n-1;i>=1;i--) w[i]=w[i+1]+v[i+1].p*v[i+1].c;
    
    for(i=1;i<=n;i++)
    {
      t=i;cnt=v[i].p;
      num[i]=num[i-1]+v[i-1].p;
      while(i+1<n&&v[i].h==v[i+1].h) i++,num[i]=num[i-1]+v[i-1].p,cnt+=v[i].p;
      sum= W [I]; CNT = NUM [T] - (the CNT- . 1 
    });
       IF (CNT < 0 ) CNT = 0 ;
       for (J = . 1 ; J <= 200 is ; J ++ ) 
      { 
        IF ! (Value [J]) Continue ;
         IF (CNT> = value [J]) 
          {CNT - = value [J]; SUM + = J * value [J];}
         the else 
          {SUM + = J * CNT; BREAK ;} 
      } 
     for (J = T; J <= I; J ++) value [V [J] .c] = V + [J] .p; // value [] is always stored number of tree height less than the current cost tree and tree 
     ANS = min (ANS, SUM); 
    the printf ( " % LLD \ n- ",ans);
  }
  system("pause");
  return 0;
}

Guess you like

Origin www.cnblogs.com/VividBinGo/p/11331601.html