Buffcraft——ACM ICPC 2014–2015, NEERC, Northern Subregional Contest-B(模拟)

Input file: buffcraft.in

Output file: buffcraft.out

Time limit: 2 seconds

Memory limit: 256 megabytes

 Brenda enjoys a new role-playing game Buffcraft. Shields, swords, books and other carry-on items do not affects character stats in Buffcraft. The only way to increase the stats of your character is to buff her.Brenda enjoys a new role-playing game Buffcraft. Shields, swords, books and other carry-on items do not affects character stats in Buffcraft. The only way to increase the stats of your character is to buff her.

 There are two types of buffs in Buffcraft. Direct buffs increase a base value of the stat, while percentage buffs increase stats by the fraction of the base value. To be precise, if unbuffed base value of your character stat is b, you have buffed her using n direct buffs of strength d1, d2, ...dn and m percentage buffs of strength p1, p2, ..., pm, the resulting stat will be equal to (b + d1 + d2 + · · · + dn)(100 + p1 + p2 + · · · + pm)/100. Note that the resulting stat may be fractional.

 Unfortunately, your character has only k buff slots and if you apply more than k buffs on her, only the last k buffs remains active. Thus, there is no reason to apply more than k buffs simultaneously. You cannot apply the same buff more than once.

 Brenda is going to send his character to raid and wants to buff her health to maximal possible value. She has some direct and some percentage buffs at her disposal and needs your help to select the set of buffs that leads to maximal possible total health.

Input

 The first line of the input file contains four integers b, k, cd and cp — the base health of the character, the number of buff slots, the number of available directs buffs, and the number of available percentage buffs.

 The following line contains cd integers di — strengths of direct buffs.

 The last line of the input file contains cp integer numbers pi — strengths of percentage buffs.

 All numbers in the input file are greater than or equal to zero, and less than or equal to fifty thousand.

Output

 The first line of the output file must contain two integers n and m — the number of direct and percentage buffs to use (0 ≤ n ≤ cd; 0 ≤ m ≤ cp; 0 ≤ n + m ≤ k).

 The following line must contain n different numbers — indices of direct buffs to apply (buffs are numbered from one).

 The last line of the output must contain m different numbers — indices of percentage buffs to apply (also numbered from one).

 The resulting total health after application of all n + m buffs must be maximal possible.

Examples

buffcraft.in

70 3 2 2

40 30

50 40

buffcraft.out

2 1

2 1

1

buffcraft.in

1 2 3 4

6 6 5

8 10 7 9

buffcraft.out

2 0

1 2

这道题还是比较有含金量的,WA过,RE过,总有bug想害朕

题意and思路:

第一行输入s, tot, n, m;初始数字s,tot最多能操作的此数,

两种操作,第一种操作直接往上加,第二种操作加上当前数字乘百分之操作数,看不懂的题目加粗字体是公式。

第二行n个数,都为第一种操作

第三行m个数,都为第二种操作

问怎么操作能让这个公式最大,

其实可以把公式第一个括号看做sum1,第二个括号看做sum2,

目的转化成怎么从第二和第三行里挑出部分操作让sum1*sum2最大

很自然的想到先对两种操作分别排序,

然后我们尽可能的让所有操作都是第一种,渐渐的向第二种操作靠拢,常规应该先递增后递减,开始递减的时候我们就可以得到答案了,如图:

思路就是这样啦

