CodeForces杂题#2 ——摸鱼#1

Superhero Transformation

1111 A

https://codeforces.com/problemset/problem/1111/A

 

 

题意:

求两个字符串对应的元音字母和其他字母是否均在同一位置上。

扫描字符串,但是要加上双重判断,既要判断A串也要判断B串。

 

AC代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int T;
double n;
typedef long long ll;
string a,b;
int main(){
    cin >> a >> b;
    if(a.length() != b.length()) {
        cout << "NO" << endl;
    }
    else {
        int lena = a.length();
        //int lenb = b.length();
        bool f = 1;
        for(int i = 0; i < lena; i++) {
            if((a[i] == 'a' || a[i] == 'e' || a[i] == 'i' || a[i] == 'o' || a[i] == 'u') ) {
                a[i] = '1';
            }
            else {
                a[i] = '2';
            }
        }
         for(int i = 0; i < lena; i++) {
             if((b[i] == 'a' || b[i] == 'e' || b[i] == 'i' || b[i] == 'o' || b[i] == 'u')) {
                 b[i] = '1';
             }else {
                 b[i] = '2';
             }
         }
         if(a == b) cout << "Yes" << endl;
         else cout <<"No" << endl;
    }
    return 0;
}

 

1111B

Average Superhero Gang Power

https://codeforces.com/problemset/problem/1111/B

 

题意:

有N个超级英雄,你可以进行M次操作,对每个英雄最高不超过K次增加,要求其所有平均值最大化。

这是一道很开拓思维的题目。

题目并非可以直接删除值最低的几个数字从而增加平均值。

而是需要一边删除一边判断。

 

AC代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
ll n, k, m;
const int maxn = 1e5 + 5;
ll a[maxn];
ll sum = 0;
int main(){
    cin >> n >> k >> m;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];                //SUM存放总和值
    }
    sort(a+1,a+n+1);
    double ans = (double)(sum + min((k*n), m)) / (double)n;    //ans是最初的平均值
    if(n == 1) printf("%.20lf\n",ans);
    else {
        for (int i = 1; i <= min(n - 1, m); i++) {
            sum -= a[i];                        //删除最低的

            //min((n - i)*k,(m-i))代表了当前可以加的最大值
            double tmp = (double)(sum + min((n - i)*k,(m-i))) /(double) (n-i);
            ans = max(ans,tmp);
        }
        printf("%.20lf\n",ans);
    }
    return 0;
}

 

Minimum Binary Number

976A

https://codeforces.com/problemset/problem/976/A

 

题意:

不论有多少1 最后都只剩一个1其他全是0

AC代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int T;
typedef long long ll;
string a;
int main(){
    cin >> T;
    cin >> a;
    int sum1 = 0;
    int sum0 = 0;
    for(int i = 0; i < T; i++) {
        if(a[i] == '1') sum1++;
        else sum0++;
    }
    if(sum1) cout <<"1";
    for(int i = 0; i < sum0;i++) cout<<"0";
    return 0;
}

 

 Lara Croft and the New Game

976B

https://codeforces.com/problemset/problem/976/B

 

题意:

找规律,这题规律不算很好找。

行的话 L = n - (k - n) / (m - 1)

列的话 由于奇数行和偶数行行走的方向并非是一致的,因此还需要判断。

取模中的(m-1)是因为仅有(m-1)个列(第一列已经特判),而非是随意选取的值。

 

AC代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
ll n, m, k;
int main(){
    cin >> n >> m >> k;
    if(k < n) cout << k+1 <<" 1" << endl;
    else {
        k -= n;
        ll l = n - k/(m-1);
        if(l&1) {
            ll r = m - (k%(m-1));
            cout <<l <<" " << r << endl;
        }else {
            ll r = k%(m-1)+2;
            cout << l << " " << r << endl;
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值