• Codeforces 321B Ciel and Duel


    题意:对方有N张卡牌,每一张卡牌要么是攻击模式要么是防守模式,你有M张卡牌,都是攻击模式 ,每张卡牌都有一个值,你可以进行一下的任意操

    1)如果对方牌都被你消灭了,那么你任选一张没有选过的牌是对方遭受牌值的攻击。

    2)可以选择一张没有选过值为X的牌,攻击对方一张攻击模式值为Y 的牌  对对方造成(X-Y)的伤害并把牌消灭 X必须 大于等于Y

    3)可以选择一张没有选过值为X的牌,攻击对方一张防守模式值为Y 的牌  对对方不造成伤害,把对方牌消灭. X必须大于Y

    解题思路:暴力 + DP?

    解题代码:

      1 /************************************************************
      2  * Author : darkdream
      3  * Email : darkdream1994@gmail.com 
      4  * Last modified : 2015-03-31 11:10
      5  * Filename : 321b.cpp
      6  * Description :
      7  * *********************************************************/
      8 // File Name: 321b.cpp
      9 // Author: darkdream
     10 // Created Time: 2015年03月31日 星期二 09时34分01秒
     11 
     12 #include<vector>
     13 #include<list>
     14 #include<map>
     15 #include<set>
     16 #include<deque>
     17 #include<stack>
     18 #include<bitset>
     19 #include<algorithm>
     20 #include<functional>
     21 #include<numeric>
     22 #include<utility>
     23 #include<sstream>
     24 #include<iostream>
     25 #include<iomanip>
     26 #include<cstdio>
     27 #include<cmath>
     28 #include<cstdlib>
     29 #include<cstring>
     30 #include<ctime>
     31 #define LL long long
     32 
     33 using namespace std;
     34 int n , m; 
     35 int atk[105];
     36 int atkn;
     37 int def[105];
     38 int defn; 
     39 int matk[105];
     40 int tatk[105];
     41 int tatkn;
     42 char str[100];
     43 int mx;
     44 int solve(int k)
     45 {
     46     int ans  = 0 ;
     47     for(int i = 1;i<= k;i ++)
     48     {
     49         if(matk[i] >= atk[k-i+1])
     50         {
     51            ans += matk[i] - atk[k-i+1];
     52         }else{
     53          return -1;
     54         }
     55     }
     56     mx = max(mx,ans);
     57     return ans;
     58 }
     59 int cmp(int a, int b)
     60 {
     61    return a > b; 
     62 }
     63 multiset<int> num;
     64 int main(){
     65     scanf("%d %d",&n,&m);    
     66     int ta; 
     67     for(int i = 1;i <= n;i ++)
     68     {
     69        scanf("%s",str);
     70        scanf("%d",&ta);
     71        
     72        if(str[0] == 'D')
     73        {
     74          defn ++ ; 
     75          def[defn] = ta;               
     76        }
     77        else{
     78          atkn ++ ; 
     79          atk[atkn] = ta; 
     80        }
     81     }
     82     for(int i = 1;i <= m;i ++)
     83     {
     84         scanf("%d",&matk[i]);
     85         num.insert(matk[i]);
     86       // printf("%d %d
    ",m,num.size());
     87     }
     88     sort(atk+1,atk+1+atkn);
     89     sort(matk+1,matk+m+1,cmp);
     90     for(int i = 1;i <= min(atkn,m); i++)
     91     {
     92         solve(i); 
     93     }
     94     if(m > atkn + defn)
     95     {
     96         set<int>::iterator tt;
     97         int ok = 1; 
     98         for(int i = 1;i <= defn; i ++)
     99         {
    100             tt = num.upper_bound(def[i]) ;
    101             if(tt == num.end()) 
    102             {
    103                 ok = 0 ;
    104                 break;
    105             }else{
    106                 num.erase(tt);
    107             }
    108         }
    109         if(ok == 1)
    110         {
    111             m = 0 ;
    112             memset(matk,0,sizeof(matk));
    113             for(tt = num.begin();tt != num.end();tt ++)
    114             {
    115                 m ++ ;
    116                 matk[m] = *tt;
    117             }
    118             sort(matk+1,matk+m+1,cmp);
    119             int hehe = solve(atkn);
    120             if(hehe != -1 )
    121             {
    122                for(int i = atkn+1;i <= m;i ++)
    123                {
    124                   hehe += matk[i];
    125                }
    126                mx = max(hehe,mx);
    127             }
    128         }
    129     }
    130     printf("%d
    ",mx);
    131 return 0;
    132 }
    View Code
    没有梦想,何谈远方
  • 相关阅读:
    数据库设计的几个建议
    CAS单点登录和spring securtiy集成
    冒烟测试
    匠人精神
    iOS UIButton 设置图片文字垂直排列
    PHP字符串处理函数
    php 数组的常用函数
    Linux中常用操作命令
    yii2.0高级框架配置时打开init.bat秒退的解决方法 (两种方法)
    前端优化网站性能的14条规则
  • 原文地址:https://www.cnblogs.com/zyue/p/4381155.html
Copyright © 2020-2023  润新知