2022杭电(3)题解

目录

1003 Cyber Language

1009 Package Delivery


1003 Cyber Language

题目大意:给定用空格分割的n个汉字拼音(1<=n<=50),输出每个汉字拼音的大小首字母

思路:每次读取到空格时保存下一个字符并转换为大写

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f;
const int mod=1e3+7;
const int N=1e3+5,M=5e5+5;

int n,m;
string str;

int main(){
    //freopen("data.in","r",stdin);
    // ios::sync_with_stdio(false);
    // cin.tie(0); cout.tie(0);
    int T;
    cin>>T;
    getchar();
    while(T--) {
        getline(cin,str);
        string ans="";
        for(int i=0;i<str.length();i++) {
            if(i==0) ans+=str[i]-32;
            else if(str[i]==' '&&i!=str.length()-1) ans+=str[i+1]-32;
        }
        cout<<ans<<endl;
    }
	return 0;
}

1009 Package Delivery

题目大意:给出n和k,n表示包裹数量,k表示每次最多拿回的数量,下面有n个包裹,每个包裹用起始天l和截止天r表示.求拿回所有包裹的最小次数.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f;
const int mod=1e3+7;
const int N=1e5+5,M=5e5+5;

int n,m,k;
struct node{
    int l,r,id;
    bool operator < (const node &b) const {
        if(r==b.r) return l>b.l;
		return r > b.r; //从大到小
	}
};

struct node p[N],q[N];
bool st[N];

bool cmp1(struct node a,struct node b) {
    if(a.r==b.r) return a.l<b.l;
    return a.r<b.r;
}

bool cmp2(struct node a,struct node b) {
    if(a.l==b.l) return a.r<b.r;
    return a.l<b.l;
}

int check() {
    int pos=1,pos2=1,t=0,r;
    priority_queue<node> heap;
    int cnt=0;
    while(pos<=n) {
        if(st[p[pos].id]) {
            pos++;
            continue;
        }
        st[p[pos].id]=1;
        r=p[pos].r;
        pos++; t++;
        while(pos2<=n) {
            if(st[q[pos2].id]) {
                pos2++;
                continue;
            }
            if(q[pos2].l>r) break;
            heap.push(q[pos2++]);
        }
        while(heap.size()&&t<k) {
            node tt=heap.top(); heap.pop();
            if(st[tt.id]||tt.r<r) continue;
            st[tt.id]=1;
            t++;
        }
        t=0;
        cnt++;
    }
    return cnt;
}

int main(){
    //freopen("data.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int T;
    scanf("%d",&T);
    while(T--) {
       memset(st,0,sizeof(st));
       scanf("%d%d",&n,&k);
       //printf("%d %d\n",n,k);
       int a,b;
       for(int i=1;i<=n;i++) {
            scanf("%d%d",&a,&b);
            p[i]={a,b,i};
            q[i]={a,b,i};
       }
       sort(p+1,p+n+1,cmp1);
       sort(q+1,q+n+1,cmp2);
       printf("%d\n",check());
    }
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值