PTA2022 520钻石争霸赛题解

7-1 520表白

不用说

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e9;
const int maxm = 1e5 + 5;
const int inf = 2147483647;
using namespace std;

int solve(){
    int n, m;
    cin >> n;
    cout << n << "! " << "520!";
    return 0;
}

int main() {
    int t = 1;
    // cin >> t;
    while(t--){
      solve();
    }
    return 0;
}

 

7-2 分糖豆

不用说

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e9;
const int maxm = 1e5 + 5;
const int inf = 2147483647;
using namespace std;

int solve(){
    int n, m, k;
    cin >> n >> m >> k;
    if(n * k == m){
        cout << "zheng hao mei ren " << k << "!";
    }else if(n * k < m){
        cout << "hai sheng " << m - n * k << "!";
    }else cout << "hai cha " << n * k - m << "!";
    return 0;
}

int main() {
    int t = 1;
    // cin >> t;
    while(t--){
      solve();
    }
    return 0;
}

 

7-3 约会App

判断下就可以,不用说

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e9;
const int maxm = 1e5 + 5;
const int inf = 2147483647;
using namespace std;

int solve(){
    int x, a, b, c, d, n;
    cin >> x >> a >> b >> c >> d >> n;
    while(n--){
        int s, y, h;
        cin >> s >> y >> h;
        if(s != x && y >= a && y <= b && h >= c && h <= d){
            cout << s << ' ' << y << ' ' << h << "\n";
        }
    }
    return 0;
}

int main() {
    int t = 1;
    // cin >> t;
    while(t--){
      solve();
    }
    return 0;
}

 

7-4 关于奇数的等式

范围小从1开始找就行,根据等式判断

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e9;
const int maxm = 1e5 + 5;
const int inf = 2147483647;
using namespace std;

int solve(){
    int n, m, x, y, z, f = 0;
    cin >> n >> m;
    for(int i = 1; i <= m - 4; i += 2){
        for(int j = i + 2; j <= m - 2; j += 2){
            for(int k = j + 2; k <= m; k += 2){
                if((1.0 * 3 / n) == ((1.0 / i) + (1.0 / j) + (1.0 / k))){
                    f = 1;
                    cout << i << ' ' << j << ' ' << k;
                    return 0;
                }
            }
        }
    }
    if(!f)cout << "No solution in (3, " << m << "].";
    return 0;
}

int main() {
    int t = 1;
    // cin >> t;
    while(t--){
      solve();
    }
    return 0;
}

 

7-5 我侬数

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e9;
const int maxm = 1e5 + 5;
const int inf = 2147483647;
using namespace std;
 
int aa[10], cc[10];//分别是存 原本基础数 和 需要判断的数 的0-9的个数

int solve(){
    string a, b, c, d;
    cin >> a >> b;
    int i = 0, j = 0, p = 0;
    //去掉前面0
    while(a[i] == '0' && i < a.length())i++;
    while(b[j] == '0' && j < b.length())j++;
    
    //找0-9的个数
    while(i < a.length())aa[a[i] - '0']++, i++;
    while(j < b.length())aa[b[j] - '0']++, j++;
    
    while(1){
        for(int k = 0; k < 10; k ++)cc[k] = 0;//每次都要重新清0
        cin >> c >> d;
        if(c == "0" && d == "0")break;
        
        //同上
        i = 0, j = 0;
        while(c[i] == '0' && i < c.length())i++;
        while(d[j] == '0' && j < d.length())j++;
        while(i < c.length())cc[c[i] - '0']++, i++;
        while(j < d.length())cc[d[j] - '0']++, j++;
        
        int f = 0;
        for(int k = 0; k < 10; k++){
                //有不一样就No
            if(aa[k] != cc[k]){
                cout << "No\n";
                f = 1;
                break;
            }
        }
        if(!f)cout << "Yes\n";
    }
    return 0;
}

int main() {
    int t = 1;
    // cin >> t;
    while(t--){
      solve();
    }
    return 0;
}

 

7-6 非诚勿扰

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e9;
const int maxm = 1e5 + 5;
const int inf = 2147483647;
using namespace std;

int solve(){
    int n, m, k, j = 3, p = 3, f = 0, q, h;
    cin >> n;
    
    k = n / 2.718;
    
    for(int i = 1; i <= n; i ++){
        cin >> m;
        
        //p是找全部人中最合适的,h保留下标
        if(m >= p){
            p = m;
            h = i;
        }
        
        if(i <= k) j = max(j, m);
        else if(!f && m >= j) {q = i;f = 1;}//找决定牵手的,q存下标
    }
    if(!f)q = 0;
    cout << q << ' ' << h;
        return 0;
}

int main() {
      int t = 1;
      // cin >> t;
      while(t--){
        solve();
      }
      return 0;
}

 

7-7 新式六合彩

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e9;
const int maxm = 1e5 + 5;
const int inf = 2147483647;
using namespace std;

int a[1010][1010], minm = inf;

int solve(){
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= m; j ++)
            cin >> a[i][j];
    
    int r, c, x;
    cin >> r >> c >> x;
    
    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= m; j ++){
            if(i == r || j == c){
                if(a[i][j] != -1)
                //找r行或c列中差值最小的
                minm = min(minm, abs(a[i][j] - x));
            }
        }
    } 
    //范围小,一行一行输出就行,符合输出要求   
    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= m; j ++){
            if(i == r || j == c){
                if(a[i][j] != -1)
                    if((abs(a[i][j] - x)) == minm)
                    cout << "(" << i << ":" << j << ")" << "\n";                 
            }
        }
    }
    return 0;
}

int main() {
    int t = 1;
    // cin >> t;
    while(t--){
      solve();
    }
    return 0;
}

 

7-8没时间做

posted @ 2022-05-21 00:25  acwarming  阅读(84)  评论(0编辑  收藏  举报