https://codeforces.com/contest/1150/problem/C

题解:思维+贪心

按2 1 2 2 2 ...... 1 1 1 1就可以了

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=200000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,p,l,r,u,v;
int ans,cnt,flag,temp,sum[3];
int a[N],b[N];
char str;
struct node{};
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&a[i]);sum[a[i]]++;}if(sum[2]){b[++cnt]=2;sum[2]--;}if(sum[1]){b[++cnt]=1;sum[1]--;}while(sum[2]){b[++cnt]=2;sum[2]--;}while(sum[1]){b[++cnt]=1;sum[1]--;}for(int i=1;i<=cnt;i++)printf("%d%c",b[i]," \n"[i==cnt]);//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif//cout << "Hello world!" << endl;return 0;
}

Prefix Sum Primes相关推荐

  1. 【CodeForces - 1150C】Prefix Sum Primes(思维)

    题干: We're giving away nice huge bags containing number tiles! A bag we want to present to you contai ...

  2. CodeForces - 1485F Copy or Prefix Sum(dp)

    题目链接:点击查看 题目大意:给出数组 bbb,问可以构造出多少种满足条件的数组 aaa,规定数组 aaa 和数组 bbb 的关系如下: bi=aib_i = a_ibi​=ai​ or bi=∑j= ...

  3. codeforces1485 F. Copy or Prefix Sum(dp)

    F. Copy or Prefix Sum Venice technique简要就是懒标记思想. 由于前缀和数组和原数组一一对应,这里我们选择求aia_iai​的前缀和数组的方案数(下面aia_iai ...

  4. 牛客网暑期ACM多校训练营(第九场)H. Prefix Sum(CDQ分治)

    题目描述 Niuniu has learned prefix sum and he found an interesting about prefix sum. Let's consider (k+1 ...

  5. 牛客网暑期ACM多校训练营(第十场)D Rikka with Prefix Sum

    链接:https://www.nowcoder.com/acm/contest/148/D 来源:牛客网 题目描述 Prefix Sum is a useful trick in data struc ...

  6. Prefix Sum 总结

    注意:prefixsum一般都是用PrefixSum[n+1]的数组,prefix[0] = 0; 那么 因为i, j 是A里面的坐标,而prefixsum比A多了1:所以原来的sum[j] - su ...

  7. OpenGL 2D Prefix Sum 2维前缀总和的实例

    OpenGL 2维前缀总和 先上图,再解答. 完整主要的源代码 源代码剖析 先上图,再解答. 完整主要的源代码 #include <vmath.h> #include <shader ...

  8. 牛客网暑期ACM多校训练营(第十场)D Rikka with Prefix Sum (组合数学)

    https://www.nowcoder.com/acm/contest/148/D 题意 一个A数组,初始全为0.现有三种操作,1:给区间[L,R]+w:2:把每个位置的元素变为其前缀和:3:求区间 ...

  9. Codeforces Round #556 (Div. 1Div. 2)

    Codeforces Round #556 (Div. 1&&Div. 2) 题号 题目 知识点 A Stock Arbitraging 贪心 B Tiling Challenge 贪 ...

最新文章

  1. Java之Java程序与虚拟机
  2. boost::is_readable_iterator用法的测试程序
  3. idea快速从dao层跳转到mapper.xml文件的插件
  4. 快速了解Bagging算法
  5. java 中的event_Java中this与event有什么不同
  6. web mysql数据库的持久连接_JavaWeb连接数据库MySQL的操作技巧
  7. window环境配置虚拟主机
  8. 格式要求_课题论文的格式要求
  9. Hadoop中maptask数量的决定因素
  10. python在线编辑器
  11. 体验Windows Mobile 6.5 (模拟器)
  12. 2016年剩一个月规划已将2017年展望
  13. 视频中的I、P、B帧
  14. 教你如何设计ASP网上考试系统
  15. 正则表达式在一个字符串上多次搜索、正则表达式匹配书名等
  16. 等比数列求和python_Python科学计算
  17. 40万奖金 | 阿里云天池第三届数据库性能大赛,广邀英才挑战创新上云
  18. 【原创】samba移植到android流程
  19. 我和数据标注的那些事儿
  20. html5中拦截url,puppeteer 拦截页面请求

热门文章

  1. 分别是什么意思_美国FBA头程:空派/海派分别是什么意思?
  2. android r文件错误,Android R文件丢失异常原因汇总
  3. 人工神经网络_用人工神经网络控制猴子大脑,MIT科学家做到了
  4. python在sql添加数据库_使用Python创建MySQL数据库实现字段动态增加以及动态的插入数据...
  5. (看这一篇就够了)基本数据类型的赋值与引用类型赋值的区别
  6. WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
  7. 未能为服务器,未能为数据库 'TEMPDB' 分配新页
  8. linux无法打开共享对象文件或目录,linux - libmodbus.so.5:无法打开共享对象文件:没有这样的文件或目录 - 堆栈内存溢出...
  9. java编程赋值运算符_(24)赋值运算符
  10. 七十七、React中的propTypes,defaultProps和生命周期函数