首页 新闻 赞助 找找看

HDU 4544 能用mulitset写?麻烦各位大佬看看这样写wa在哪?

0
悬赏园豆:15 [已关闭问题] 关闭于 2017-07-29 22:03
湫湫减肥
  越减越肥!

  最近,减肥失败的湫湫为发泄心中郁闷,在玩一个消灭免子的游戏。
  游戏规则很简单,用箭杀死免子即可。
  箭是一种消耗品,已知有M种不同类型的箭可以选择,并且每种箭都会对兔子造成伤害,对应的伤害值分别为Di(1 <= i <= M),每种箭需要一定的QQ币购买。
  假设每种箭只能使用一次,每只免子也只能被射一次,请计算要消灭地图上的所有兔子最少需要的QQ币。

Input输入数据有多组,每组数据有四行;
第一行有两个整数N,M(1 <= N, M <= 100000),分别表示兔子的个数和箭的种类;
第二行有N个正整数,分别表示兔子的血量Bi(1 <= i <= N);
第三行有M个正整数,表示每把箭所能造成的伤害值Di(1 <= i <= M);
第四行有M个正整数,表示每把箭需要花费的QQ币Pi(1 <= i <= M)。

特别说明:
1、当箭的伤害值大于等于兔子的血量时,就能将兔子杀死;
2、血量Bi,箭的伤害值Di,箭的价格Pi,均小于等于100000。Output如果不能杀死所有兔子,请输出”No”,否则,请输出最少的QQ币数,每组输出一行。Sample Input

3 3
1 2 3
2 3 4
1 2 3
3 4
1 2 3
1 2 3 4
1 2 3 1

Sample Output

6
4

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<algorithm>
 4 #include<set>
 5 #include<string.h>
 6 using namespace std;
 7 struct Node{
 8     int d;
 9     int cost;
10 }a[100050];
11 multiset<int> num;
12 bool cmp(Node a,Node b)
13 {
14     if(a.cost==b.cost)
15         return a.d>b.d;
16     else
17         return a.cost<b.cost;
18 }
19 int main()
20 {
21     int n,m;
22     while(cin>>n>>m)
23     {
24         num.clear();
25         int y;
26         for(int i=0;i<n;i++)
27         {
28             scanf("%d",&y);
29             num.insert(y);
30         }
31         for(int i=0;i<m;i++)
32             scanf("%d",&a[i].d);
33         for(int i=0;i<m;i++)
34             scanf("%d",&a[i].cost);
35         sort(a,a+m,cmp);
36         if(n>m)
37             cout<<"No"<<endl;
38         else
39         {
40             multiset<int>::iterator it,st,last;
41             long long sum=0;
42             for(int i=0;i<m;i++)
43             {
44                 if(num.empty())
45                     break;
46                 int key=a[i].d;
47                 if(key<*num.begin())
48                     continue;
49                 if(key>=*num.end())
50                 {
51                     it=num.end();
52                     num.erase(--it);
53                     sum+=a[i].cost;
54                     continue;
55                 }
56                 it=num.find(key);
57                 if(it!=num.end())
58                 {
59                     num.erase(it);
60                     sum+=a[i].cost;
61                     continue;
62                 }
63                 else
64                 {
65                     st=num.begin();
66                     last=num.end();
67                     it=lower_bound(st,last,key);//二分查找
68                     num.erase(it);
69                     sum+=a[i].cost;
70                 }
71             }
72             if(num.empty())
73                 cout<<sum<<endl;
74             else
75                 cout<<"No"<<endl;
76         }
77     }
78     return 0;
79 }

 



        
ISGuXing的主页 ISGuXing | 菜鸟二级 | 园豆:202
提问于:2017-07-26 16:33
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册