codeforces 1272 C 思维

71 篇文章 0 订阅

cf 1272 c

题意 给你第一天a小时 ,第二天b小时

第i本书要看i小时 不能带到第二天看 问你如何使看的书最多

一开始一直在找(i+1)*(i)/2和a ,b分别的关系

其实这题要找和a+b的和这样的关系

我们从大到小进行枚举 如果第一天比枚举的数大 那么就放进第一天,因为大到小枚举 所以第一天肯定能填满

第一天填满那么这个 当前的 (i+1)*(i)/2已经小于a+b 那么 现在 a+b-a用掉的肯定小于b 所以就能放进b里面 主要是填满思路很重要

#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;
vector <int > ans,ans_;

int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    long long x;
    for(x= 1;x*(x+1)/2<=a+b;x++);
    x--;
    for(;x>=1;x--)
        if(a>=x) a-=x,ans.push_back(x);
        else if(b>=x) b-=x,ans_.push_back(x);
    printf("%d\n",ans.size());
    int sz = ans.size();
    sort(ans.begin(),ans.end());
    for(int i = 0;i<sz;++i)
        i==sz-1?printf("%d\n",ans[i]):printf("%d ",ans[i]);
    sz = ans_.size();
    printf("%d\n",sz);
    sort(ans_.begin(),ans_.end());
    for(int i = 0;i<sz;++i)
        i==sz-1?printf("%d\n",ans_[i]):printf("%d ",ans_[i]);
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值