PTA 520钻石争霸赛 2022

原题链接:【传送门】PTA2022-520

  • 2022.5.20:更新前7题题解,第8题14/25 (思路待更新)。
  • 2022.5.25:第8题题解。
/*Q1*/
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    cout << n << "! 520!";
    return 0;
}

/*Q2*/
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m,k; cin >> n >> m >> k;
    if(m/n==k&&m%n==0) cout << "zheng hao mei ren "<< k << "!";
    else if(m/n>k||m/n==k&&m%n!=0){
        cout << "hai sheng " << m-n*k << "!";
    }else{
        cout << "hai cha "<< n*k-m << "!";
    }
    return 0;
}

/*Q3*/
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,a,b,c,d; cin >> n >> a >> b >> c >> d;
    int m; cin >> m;
    for(int i=0;i<m;i++){
        int s,age,height;
        cin >> s >> age >> height;
        if((s==!n)&&age>=a&&age<=b&&height>=c&&height<=d) cout << s << " " << age << " " << height << endl;
    }
    return 0;
}

/*Q4*/
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m; cin >> n >> m;
    for(int x=1;x<m;x+=2){
        for(int y=x+2;y<m;y+=2){
            for(int z=y+2;z<=m;z+=2){
                if(3*x*y*z==n*y*z+n*x*z+n*x*y){
                    cout << x << " " << y << " " << z;
                    return 0;
                }
            }
        }
    }
    cout << "No solution in (3, " << m << "].";
    return 0;
}

/*Q5*/
#include <bits/stdc++.h>
using namespace std;
unordered_map<char,int> st;
int main(){
    string a,b;
    cin >> a >> b;
    int i=0;
    while(a[i]=='0') i++;
    a=a.substr(i,a.length()-i);
    i=0;
    while(b[i]=='0') i++;
    b=b.substr(i,b.length()-i);
    for(auto it:a) st[it]++;
    for(auto it:b) st[it]++;
    while(1){
        int flag=1;
        string str1,str2;
        unordered_map<char,int> mapp;
        cin >> str1 >> str2;
        if(str1=="0"&&str2=="0") break;
        for(auto it:str1) mapp[it]++;
        for(auto it:str2) mapp[it]++;
        for(auto it:mapp){
            if(st[it.first]!=it.second){
                flag=0;
                break;
            }
        }
        int i=0;
        while(str1[i]=='0') i++;
        str1=str1.substr(i,str1.length()-i);
        i=0;
        while(str2[i]=='0') i++;
        str2=str2.substr(i,str2.length()-i);
        if(str1.length()+str2.length()==a.length()+b.length()&&flag==1) cout << "Yes";
        else cout << "No";
        cout << endl;
    }
    return 0;
}


/*Q6*/
#include <bits/stdc++.h>
using namespace std;
int score[10010];
int main(){
    int n,res=0,m=0,mid=1,ans=0,flag=0; cin >> n;
    const int R=n/2.718;
    for(int i=1;i<=n;i++){
        cin >> score[i];
        if(m<=score[i]){
            m=score[i],mid=i;
        }
        if(i<=R){
            res=max(res,score[i]);
        }else{
            if(flag==0&&score[i]>=res){
                flag=1,ans=i;
            }
        }
    }
    cout << ans << " " << mid;
    return 0;
}

/*Q7*/
#include <bits/stdc++.h>
using namespace std;
set<pair<int,int>> st;
int a[1010][1010];
int main(){
    int n,m,minn=0x3f3f3f3f;
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin >> a[i][j];
        }
    }
    int r,c,num;
    cin >> r >> c >> num;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if((i==r||j==c)&&a[i][j]!=-1){
                if(abs(a[i][j]-num)<minn){
                    st.clear();
                    minn=abs(a[i][j]-num);
                    st.insert({i,j});
                }else if(abs(a[i][j]-num)==minn){
                    st.insert({i,j});
                }
            }
        }
    }
    for(auto it:st){
        pair<int,int> p=it;
        printf("(%d:%d)\n",p.first,p.second);
    }
    return 0;
}

/*Q8*/
/* 
将集合从大到小排序,总共需要选择n/3个元素。
如果遇到>0的x:除以5,然后再去除他的5倍、2倍、1倍。 
如果遇到<0的x:直接去除这个数的5倍、2倍、1倍。
当前记录的x就是原始序列中的数之一,而且一定是从大到小排列的。 
*/ 
#include <bits/stdc++.h>
using namespace std;
multiset<int,greater<int>> st; //从大到小排序的集合
int main(){
	int n; cin >> n;
	for(int i=0;i<n;i++){
		int x; cin >> x;
		st.insert(x);
	}
    for(int i=0;i<n/3;i++){
    	int x=*st.begin();
    	if(x>0) x/=5;
    	st.erase(st.find(x*5)); //删除第一个x*5
		st.erase(st.find(x*2));
		st.erase(st.find(x*1));
		cout << x ;
		if(i==n/3-1) cout << endl;
		else cout << " "; 
    }
	return 0;
}

END

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值