Problem  Codeforces Round #556 (Div. 2) - D. Three Religions

Time Limit: 1000 mSec

Problem Description

Input

Output

Sample Input

5
1 2 1 2 1

Sample Output

1 1 1 2 2

题解:这个题有做慢了,这种题做慢了和没做出来区别不大。。。

  读题的时候脑子里还意识到素数除了2都是奇数,读完之后就脑子里就只剩欧拉筛了,贪心地构造使得前缀和是连续的素数,那实现就很简单了,将素数序列的差分序列求出来,不断凑出差分序列的每个数即可,但是之后想想,除了2 和 3,每个的间隔不都是偶数么,肯定是连续的2呀,费劲算差分序列干什么,直接先放2再放1不就行了(特殊处理一下2 和 3 即可),写着写着还误以为要输出下标,临时改了改,等到测样例的时候发现是输出1、2,暴风哭泣。

 #include <bits/stdc++.h>

 using namespace std;

 #define REP(i, n) for (int i = 1; i <= (n); i++)
#define sqr(x) ((x) * (x)) const int maxn = + ;
const int maxm = + ;
const int maxs = + ; typedef long long LL;
typedef pair<int, int> pii;
typedef pair<double, double> pdd; const LL unit = 1LL;
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const double inf = 1e15;
const double pi = acos(-1.0);
const int SIZE = + ;
const LL MOD = ; LL n;
LL a[maxn];
int cnt[];
LL cnt1, cnt2;
LL tot, prime[maxn];
bool is_prime[maxn]; void Euler()
{
memset(is_prime, true, sizeof(is_prime));
is_prime[] = is_prime[] = false;
for (LL i = ; i < maxn; i++)
{
if (is_prime[i])
{
prime[tot++] = i;
}
for (LL j = ; j < tot && i * prime[j] < maxn; j++)
{
is_prime[prime[j] * i] = false;
if (i % prime[j] == )
{
break;
}
}
}
} vector<int> ans;
queue<int> que[]; int main()
{
ios::sync_with_stdio(false);
cin.tie();
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
Euler();
cin >> n;
int x;
LL sum = ;
for (int i = ; i <= n; i++)
{
cin >> x;
que[x].push(i);
cnt[x]++;
sum += x;
}
cnt1 = cnt[], cnt2 = cnt[];
LL pre = ;
for (int i = ; i < tot && prime[i] <= sum; i++)
{
LL tmp = prime[i] - pre;
LL x = tmp / ;
x = min(x, cnt2);
if (tmp - x * <= cnt1)
{
pre = prime[i];
for (int j = ; j < x; j++)
{
ans.push_back();
}
for (int j = ; j < tmp - x * ; j++)
{
ans.push_back();
}
cnt2 -= x;
cnt1 -= (tmp - x * );
}
}
for(int i = ; i < ans.size(); i++)
{
cout << ans[i] << " ";
}
while(cnt1--)
{
cout << << " ";
}
while(cnt2--)
{
cout << << " ";
}
return ;
}

Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)的更多相关文章

  1. Codeforces Round #556 (Div. 1)

    Codeforces Round #556 (Div. 1) A. Prefix Sum Primes 给你一堆1,2,你可以任意排序,要求你输出的数列的前缀和中质数个数最大. 发现只有\(2\)是偶 ...

  2. Codeforces Round #556 (Div. 2) - D. Three Religions(动态规划)

    Problem  Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 3000 mSec Problem Descripti ...

  3. Codeforces Round #556 (Div. 2)-ABC(这次的题前三题真心水)

    A. Stock Arbitraging 直接上代码: #include<cstdio> #include<cstring> #include<iostream> ...

  4. Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)

    Codeforces Round #521 (Div. 3)  E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...

  5. Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp

    B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...

  6. Codeforces Round #344 (Div. 2) E. Product Sum 维护凸壳

    E. Product Sum 题目连接: http://www.codeforces.com/contest/631/problem/E Description Blake is the boss o ...

  7. Codeforces Round #238 (Div. 2) D. Toy Sum(想法题)

     传送门 Description Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to s ...

  8. Codeforces Round #232 (Div. 2) D. On Sum of Fractions

    D. On Sum of Fractions Let's assume that v(n) is the largest prime number, that does not exceed n; u ...

  9. Codeforces Round #238 (Div. 2) D. Toy Sum 暴搜

    题目链接: 题目 D. Toy Sum time limit per test:1 second memory limit per test:256 megabytes 问题描述 Little Chr ...

随机推荐

  1. 利用SHELL脚本修改当前环境变量

    转自http://www.chinaunix.net/old_jh/7/21485.html 1.背景 ---- 在日常的工作中,为了设置一大批环境变量,我们通常编辑了一个shell程序,包含了多个的 ...

  2. mybaties 一对多关系映射

    背景: 数据库格式如下图所示 现在要统计出在一段时间内dimension_type为op即所有运营商的pv.uv.vv等指标的数组,以便页面显示出每个运营商在该事件段内历史指标曲线图. 分析: 返回的 ...

  3. Netty之Reactor模式

    无论是C++还是Java编写的网络框架,大多数都是基于Reactor模式进行设计和开发,Reactor模式基于事件驱动,特别适合处理海量的I/O事件. 1. 单线程模型 Reactor单线程模型,指的 ...

  4. mysql 用户创建,修改和忘记root密码的操作

    #创建用户CREATE USER 'zzq'@'localhost' IDENTIFIED by 'zzq';#flush privileges 命令本质上的作用是将当前user和privilige表 ...

  5. ADF文件数据结构解析和ADF文件读写

    包括位姿和特征点位置和描述信息. What does an Area Description File (ADF) looks like? 4down votefavorite 2 I'm start ...

  6. javascript 如何创建只能执行一次的事件。

    document.getElementById("myelement").addEventListener("click", handler);   // ha ...

  7. Hadoop的Windows伪分布式学习

    解压hadoop-2.7.2.zip,不是tar.gz,前者是Windows所用的 解压到路径,设置环境变量 HADOOP_HOME=E:\hadoop-2.7.2\ HADOOP_USER_HOME ...

  8. linux bash命令行基本操作

      shell shell 我们叫做壳,我们知道操作系统底层是有一个内核kernel的,内核用来实现所有上层服务,所有上层命令,上层应用所需要的一些基本功能,比如说网络连接,网络通信,比如说键盘驱动, ...

  9. unigui不是单个网页相应的链接,而是整体Web Application,如何把webApp的子功能映射到微信公众号菜单?

    只需要用UniApplication.Parameters.Values[‘xxx’]读取url的参数然后调用就可以 例如:要打开公众号菜单的取样送检指南查询模块,在自定义菜单设定:http://ww ...

  10. log4net 入门使用

    log4net 是dotnet平台下的一个日记记录组件. 一  NuGet中安装log4net包: 二 配置log4net.config文件 配置文件内容: <?xml version=&quo ...