AtCoder Regular Contest 126

A- Make 10
传送门
题意

你有三种棍子,长度分别为2,3,4;每一种有A i个。你需要尽可能多的用这三种棍子组成长度为10的棍子,并输出能组成多少根。

思路

贪心 我们可以发现长度为3的棍子必须两两出现,我们可以将其组成一个长度为6的。然后我们贪心的优先选取长度最长的。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int T;
    cin>>T;
    while(T--){
        ll a,b,c;
        cin>>a>>c>>b;
        ll ans=0,t=0;
        c/=2;
        if(b&&c){
            t=min(b,c);
            b-=t;c-=t;
            ans+=t;
        }
        if(c&&a>=2){
            t=min(c,a/2);
            a-=t*2;c-=t;
            ans+=t;
        }
        if(b>=2&&a){
            t=min(a,b/2);
            a-=t;b-=t*2;
            ans+=t;
        }
        if(b&&a>=3){
            t=min(b,a/3);
            a-=t*3;b-=t;
            ans+=t;
        }
        if(a){
            ans+=a/5;
        }
        cout<<ans<<"\n";
    }
    return 0;
}

B - Cross-free Matching

LIS题,对ai排序后求bi的LIS。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=2e5+5;
PII p[maxn];
int dp[maxn],a[maxn];
bool cmp(PII x,PII y){return x.first==y.first ? x.second>y.second:x.first<y.first  ;}//若second顺序反过来则会记录1-2,1-3导致错误
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
        scanf("%d%d",&p[i].first,&p[i].second);
 
    sort(p+1,p+m+1,cmp);
    int len=1;
    memset(dp,0x3f,sizeof dp);
    dp[1]=p[1].second;
 
    for(int i=2;i<=m;i++){
        if(p[i].second>dp[len])
            dp[++len]=p[i].second;
        else{
            int pos=lower_bound(dp+1,dp+1+n,p[i].second)-dp;
            dp[pos]=p[i].second;
        }
 
    }
    cout<<len;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值