zoukankan      html  css  js  c++  java
  • 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, m);
     34         for(i=0; i<n; i++)
     35         {
     36             if(i==n-1) printf("%lld
    ", i+1);
     37             else printf("%lld ", i+1);
     38         }
     39         for(i=0; i<m; i++)
     40         {
     41             if(i==m-1) printf("%lld
    ", i+1);
     42             else printf("%lld ", i+1);
     43         }
     44     }
     45     else if(tot==0) printf("0 0
    ");
     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
    ", top1, top2);
     89 
     90         for(i=0; i<top1; i++)
     91         {
     92             if(i==top1-1) printf("%lld
    ", 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
    ", 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 }

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

  • 相关阅读:
    SupoSE 概述 Redmine
    tmux guake
    How to Install and Use Krugle Basic
    use webdevelop tools to delete domain specific cookies for ecommerical cps union effect
    执行hudson daemon的脚本
    python技巧26[python的egg包的安装和制作]
    HOWTO Modular Xorg
    ARC专题:再续 Xcode 4.2 中的Automatic Reference Counting (ARC)
    ARC专题:在Xcode 4.2中加入不支持ARC的源码
    Windows下的.NET+ Memcached安装
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/11354297.html
Copyright © 2011-2022 走看看