接下来看代码吧:

  1 #include <bits/stdc++.h>
  2 typedef long long ll;
  3 using namespace std;
  4 #define int ll
  5 struct node
  6 {
  7     long long data, num;
  8 }str1[100005], str2[100005], q1[100005], q2[100005];
  9
 10 int cmp(struct node a, struct node b)
 11 {
 12     return a.data > b.data;
 13 }
 14 signed main()
 15 {
 16     freopen("buffcraft.in", "r", stdin);
 17     freopen("buffcraft.out", "w", stdout);
 18     ll n, m, i, j, maxx, sum1, sum2, top1, top2, rem;
 19     ll tot, s, x;
 20     scanf("%lld %lld %lld %lld", &s, &tot, &n, &m);
 21     for(i=0; i<n; i++)
 22     {
 23         scanf("%lld", &str1[i].data);
 24         str1[i].num = i + 1;
 25     }
 26     for(i=0; i<m; i++)
 27     {
 28         scanf("%lld", &str2[i].data);
 29         str2[i].num = i + 1;
 30     }
 31     if(tot>=n+m)
 32     {
 33         printf("%lld %lld\n", n, m);
 34         for(i=0; i<n; i++)
 35         {
 36             if(i==n-1) printf("%lld\n", i+1);
 37             else printf("%lld ", i+1);
 38         }
 39         for(i=0; i<m; i++)
 40         {
 41             if(i==m-1) printf("%lld\n", i+1);
 42             else printf("%lld ", i+1);
 43         }
 44     }
 45     else if(tot==0) printf("0 0\n");
 46     else
 47     {
 48         sort(str1, str1+n, cmp);
 49         sort(str2, str2+m, cmp);
 50         top1 = 0;
 51         sum1 = s;
 52         for(i=0; i<n&&i<tot; i++)
 53         {
 54             sum1 += str1[i].data;
 55             q1[top1++] = str1[i];
 56         }
 57         rem = q1[top1-1].num;
 58         top2 = 0;
 59         sum2 = 100;
 60         for(j=0; i<tot; i++,j++)
 61         {
 62             sum2 += str2[j].data;
 63             q2[top2++] = str2[j];
 64         }
 65
 66         maxx = sum1 * sum2;
 67         x = -1;
 68
 69         while(maxx > x)
 70         {
 71             x = maxx;
 72             rem = q1[top1-1].num;
 73             sum1 -= q1[top1-1].data;
 74             top1--;
 75
 76             q2[top2++] = str2[j++];
 77             sum2 += q2[top2-1].data;
 78             maxx = sum1 * sum2;
 79             if(top1==0||j>=m) break;
 80         }
 81
 82         if(maxx < x)
 83         {
 84             q1[top1++].num = rem;
 85             top2--;
 86         }
 87
 88         printf("%lld %lld\n", top1, top2);
 89
 90         for(i=0; i<top1; i++)
 91         {
 92             if(i==top1-1) printf("%lld\n", q1[i].num);
 93             else printf("%lld ", q1[i].num);
 94         }
 95         for(i=0; i<top2; i++)
 96         {
 97             if(i==top2-1) printf("%lld\n", q2[i].num);
 98             else printf("%lld ", q2[i].num);
 99         }
100     }
101     return 0;
102 }

WA是因为边界条件没有判断完整,就不多说了

RE就比较扎心了,一般不怎么用C++,这道题写的sort让我RE到第二十四个样例

原因是我写的cmp是这个样子的:

1 int cmp(struct node a, struct node b)
2 {
3     return a.data >= b.data;
4 }

多了个等于号,第一次出现这样的错误,很是新奇

原文地址:https://www.cnblogs.com/0xiaoyu/p/11354297.html

时间: 2024-10-12 16:21:43

Buffcraft——ACM ICPC 2014–2015, NEERC, Northern Subregional Contest-B(模拟)的相关文章

ACM ICPC 2011–2012, NEERC, Northern Subregional Contest J. John’s Inversions(合并排序求逆序数对数)

题目链接:http://codeforces.com/gym/100609/attachments 题目大意:有n张牌,每张牌有红色和蓝色两面,两面分别写了一些数字,同种颜色的任意两个数字若排在前面的数字比排在后面的数字大就叫做一对逆序数.求怎样排序得到的逆序数对最少. 解题思路:其中一种颜色的数字是顺序且这种颜色数字相同时对应的另一种颜色的数字是顺序时得到的逆序数对数最少.难点在于求逆序数对数.因为数量很大O(n^2)复杂度不能满足,这里根据合并排序的原理求解每个数字前面有多少个比它大的数字,

