ACM实验室2020.11.14 天梯赛六

7-1 阅览室 (20分)

做法:用数组来标记某本书是否被借以及借的时间,当一天结束时判断借出的书的数量判断是否需要输出。如此循环,另外借书时间需要向上取整

代码:

//去吧马里奥!!把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.;
const double EPS = 1e-6;
const int INF = 0x3f3f3f3f;
using namespace std;


int main(){
    int n;
    cin >> n;
    int id, h, m, cnt = 0, sum = 0;
    char se, mm;
    int time[2000] ={0};
    int huanshu[2000] = {0};
    for (int i = 0; i < 2000;i++){
        huanshu[i] = 0;
        time[i] = 0;
    }
    int day = 0;
    for (day = 0; day < n;){
        cin >> id >> se >> h >> mm >> m;
        if(id == 0){
            if(cnt == 0){
                cout << 0 << " " << 0 << endl;
            }else{
                cout << cnt << " " << int(1.0 * sum / cnt + 0.5) << endl;
            }
            day++;
            cnt = 0;
            sum = 0;
            for (int i = 0; i < 2000;i++){
                huanshu[i] = 0;
            }
        }else if(se == 'S'){
            huanshu[id] = 1;
            time[id] = h * 60 + m;
        }else if(se == 'E' && huanshu[id] == 1){
            huanshu[id] = 0;
            sum = sum + h * 60 + m - time[id];
            cnt++;
        }
    }
}

7-2 A除以B (10分)

做法:pass

代码:

//去吧马里奥!!把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.;
const double EPS = 1e-6;
const int INF = 0x3f3f3f3f;
using namespace std;

int main(){
    double a, b;
    scanf("%lf %lf", &a, &b);
    if(b > 0){
        printf("%.0lf/%.0lf=%.2lf\n", a, b, a / b);
    }else if(b < 0){
        printf("%.0lf/(%.0lf)=%.2lf\n", a, b, a / b);
    }else if(b == 0){
       printf("%.0lf/%.0lf=Error\n", a, b);
    }
    return 0;
}

7-3 Left-pad (20分)

做法:注意一下要求的比原字符串小的情况

代码:

//去吧马里奥!!把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.;
const double EPS = 1e-6;
const int INF = 0x3f3f3f3f;
using namespace std;

int main(){
    int n;
    char s;
    cin >> n >> s;
    getchar();
    string a;
    getline(cin, a);
    int len;
    len = a.length();
    //cout << len << endl;
    if(n > len){
        int xx;
        xx = n - len;
        for (int i = 0; i < xx;i++){
            cout << s;
        }
        cout << a << endl;
    }else{
        int nn;
        nn = len - n;
        for (int i = nn; i < len;i++){
            cout << a[i];
        }
        cout << endl;
    }
}

7-4 新世界 (5分)

做法:pass

代码:

//去吧马里奥!!把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.;
const double EPS = 1e-6;
const int INF = 0x3f3f3f3f;
using namespace std;

int main(){
    cout << "Hello World" << endl;
    cout << "Hello New World" << endl;
}

7-5 查验身份证 (15分)

做法:写一个超长的判断(感觉我笨死了)

代码:

//去吧马里奥!!把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.;
const double EPS = 1e-6;
const int INF = 0x3f3f3f3f;
using namespace std;

int main(){
    
    int n;
    cin >> n;
    char a[20];
    a[0] = '1';
    a[1] = '0';
    a[2] = 'X';
    a[3] = '9';
    a[4] = '8';
    a[5] = '7';
    a[6] = '6';
    a[7] = '5';
    a[8] = '4';
    a[9] = '3';
    a[10] = '2';
    int flag = 1;
    while (n--)
    {
        char num[20];
        char yan;
        getchar();
        for (int i = 0; i < 17;i++){
            num[i] = getchar();
        }
        yan = getchar();
        //cin >> yan;
        //getchar();
        LL sum = 0;
        sum = 7 * (num[0]-48) + 9 * (num[1]-48) + 10 * (num[2]-48) + 5 * (num[3]-48) + 8 * (num[4]-48) + 4 * (num[5]-48) + 2 * (num[6]-48) + 1 * (num[7]-48) + 6 * (num[8]-48) + 3 * (num[9]-48) + 7 * (num[10]-48) + 9 * (num[11]-48) + 10 * (num[12]-48) + 5 * (num[13]-48) + 8 * (num[14]-48) + 4 * (num[15]-48) + 2 * (num[16]-48);
        LL z = 0;
        z = sum % 11;
        //cout <<sum<<" "<<z<<" " <<a[z] << " " << yan << endl;
        if(a[z] == yan){
            
            continue;
        }else{

            flag = 0;
            for (int i = 0; i < 17;i++){
                cout << num[i];
            }
            cout << yan << endl;

        }
    }
    if(flag == 1){
        cout << "All passed" << endl;
    }
    return 0;
}

7-6 吃鱼还是吃肉 (10分)

做法:注意判断顺序注意判断顺序注意判断顺序

代码:

//去吧马里奥!!把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.;
const double EPS = 1e-6;
const int INF = 0x3f3f3f3f;
using namespace std;

int main(){
    int n;
    cin >> n;
    while(n--){
        int sex, hi, we;
        cin >> sex >> hi >> we;
        if(sex == 0){
            if(hi < 129){
                cout << "duo chi yu! ";
            }
            if(hi > 129){
                cout << "ni li hai! ";
            }
            if(hi == 129){
                cout << "wan mei! ";
            }
            if(we == 25){
                cout << "wan mei!";
            }
            
            if(we<25){
                cout << "duo chi rou!";
            }
            if(we > 25){
                cout << "shao chi rou!";
            }
            cout << endl;
        }else
        if(sex == 1){
            if(hi < 130){
                cout << "duo chi yu! ";
            }
             if(hi > 130){
                cout << "ni li hai! ";
            }
            if(hi == 130){
                cout << "wan mei! ";
            }
            if(we == 27){
                cout << "wan mei!";
            }
           
            if(we<27){
                cout << "duo chi rou!";
            }
            if(we > 27){
                cout << "shao chi rou!";
            }
            cout << endl;
        }
    }
}

7-7 矩阵A乘以B (15分)

做法: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.;
const double EPS = 1e-6;
const int INF = 0x3f3f3f3f;
using namespace std;

int main(){

    int a[200][200], b[200][200], c[200][200];
    int n1, m1, n2, m2;
    cin >> n1 >> m1;
    for (int i = 0; i < n1;i++){
        for (int j = 0; j < m1;j++){
            cin >> a[i][j];
        }
    }
    cin >> n2 >> m2;
    for (int i = 0; i < n2;i++){
        for (int j = 0; j < m2;j++){
            cin >> b[i][j];
        }
    }
    if(n2 != m1){
        printf("Error: %d != %d\n", m1, n2);
        return 0;
    }else{
        cout << n1 << " " << m2 << endl;
        for (int i = 0; i < n1;i++){
            for (int j = 0; j < m2;j++){
                for (int k = 0; k < n2;k++){
                    c[i][j] += a[i][k] * b[k][j];
                }
            }
        }
        for (int i = 0; i < n1;i++){
            for (int j = 0; j < m2;j++){
                if(j ==0){
                    cout << c[i][j];
                }else{
                    cout << " " << c[i][j];
                }
            }
            cout << endl;
        }
    }

    
}

7-8 心理阴影面积 (5分)

做法:pass

代码:

//去吧马里奥!!把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.;
const double EPS = 1e-6;
const int INF = 0x3f3f3f3f;
using namespace std;

int main(){
    int x, y;
    cin >> x >> y;
    int ans;
    ans = 5000 - (100 * (100-x) / 2) - (100 * y / 2);
    cout << ans << endl;
}

7-11 集合相似度 (25分)

做法:把数据塞到set数组里,注意是set数组,之后用count函数找没重复的数量,再用总数减去就行

代码:

//去吧马里奥!把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;
    cin >> N;
    int M;
    set<int>se[51];
    for(int i = 1;i <= N;i++){
        cin >> M;
        while(M--){
            int xx;
            cin >> xx;
            se[i].insert(xx);
        }
    }
    int K;
    cin >> K;
    while(K--){
        int n,m;
        cin >> n >> m;
        set<int>::iterator it;
        int num = 0;
        for(it = se[n].begin();it != se[n].end();it++){
            if(se[m].count(*it) == 1){
                num++;
            }
        }
        int sum;
        sum = se[n].size()+se[m].size()-num;
        
        printf("%.2lf\%\n", num * 100.0 / sum);
    }
}

 

posted @ 2020-11-22 19:24  CCCCrack  阅读(151)  评论(0)    收藏  举报