1. 程式人生 > 實用技巧 >2020.10.16 Rating 補題報告

2020.10.16 Rating 補題報告

A - Juggling Letters

題意:給出一些字串,其中字元可以互相移動交換,問能否使所有字串都相等

做法:統計所有字母出現的次數,然後再看看能不能被n整除就行

程式碼:

//去吧馬里奧!把AC公主救回來!
//        ********
//       ************
//       ####....#.
//     #..###.....##....
//     ###.......######
//        ...........
//       ##*#######
//    ####*******######
//   ...#***.****.*###....
//   ....**********##.....
// ....**** *****.... // #### #### // ###### ###### #include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<string> #include<map> #include<sstream> #include<cstring> #include<vector> #include<iomanip> #include
<queue> #include<set> #define LL long long #define _64 __int64 const double PI = atan(1.)*4.; using namespace std; int main(){ int t; cin >> t; while(t--){ int a[2000]; for(int i= 0;i < 2000;i++){ a[i] = 0; } int n; cin
>> n; int num = n; while(n--){ char s[2000]; cin >> s; for(int i = 0;s[i] != 0;i++){ a[s[i] - 'a']++; } } int flag = 1; for(int i = 0;i <= 26;i++){ if(a[i] % num != 0){ flag = 0; break; } } if(flag == 1){ cout << "YES" << endl; }else{ cout << "NO" << endl; } } }

B - Power Sequence

題意:給出一串數字,可以進行加減1的操作,最終目的是使其成為一串等比數列,問需要最少多少步

做法:可以暴力列舉,,先排序,之後每個數列舉需要的步數就行

程式碼:

//去吧馬里奧!把AC公主救回來!
//        ********
//       ************
//       ####....#.
//     #..###.....##....
//     ###.......######
//        ...........
//       ##*#######
//    ####*******######
//   ...#***.****.*###....
//   ....**********##.....
//   ....****    *****....
//     ####        ####
//   ######        ######
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<map>
#include<sstream>
#include<cstring>
#include<vector>
#include<iomanip>
#include<queue>
#include<set>
#define LL long long
#define _64 __int64
const double PI = atan(1.)*4.;
using namespace std;

int a[200005];

int main(){

    int n;
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    LL minn = 1e20;
    sort(a+1,a+1+n);
    for(int i = 1;i <= 1000000;i++){
        LL num = 0;
        LL bi = 1;
        for(int j = 1;j <= n;j++){
            num += abs(a[j] - bi);
            if(num > minn){
                break;
            }
            bi = bi * i;
        }
        if(num < minn){
            minn = num;
        }
    }

    cout << minn << endl;

}

D - Drinks Choosing

題意:這個題的題意繞的一批,看半天都沒看明白是什麼意思,大體意思就是輸入學生的數量和飲料的種類,然後輸入學生想要的飲料的編號,之後這倒黴玩意的意思是飲料都是一組兩杯的,兩杯一定是同一種飲料,問最多有多少學生能得到自己想要的飲料

做法:首先,得把學生分成兩人一組,如果兩人想要同一種飲料,那就屬於滿足的一類,如果兩人想要的不一樣,那必然只有一個人能夠滿足需求,把這兩組分開後,滿足的加上不滿足的除以二就是答案了(注意要向上取整)

程式碼:

//去吧馬里奧!把AC公主救回來!
//        ********
//       ************
//       ####....#.
//     #..###.....##....
//     ###.......######
//        ...........
//       ##*#######
//    ####*******######
//   ...#***.****.*###....
//   ....**********##.....
//   ....****    *****....
//     ####        ####
//   ######        ######
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<map>
#include<sstream>
#include<cstring>
#include<vector>
#include<iomanip>
#include<queue>
#include<set>
#define LL long long
#define _64 __int64
const double PI = atan(1.)*4.;
using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    int a[2000];
    for(int i = 0;i < 2000;i++){
        a[i] = 0;
    }
    int m;
    for(int i = 0;i <n;i++){

        cin >>m;
        a[m]++;
    }
    int manzu = 0;
    int bumanzu = 0;
    int ans = 0;
   for(int i = 0;i < 2000;i++){
        manzu  = manzu + (a[i]-a[i]%2);
        bumanzu = bumanzu + (a[i] % 2);
    }
    ans = manzu + (bumanzu+1) / 2;
    cout << ans << endl;

}

E - Sport Mafia

題意:一個盒,往裡面放糖,每次放的糖都是上一次放的+1(也就是等差數列),之後還會吃,問給出操作的次數和最後剩的糖,求吃了多少

做法:因為每次放的都是等差數列,所以可以設變數用數學方法做,如下(計算過程滿滿一頁紙,不放了):

//去吧馬里奧!把AC公主救回來!
//        ********
//       ************
//       ####....#.
//     #..###.....##....
//     ###.......######
//        ...........
//       ##*#######
//    ####*******######
//   ...#***.****.*###....
//   ....**********##.....
//   ....****    *****....
//     ####        ####
//   ######        ######
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<map>
#include<sstream>
#include<cstring>
#include<vector>
#include<iomanip>
#include<queue>
#include<set>
#define LL long long
#define _64 __int64
const double PI = atan(1.)*4.;
using namespace std;

int main(){
    LL n,k;
    cin >> n >> k;
    LL ans;
    ans = (sqrt(9+8*(k+n))-3)/2;
    ans = n - ans;
    cout << ans << endl;

}