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

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 2147483647
12 #define ls rt<<1
13 #define rs rt<<1|1
14 #define lson ls,nl,mid,l,r
15 #define rson rs,mid+1,nr,l,r
16 #define N 100010
17 #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 }

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

时间: 2024-10-14 03:51:34

http://codeforces.com/gym/100623/attachments H题的相关文章

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

http://codeforces.com/gym/100623/attachments E题第一个优化它虽然是镜像对称,但它毕竟是一一对称的,所以可以匹配串和模式串都从头到尾颠倒一下第二个优化,与次数无关,所以排个序就完事了 1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #include<algorithm> 5 #include<cmath> 6 #include<

Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉

Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description Andrew is having a hard time preparing his 239-th contest for Petrozavodsk. This time the solution to the problem is based on Di

Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞

Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description In a Famous TV Show “Find Out” there are n characters and only one Horrible Truth. To make the series breathtaking all way long, the sc

Codeforces 828B Black Square(简单题)

Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n?×?m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum pos

codeforces 848B Rooter&#39;s Song 思维题

http://codeforces.com/problemset/problem/848/B 给定一个二维坐标系,点从横轴或纵轴垂直于发射的坐标轴射入(0,0)-(w,h)的矩形空间.给出点发射的坐标轴,位置,延迟时间,发生碰撞则交换方向.求最后每个点的射出位置. 首先我们观察能得出两个结论,1. 类似蚂蚁爬树枝的问题,相遇只会交换方向,所以最后的射出点集只会因为碰撞而改变动点与射出点的对应关系,而不会增加减少射出点集.2.我们根据其射入位置和延迟时间可以计算出一个值v=pos-time,只有这

Codeforces Round #634 (Div. 3) 补题

A. Candies and Two Sisters 签到题,直接输出即可 代码 #include<bits/stdc++.h> #define INF 0x3f3f3f3f typedef long long ll; using namespace std; inline void read(int &p) { p=0;int flag=1;char c=getchar(); while(!isdigit(c)) {if(c=='-') flag=-1;c=getchar();} w

ZOJ 3829 Known Notation (2014牡丹江H题)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5383 Known Notation Time Limit: 2 Seconds      Memory Limit: 65536 KB Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathematics and computer science. I

Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟

E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to

2014 HDU多校弟八场H题 【找规律把】

看了解题报告,发现看不懂 QAQ 比较简单的解释是这样的: 可以先暴力下达标,然后会发现当前数 和 上一个数 的差值是一个 固定值, 而且等于当前数与i(第i个数)的商, 于是没有规律的部分暴力解决,有规律的套公式 //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <cstring&g