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;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章