CodeCraft-19 and Codeforces Round #537 (Div. 2) A, B, C

CodeCraft-19 and Codeforces Round #537 (Div. 2) A, B, C


A. Superhero Transformation

题目链接
题面:

划掉

题意:

见题面

思路:

将元音字母转换为*,辅音字母转换为+,判断最后两个字符串是否相同即可。

AC代码:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <stack>
#include <bitset>

using namespace std;

#define FSIO  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define DEBUG(a)   cout<<"DEBUG: "<<(a)<<endl;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define MP make_pair
#define X  first
#define Y  second
#define REP(i,st,ed)    for(int i=st;i<=ed;++i)
#define IREP(i,st,ed)   for(int i=st;i>=ed;--i)
#define TCASE(T)    cin>>T;while(T--)

const int MAXN = 200005;
const ll MOD = 1e9+7 ;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 1e9+7;
const double PI = acos(-1.0);
const double EPS = 1e-8;

int _;

using namespace std;



int main()
{
    //freopen("test.in","r+",stdin);
    //freopen("test.out","w+",stdout);
    FSIO;
    string S, T;
    while(cin>>S>>T)
    {

        for(int i=0;i<S.length();++i)
        {
            char c= S[i];
            if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
                S[i]='*';
            else    S[i]='+';
        }
        for(int i=0;i<T.length();++i)
        {
            char c= T[i];
            if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
                T[i]='*';
            else    T[i]='+';
        }
        //cout<<S<<" "<<T<<endl;
        if(S==T)    cout<<"Yes"<<endl;
        else    cout<<"No"<<endl;
    }
    return 0;
}

B. Average Superhero Gang Power

题目链接
题面:

划掉

题意:

n n n个英雄,每个人拥有 a 1 , a 2 , . . . , a n a_1, a_2, ... , a_n a1,a2,...,an的能量,让你进行m次操作:

  • 去掉某个英雄
  • 给某个英雄能量加 1 1 1
    注意每个英雄最多加 k k k次能量

问按上述操作,最后英雄的平均能量的最大值。

思路:

贪心。
从前往后,考虑首先去掉 i i i个英雄,剩下能加上的能量为 m i n ( m − i , ( n − i ) ∗ k ) min(m-i,(n-i)*k) min(mi,(ni)k)
O ( n ) O(n) O(n)扫一遍即可。

AC代码:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <stack>
#include <bitset>

using namespace std;

#define FSIO  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define DEBUG(a)   cout<<"DEBUG: "<<(a)<<endl;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define MP make_pair
#define X  first
#define Y  second
#define REP(i,st,ed)    for(int i=st;i<=ed;++i)
#define IREP(i,st,ed)   for(int i=st;i>=ed;--i)
#define TCASE(T)    cin>>T;while(T--)

const int MAXN = 100005;
const ll MOD = 1e9+7 ;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 1e9+7;
const double PI = acos(-1.0);
const double EPS = 1e-8;

int _;

using namespace std;

int power[MAXN];
int N, K, M;

int main()
{
    //freopen("test.in","r+",stdin);
    //freopen("test.out","w+",stdout);
    FSIO;
    cout<<setprecision(10);
    cout<<fixed;
    while(cin>>N>>K>>M)
    {
        REP(i,1,N)  cin>>power[i];
        sort(power+1,power+1+N);
        ll summ = 0;
        REP(i,1,N)  summ+=power[i];
        double res = (double)summ/N;
        REP(i,0,N-1)
        {
            if(M-i<0)   break;
            summ -= power[i];
            ll togo = min(1LL*(N-i)*K,1LL*(M-i));
            res = max(res,(double)(togo+summ)/(N-i));
        }
        cout<<res<<endl;
    }
    return 0;
}

C. Creative Snap

题目链接
题面:

划掉

题意:

有一排敌人的基地,长度为 1 &lt; &lt; n 1&lt;&lt;n 1<<n,还有k个敌人,每个敌人仅且仅在一个基地。
现在让你来消灭这些基地,每次你能进行的有两种操作:

  • 将你要消灭的基地对半分(保证长度 ≥ 2 \geq 2 2)
  • 消灭一段基地,如果没有敌人,则消耗 A A A能量,否则消耗 B ∗ 敌 人 数 量 ∗ 基 地 长 度 B*敌人数量*基地长度 B能量。

问你消灭这排基地所需最小能量。

思路:

DFS
每次要消灭 l 到 r l到r lr这段基地时,
首先使用二分前缀和求出基地敌人数量,

  • 如果为0,那么消灭这排基地所需最小能量为 A A A
  • 否则,求出当前消灭这排基地所需能量值,与 d f s ( l , m i d ) + d f s ( m i d + 1 , r ) dfs(l,mid)+dfs(mid+1,r) dfs(l,mid)+dfs(mid+1,r)取最小值
    注意当敌人数量为0时,直接返回
AC代码:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <stack>
#include <bitset>

using namespace std;

#define FSIO  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define DEBUG(a)   cout<<"DEBUG: "<<(a)<<endl;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define MP make_pair
#define X  first
#define Y  second
#define REP(i,st,ed)    for(int i=st;i<=ed;++i)
#define IREP(i,st,ed)   for(int i=st;i>=ed;--i)
#define TCASE(T)    cin>>T;while(T--)

const int MAXN = 100005;
const ll MOD = 1e9+7 ;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 1e9+7;
const double PI = acos(-1.0);
const double EPS = 1e-8;

int _;

using namespace std;

int position[MAXN];
int N, K, A, B;

int cnt_avengers(int l, int r)
{
    l = lower_bound(position+1,position+1+K,l)-position;
    r = upper_bound(position+1,position+1+K,r)-position-1;
    return max(0,r-l+1);
}

ll rua(int l, int r)
{
    int num_ave = cnt_avengers(l,r);
    ll base = 1LL*num_ave*B*(r-l+1)+(num_ave==0)*A;

    if(r-l+1<2||num_ave==0) return base;
    int mid = (l+r)>>1;
    base = min(base,rua(l,mid)+rua(mid+1,r));
    return base;
}

int main()
{
    //freopen("test.in","r+",stdin);
    //freopen("test.out","w+",stdout);
    FSIO;
    while(cin>>N>>K>>A>>B)
    {
        REP(i,1,K)  cin>>position[i];
        sort(position+1,position+1+K);
        cout<<rua(1,1<<N)<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值