【贪心】10.24assassin


题目分析

没有题目分析……

寄存一下神奇反悔贪心

 1 #include<bits/stdc++.h>
 2 const int maxn = 100035;
 3
 4 struct node
 5 {
 6     int a,b;
 7     node(int x=0, int y=0):a(x),b(y) {}
 8     bool operator < (node x) const
 9     {
10         return a < x.a;
11     }
12 }a[maxn],b[maxn];
13 int T,n,m,mn,tot;
14 int mx,ans,cnt1,cnt2;
15
16 int read()
17 {
18     char ch = getchar();
19     int num = 0;
20     bool fl = 0;
21     for (; !isdigit(ch); ch=getchar())
22         if (ch==‘-‘) fl = 1;
23     for (; isdigit(ch); ch=getchar())
24         num = (num<<1)+(num<<3)+ch-48;
25     if (fl) num = -num;
26     return num;
27 }
28 int main()
29 {
30     freopen("assassin.in","r",stdin);
31     freopen("assassin.out","w",stdout);
32     T = read();
33     while (T--)
34     {
35         n = read(), m = read();
36         cnt1 = cnt2 = mx = ans = tot = 0, mn = m+1;
37         for (int i=1; i<=n; i++)
38         {
39             int x = read(), y = read();
40             if (y) a[++cnt1] = node(x, y), mn = std::min(mn, x), tot += y;
41             else b[++cnt2] = node(x, y);
42         }
43         std::sort(a+1, a+cnt1+1);
44         std::sort(b+1, b+cnt2+1);
45         if (m >= mn){
46             mx = tot+1, ans = mn;
47             if (mx >= n){
48                 printf("%d %d\n",n,mn);
49                 continue;
50             }
51             cnt2 -= mx-cnt1;
52             for (int i=2; i<=cnt1; i++) b[++cnt2] = a[i];
53             std::sort(b+1, b+cnt2+1);
54             for (int i=1; i<=cnt2&&mx<n; i++)
55                 if (ans+b[i].a <= m) mx++, ans += b[i].a;
56                 else break;
57             printf("%d %d\n",mx,ans);
58         }else{
59             mx = 0;
60             for (int i=1; i<=cnt2; i++)
61                 if (b[i].a <= m) m -= b[i].a, mx++, ans += b[i].a;
62             printf("%d %d\n",mx,ans);
63         }
64     }
65     return 0;
66 }

END

原文地址:https://www.cnblogs.com/antiquality/p/9845230.html

时间: 2024-08-30 02:07:33

【贪心】10.24assassin的相关文章

友链 &amp; 标签

友链 NiveusNix(去膜拜TA) M_sea(去膜拜TA) M_Fish(去膜拜TA) Ivystorm(去膜拜TA) Qihoo360(去膜拜TA) ZYJ(去膜拜TA) XYF(去膜拜TA) smy(去膜拜TA) returdex(去膜拜TA) CZang-SaMa(去膜拜TA) hhxxttxs_(去膜拜TA) ZCDHJ(去膜拜TA) 标签球 Codeforces (10) 其他算法 (10) 数据结构 (10) 最小生成树 (10) 游记 (10) 网络流 (10) 总结 (10

944. 删列造序

944. 删列造序 描述: 给定由 N 个小写字母字符串组成的数组 A,其中每个字符串长度相等. 删除 操作的定义是:选出一组要删掉的列,删去 A 中对应列中的所有字符,形式上,第 n 列为 [A[0][n], A[1][n], ..., A[A.length-1][n]]). 比如,有 A = ["abcdef", "uvwxyz"], 要删掉的列为 {0, 2, 3},删除后 A 为["bef", "vyz"], A 的列

百度粉红色风科技上来看积分

http://www.ebay.com/cln/508gua_gvqjq/-/167266747010/2015.02.10 http://www.ebay.com/cln/jhu2290/-/167423283013/2015.02.10 http://www.ebay.com/cln/cha.m22/-/167166250017/2015.02.10 http://www.ebay.com/cln/fenyu56/-/167382503016/2015.02.10 http://www.eb

百度附件是分开就爱死了开发了

http://www.ebay.com/cln/m_m3154/-/167249028014/2015.02.10 http://www.ebay.com/cln/zhsu412/-/167238372018/2015.02.10 http://www.ebay.com/cln/mi.han5/-/167545028015/2015.02.10 http://www.ebay.com/cln/lij5252/-/167389481016/2015.02.10 http://www.ebay.co

hdu5802 Windows 10 贪心

Windows 10 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2096    Accepted Submission(s): 630 Problem Description Long long ago, there was an old monk living on the top of a mountain. Recently,

2017多校第10场 HDU 6178 Monkeys 贪心,或者DP

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6178 题意:给出一棵有n个节点的树,现在需要你把k只猴子放在节点上,每个节点最多放一只猴子,且要求每只猴子必有一只另外的猴子通过一条边与它相连,问最少用多少条边能达到这个要求. 解法:利用贪心的思维,显然我们应该先选择性价比最高的,即一条边连接两个点的情况.计算出这样的边的条数ans,如果ans*2>=k,结果就是(k+1)/2,否则剩下来没有安排的猴子每一只需要多一条边,即结果为ans+k-2 *

hdu 5802 Windows 10(2016 Multi-University Training Contest 6——贪心+dfs)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5802 Windows 10 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1005    Accepted Submission(s): 333 Problem Description Long long ago, there was a

hdu-5802 Windows 10(贪心)

题目链接: Windows 10 Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Problem Description Long long ago, there was an old monk living on the top of a mountain. Recently, our old monk found the operating system of his c

[ 10.03 ]CF每日一题系列—— 534B贪心

Descripe: 贪心,贪在哪里呢-- 给你初始速度,结尾速度,行驶秒数,每秒速度可变化的范围,问你行驶秒数内最远可以行驶多少距离 Solution: 贪心,我是否加速,就是看剩下的时间能不能减到原始给定的结尾速度 #include <iostream> using namespace std; int main() { int v1,v2; int t,d; while(cin>>v1>>v2) { cin>>t>>d; int ret =