分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

http://codeforces.com/gym/100623/attachments H题

发布时间:2023-09-21 20:32责任编辑:熊小新关键词:http

http://codeforces.com/gym/100623/attachments H题
已经给出来的,包括后来添加的,都累加得到ans,那么从1~ans都是可以凑出来的,如果ans<a[now]-1,那么就添加一个ans+1,然后继续操作。

 1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #include<algorithm> 5 #include<cmath> 6 #include<ctime> 7 #include<set> 8 #include<map> 9 #include<stack>10 #include<cstring>11 #define inf 214748364712 #define ls rt<<113 #define rs rt<<1|114 #define lson ls,nl,mid,l,r15 #define rson rs,mid+1,nr,l,r16 #define N 10001017 #define For(i,a,b) for(long long i=a;i<=b;i++)18 #define p(a) putchar(a)19 #define g() getchar()20 21 using namespace std;22 23 long long n,m;24 long long a[400],b[400000];25 long long ans,cnt,now;26 bool flag;27 void in(long long &x){28 ????long long y=1;29 ????char c=g();x=0;30 ????while(c<‘0‘||c>‘9‘){31 ????????if(c==‘-‘)y=-1;32 ????????c=g();33 ????}34 ????while(c<=‘9‘&&c>=‘0‘){35 ????????x=(x<<1)+(x<<3)+c-‘0‘;c=g();36 ????}37 ????x*=y;38 }39 void o(long long x){40 ????if(x<0){41 ????????p(‘-‘);42 ????????x=-x;43 ????}44 ????if(x>9)o(x/10);45 ????p(x%10+‘0‘);46 }47 int main(){48 ????freopen("key.in","r",stdin);49 ????freopen("key.out","w",stdout);50 ????in(n);in(m);51 ????For(i,1,n)52 ????????in(a[i]);53 ????sort(a+1,a+n+1);54 ????if(a[1]!=1){55 ????????b[++cnt]=1;56 ????????ans++;57 ????????m--;58 ????}59 ????// if(m>0)60 ????// ????For(i,1,n-1){61 ????// ????????ans+=a[i];62 ????// ????????if(ans<a[i+1]-1){63 ????// ????????????b[++cnt]=ans+1;64 ????// ????????????ans+=ans+1;65 ????// ????????????m--;66 ????// ????????}67 ????// ????????if(!m)68 ????// ????????????break;69 ????// ????}70 ????now=1;71 ????while(m>0){72 ????????if(ans<a[now]-1){73 ????????????b[++cnt]=ans+1;74 ?????????????ans+=ans+1;75 ????????????m--;76 ????????}77 ????????else{78 ????????????ans+=a[now];79 ????????????now++;80 ????????}81 ????????if(now>n)82 ????????????break;83 ????}84 ????while(m>0){85 ????????b[++cnt]=ans+1;86 ?????????ans+=ans+1;87 ????????m--;88 ????}89 ????For(i,1,cnt)90 ????????o(b[i]),p(‘ ‘);91 ????return 0;92 }
View Code

http://codeforces.com/gym/100623/attachments H题

原文地址:https://www.cnblogs.com/war1111/p/10798556.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved