首页 > 其他 > 详细

ACM实验室2020.11.08 天梯赛五

时间:2020-11-15 18:56:45      阅读:26      评论:0      收藏:0      [点我收藏+]

7-1 考试座位号 (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(){
    LL zhunkao[2000];
    int shiji[2000];
    int kaoji[2000];
    int cha[2000];
    int n;
    cin >> n;

    for(int i = 0;i < n;i++){
        scanf("%lld %d %d",&zhunkao[i],&shiji[i],&kaoji[i]);

    }
    int m;
    cin >> m;

    for(int i = 0;i < m;i++){
        cin >> cha[i];

    }
    for(int i = 0;i < m;i++){
        for(int j = 0;j < n;j++){
            if(cha[i] == shiji[j]){
                cout << zhunkao[j] << " " << kaoji[j] << endl;

            }

        }
    }
}

7-3 后天 (5分)

做法:注意星期天的情况

代码:

//???????£???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;
    if(n+2 == 7){
        cout << 7 << endl;
    }else
    cout << (n+2) % 7 << endl;
}

7-4 到底有多二 (15分)

做法:感觉这个题当时快把我折腾二了,思路其实很简单,就是立两个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.;
const double EPS = 1e-6;
const int INF = 0x3f3f3f3f;
using namespace std;

int main(){
    string s;
    cin >> s;
    int flag_f = 0;
    int flag_ou = 0;
    int len;

    //cout << s[0] << endl;
    if(s[0] == -){
        flag_f = 1;
    }

    if(flag_f == 1){
        len = s.length() - 1;
    }else{
        len = s.length();
    }
    if(flag_f == 1){
        if(s[len] % 2 == 0){
            flag_ou = 1;
        }
    }else{
        if(s[len-1] % 2 == 0){
            flag_ou = 1;
        }
    }

//cout << len << endl;
    int cnt = 0;
    int len2 = s.length();
    for(int i = 0;i < len2;i++){
        if(s[i] == 2){
            cnt++;
        }
    }
//cout << cnt << endl;
    double ans;

    ans = (cnt*1.0)/(len*1.0);
    //cout << ans << endl;
    if(flag_f == 1){
        ans = ans * 1.5;
    }
    if(flag_ou == 1){
        ans = ans * 2;
    }

    ans = ans * 100;

    printf("%.2f",ans);
    cout << "%";

}

7-5 念数字 (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(){
    map<char,string>mp;
    mp[-] = "fu";
    mp[1] = "yi";
    mp[2] = "er";
    mp[3] = "san";
    mp[4] = "si";
    mp[5] = "wu";
    mp[6] = "liu";
    mp[7] = "qi";
    mp[8] = "ba";
    mp[9] = "jiu";
    mp[0] = "ling";
    string s;
    cin >> s ;
    int len = s.length();
    for(int i = 0;i < len;i++){
        if(i == 0){
            cout << mp[s[i]];
        }else{
            cout << " " << mp[s[i]];
        }
    }
}

7-6 帅到没朋友 (20分)

做法:用一个vis数组存这个人有没有朋友,之后遍历要判断的人,看看vis数组是1或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.;
const double EPS = 1e-6;
const int INF = 0x3f3f3f3f;
using namespace std;

int main(){
    int N;
    cin >> N;
    int vis[200005];
    for(int i = 0;i < 200005;i++){
        vis[i] = 0;
    }
    int K;
    while(N--){
        cin >> K;
        for(int i = 0;i < K;i++){
            int id;
            cin >> id;
            if(K != 1){
                vis[id] = 1;
            }
        }
    }

    int M;
    cin >> M;
    int ids;
    int cnt = 0;
    while(M--){
        cin >> ids;
        if(vis[ids] == 0){
            if(cnt != 0){
                cout << " ";
            }
            printf("%05d",ids);
            vis[ids] = 1;
            cnt++;
        }
    }
    if(cnt == 0){
        cout << "No one is handsome" << endl;
    }
}

7-7 A乘以B (5分)

做法:就这?

代码:

//???????£???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,b;
    cin >> a >> b;
    cout << a*b << endl;
}

7-8 计算阶乘和 (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 fac(int a){
    int s = 1;
    for(int i = 1;i <= a;i++){
        s = s*i;
    }
    return s;
}

int main(){
    int n;
    int ans = 0;
    cin >> n;

    for(int i = 1;i <= n;i++){
        ans += fac(i);
    }
    cout << ans << endl;
}

7-9 点赞狂魔(25分)

做法:结构体和set一起,先开一个结构体,分别存名字,数量,平均值还有个数,之后往set里输入,因为set会自动排序去重所以非常方便,之后排序的时候写个cmp结构体排序,之后根据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 longdata
#define _64 __int64
const double PI = atan(1.)*4.;
const double EPS = 1e-6;
const int INF = 0x3f3f3f3f;
using namespace std;

struct str{
    char id[20];
    int kk;
    int cnt;
    double adv;
}data[20005];

bool cmp(str a,str b){
    if(a.cnt == b.cnt){
        return a.adv < b.adv;
    }else{
        return a.cnt > b.cnt;
    }
}

int main(){
    int N;
    cin >> N;
    int a[2000];
    for(int i = 0;i < N;i++){
        set<int>se;
        cin >> data[i].id >> data[i].kk;
        for(int j = 0;j < data[i].kk;j++){
            int xx;
            cin >> xx;
            se.insert(xx);
        }
        data[i].cnt = se.size();
        data[i].adv = (data[i].kk*1.0) / (data[i].cnt*1.0);
    }

    sort(data,data+N,cmp);

    if(N >= 3){
        cout << data[0].id << " " << data[1].id << " " << data[2].id << endl;
    }else if(N == 2){
        cout << data[0].id << " " << data[1].id << " " << "-" << endl;
    }else if(N == 1){
        cout << data[0].id << " " << "-" << " " << "-" << endl;
    }else if(N == 0){
        cout << "- - -" << endl;
    }
}

7-10 悄悄关注 (25分)

做法:set和map搭配,首先把关注列表导进set,之后根据set的find()函数特性查找关注列表,如果没找到就用map记录,然后用迭代器遍历,比较平均值,而且由于set的排序功能,排序也免了,直接输出即可

代码:

//???????£???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;
    map<string,int>mp;

    set<string>se;
    for(int i = 0;i < n;i++){
        string xx;
        cin >> xx;
        se.insert(xx);
    }

    int m;
    cin >> m;
    int sum = 0;
    int zan;
    string id;
    for(int i = 0;i < m;i++){
        cin >> id >> zan;
        sum += zan;
        if(se.find(id) == se.end()){
            mp[id] = zan;
        }
    }

    double adv;
    adv = sum*1.0/m*1.0;
    int cnt = 0;

    //set<string>::iterator is;
map<string,int>::iterator it;
    for(it = mp.begin();it != mp.end();it++){
        if(it->second > adv){

            cout << it->first <<endl;
            cnt++;

        }
    }
    if(cnt == 0){
        cout << "Bing Mei You" << endl;
    }
}

 

ACM实验室2020.11.08 天梯赛五

原文:https://www.cnblogs.com/CCCCrack/p/13977682.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!