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

2020.10.09 Rating 補題報告

A - A Blend of Springtime

題意:找給出的字串是否包含連續的不同的且不為“.”的三個字元,

做法:emmmm就是從頭讀之後判斷就行

程式碼:

//去吧馬里奧!把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; char a[2000]; int main(){ cin >> a; int flag = 0; //cout << a << endl; //cout << sizeof(a) << endl; for(int i = 1;i < strlen(a)-1
;i++){ if(a[i] != a[i+1] && a[i] != a[i-1] && a[i+1] != a[i-1] && a[i] != '.' && a[i+1] != '.' && a[i-1] != '.'){ flag = 1; break; } } if(flag == 1){ cout << "Yes" << endl; }else{ cout << "No" << endl; } }

B - A Tide of Riverscape

題意:輸入一串字串,包含“0”、“1”、“.”,其中“.”可以變成0或者1,判斷第i個數和i+p是否可以不同

做法:判斷,如果該點是“.”,直接全部變成0,之後判斷它相對的是不是1,用一個flag記錄即可

程式碼:

//去吧馬里奧!把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,p;
    cin >> n >> p;
    string s;
    cin >> s;
    int flag = 0;
    for(int i = 0;i < n;i++){
        if(s[i] == '.'){
            s[i] = '0';
            if(i + p < n && s[i+p] == '0' || i - p >= 0 && s[i-p] == '0'){
                s[i] = '1';
            }
        }
        if(i + p < n && s[i] != s[i+p]){
            flag = 1;
        }
    }
    if(flag == 1){
        cout << s << endl;
    }else{
        cout << "No" << endl;
    }

}

D - Infinity Gauntlet

題意:一組資料有一個顏色還有一個名字,其中有對應關係,給出顏色輸出名字

做法:用陣列存了(其實感覺用map會簡單些),再輸出就行

程式碼:

//去吧馬里奧!把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;

string a[10];
string b[10];
int mark[10];

int main(){
    int n;
    cin >> n;
    for(int i = 0;i <10;i++)mark[i] = 0;
    a[1] = "Power";b[1] = "purple";
    a[2] = "Time";b[2] = "green";
    a[3] = "Space";b[3] = "blue";
    a[4] = "Soul";b[4] = "orange";
    a[5] = "Reality";b[5] = "red";
    a[6] = "Mind";b[6] = "yellow";
    if(n == 0){
        for(int i=1;i < 10;i++){
            mark[i] = 0;
        }
    }else{
        for(int i = 0;i < n;i++){

            string s;
            cin >> s;
            if(s == "purple"){
                mark[1] =1;
            }else if(s == "green"){
                mark[2] = 1;
            }else if(s == "blue"){
                mark[3] = 1;
            }else if(s == "orange"){
                mark[4] = 1;
            }else if(s == "red"){
                mark[5] = 1;
            }else if(s == "yellow"){
                mark[6] = 1;
            }
        }
    }

    cout << 6-n << endl;
    //cout << mark[3] << endl;
    for(int i = 1;i < 7;i++){
        if(mark[i] ==  0){
            cout << a[i] << endl;
        }
    }
}

E - High School: Become Human

題意:都明白

做法:取對數,e的ln次方,一通亂算可以得出這個式子就等於x的y次方,可以通過比較對數的方法比較這倆數,另外由於是double型別有精度問題,也就是比較是否相等的時候得通過差多麼接近0得出,這個精度得取得很小才行

程式碼:

//去吧馬里奧!把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(){
    double x,y;
    cin >> x >> y ;
    double ansx,ansy;
    //LL a,b;
    //a = x/10;
    //b = y/10;
    //ansx = pow(a,b);
    //ansy = pow(b,a);
    //cout << ansx << ansy << endl;
    //ansx = log(x)/log(y);
    //ansy = log(y)/log(x);
    ansx = y*log(x);
    ansy = x*log(y);
    //if(ansx > ansy){
    //    cout << '>' << endl;
    //}else if(ansx < ansy){
    //    cout << '<' << endl;
    //}else if(fabs(ansx - ansy) < 1e-16){
//cout << '=' << endl;
    //}
    if(fabs(ansx - ansy) <= 1e-100){
        cout << '=' << endl;
    }else if(ansx - ansy < 0){
        cout << '<' << endl;
    }else{
        cout << '>' << endl;
    }
}

F - Three displays

題意:找既滿足i<j<k,且滿足si<sj<sk的最少的租金

做法:直接暴力,找到一個數,分別迴圈兩邊找最小值,之後把最小值加起來再算所有最小值和中的最小值就是答案

程式碼:

//去吧馬里奧!把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;

struct ans{
    int s;
    LL rent;
}anss[5000];

int main(){
    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> anss[i].s;
    }
    for(int i = 0;i < n;i++){
        cin >> anss[i].rent;
    }
    int flag1 = 0;
    int flag2 = 0;
    int flag = 0;
    LL minnx = 1e18;
    for(int i = 1;i < n-1;i++){
        LL ansx = anss[i].rent;
        flag1 = 0;
        flag2 = 0;
        LL minn1 = 1e8;
        LL minn2 = 1e8;
        for(int j = 0;j < i;j++){
            if(anss[j].s < anss[i].s){
                minn1 = min(minn1,anss[j].rent);
                flag1 = 1;
            }
        }
        for(int j = i+1;j < n;j++){
            if(anss[j].s > anss[i].s){
                minn2 = min(minn2,anss[j].rent);
                flag2 = 1;
            }
        }
        if(flag1 ==1 && flag2 == 1){
            flag = 1;
            ansx += minn1;
            ansx += minn2;
            minnx = min(minnx,ansx);
        }
    }
    if(flag == 1){
        cout << minnx << endl;
    }else{
        cout << -1 << endl;
    }
}