2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest D:Distribution in Metagonia(构造)

http://codeforces.com/gym/100801/attachments 题意:给出一个数n(1 <= n <= 1e18),将 n 拆成 m 个整数,其中 m 必须是 2^x * 3^y 的形式,并且 x 和 y 不能被彼此整除, 输出 m 并将这些整数输出. 思路:Inspired by http://blog.csdn.net/snowy_smile/article/details/49852091 . 第一步:因为要求的 m 是 2^x * 3^y 的形式,所以如果 n

2016 NEERC, Northern Subregional Contest G.Gangsters in Central City(LCA)

G.Gangsters in Central City 题意:一棵树,节点1为根,是水源.水顺着边流至叶子.该树的每个叶子上有房子.有q个询问,一种为房子u被强盗入侵,另一种为强盗撤离房子u.对于每个询问,要求给出最小的阀门数来阻断水流向强盗所在房子,且在阀门数最小的情况下求最小的误伤房子数(即没被入侵却被断水的房子). 思路:观察可发现,与根相连的子树都是独立的,因此有每有一颗这样的子树里有强盗,则ans1++,每有一颗这样的子树强盗全部撤离则ans1--:因此要维护的是误伤数ans2,我们对

2018-2019 ICPC, NEERC, Southern Subregional Contest

目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Cloud Computing(线段树) D.Garbage Disposal(模拟) E.Getting Deals Done(二分) F.Debate(贪心) H.BerOS File Suggestion(后缀自动机) I.Privatization of Roads in Berland(网络流)

模拟赛小结:2014-2015 ACM-ICPC, NEERC, Southern Subregional Contest

2014-2015 ACM-ICPC, NEERC, Southern Subregional Contest 2019年10月11日 15:30-20:30(Solved 6,Penalty 740) 国庆咸鱼十来天,回来又过了快一个星期,终于和队友约上了模拟赛.(周三拖周四,因为队(fei)友(zhai)们要跑1000米,又拖到周五QAQ) I:00:04.开场翻翻题目,机智如我很快找到一个贪心. D:00:36.看了看现场榜,有人交D.F和M,lh同学已经开F去了,xk同学说他M思路差不多

2013-2014 ACM-ICPC, NEERC, Eastern Subregional Contest PART (7/10)

\[2013-2014\ ACM-ICPC,\ NEERC,\ Eastern\ Subregional\ Contest\] \(A.Podracing\) \(B.The\ battle\ near\ the\ swamp\) 签到 //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<bits/stdc++.h> using namespace std; function<void(

ACM ICPC 2008–2009 NEERC MSC A, B, C, G, L

这套题是我上周日, 就是前天打得一场组队赛, 题目不太好找 题目链接:http://codeforces.com/gym/100861 在virtual judge 上也可以提交哦! A ACM ICPC Rules: 题目大意: 有很多所高校参加预选赛, 并在预选赛取得了排名, 但是对于每所学校, 除了MSU有4个名额之外其他大学只有两个名额( 也就是说, 只有每个大学的前2名进决赛(MSU前四名)&& 最多有10个队伍进入决赛), 高中队伍不能进入决赛. 给出预选赛的排名, 输出可以进

2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Partial Solution

从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Garbage Disposal Problem E Getting Deals Done Problem F Debate Problem G Monsters and Potions Problem H BerOS File Suggestion Problem I Privatization of

2010–2011, NEERC, Northern Subregional C.Commuting Functions

C.Commuting Functions 由于要求答案字典序最小,我们肯定希望从g(1)开始对函数g进行赋值,于是又公式f(g(x))=g(f(x)) 设f(x)=i 我们推导出 由于f是双射,当i逐个遍历1到n时 x也逐个遍历1到n 根据右边的公式,我们可以看出 当g的下标进行f-变换后 对应值也要进行f-变换 回到f的value list 显然对于任意 f(a)=b 进行若干次f变换后 必有f(c)=a 也就是说 f的value list 是由若干个环组成的 每个环上都有唯一最小值, 且小