Acwing.第135场周赛

发布时间 2023-12-24 10:56:45作者: du463

比赛地址

A.买苹果

题目

思路:

简单的模拟一下就好了

代码:

#include<bits/stdc++.h>
using namespace std;
void solve(){
	int n,x;
	cin>>n>>x;
	cout<<n/x<<endl;
	return ;
	

}
int main(){

	int t=1;
	while(t--){
		solve();
	}
	return 0;

}

B.牛群

题目

思路:

也是简单的模拟一下,字符的种数一定是2-4之间的,然后根据情况进判断就可以了

代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long

void solve(){
    string s;
    cin>>s;
    set<char> s1;
    std::map<char, int> mp;

    for(int i=0;i<s.size();i++){
        s1.insert(s[i]);
        mp[s[i]]++;


    }
    bool f=false;
    if(s1.size()==4){
        cout<<"Yes"<<endl;
        return ;
        
    }
    if(s1.size()==3){
        bool f1=false;

        for(auto i:s1){
            if(mp[i]!=1){
                f1=true;
            }
        }
        if(f1){
            cout<<"Yes"<<endl;
            return ;
        }
        else{
            cout<<"No"<<endl;
            return ;
            
        }
    }
    if(s1.size()==2){
        bool f1=true;
        for(auto it:s1){
            if(mp[it]<2){
                f1=false;
            }
        }
        if(f1){
            f=true;
        }
        else{
            f=false;
            
        }
    }
    if(f){
        cout<<"Yes"<<endl;

    }
    else{
        cout<<"No"<<endl;

    }
    
    return ;
    

}
signed main(){
    int t=1;
    while(t--){
        solve();

    }
    return 0;

}

C.货运公司

题目

思路:

贪心,我们优先考虑价值最大的

代码:

#include<bits/stdc++.h>
#define int long long 
using namespace std;
const int N=1e3+10;
int n,k;
map<int,int> h;

struct node {
    int idx;
    int c;
    int p;
    bool operator < (const node &a2) {
        if(a2.p==p) return c<a2.c;
        return p>a2.p;
    }
}a[N];

struct f {
    int idx;
    int w;
    bool operator < (const f &a2) {
        return w<a2.w;
    }
}r[N];

bool st[N];
signed main() {
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>a[i].c>>a[i].p;
        a[i].idx=i;
    }
    sort(a+1,a+n+1);
    cin>>k;
    for(int i=1;i<=k;i++) {
        cin>>r[i].w;
        r[i].idx=i;
    }
    sort(r+1,r+k+1);
    int m=0,ans=0;
    for(int i=1;i<=n;i++) {
        int w=a[i].c;
        bool f=false;
        int id=0;
        for(int j=1;j<=k;j++)
            if(!st[j]&&w<=r[j].w) {
                st[j]=true;
                f=true;
                id=j;
                break;
            }
        if(f) {
            m++;
            ans+=a[i].p;
            h[a[i].idx]=r[id].idx;
        }
    }
    cout<<m<<" "<<ans<<"\n";
    for(int i=1;i<=n;i++) {
        if(h[i]) cout<<i<<" "<<h[i]<<"\n";
    }
    return 0;
}