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. CSS块级元素、内联元素概念[转]

    CSS文档流与块级元素(block).内联元素(inline),之前翻阅不少书籍,看过不少文章, 看到所多的是零碎的CSS布局基本知识,比较表面.看过O'Reilly的<CSS权威指南>, ...

  2. Spring.net 在aps.net Web的配置复习

    1.引入程序集Spring.Core,CommonLogging,Spring.Web 2.Web.Config的配置 <?xml version="1.0" encodin ...

  3. SNP芯片的原理

    Illumina的SNP芯片原理 Illumina的SNP生物芯片的优势在于: 第1,它的检测通量很大,一次可以检测几十万到几百万个SNP位点 第2,它的检测准确性很高,它的准确性可以达到99.9%以 ...

  4. Win10安装Mongodb,并配置成服务

    好吧,今天突然发现新买的surface上没有安装mongodb,然后想着安装一下,顺便记录一下,虽说安装过程很简单 一:下载安装,然后拷贝到C盘根目录,这个就不多说了,比QQ都简单. 二:把bin文件 ...

  5. git post-receive 待验证的代码

    使用 git post-receive 钩子部署服务端代码 本站文章除注明转载外,均为本站原创或者翻译. 本站文章欢迎各种形式的转载,但请18岁以上的转载者注明文章出处,尊重我的劳动,也尊重你的智商: ...

  6. windows在python基础上安装pip

    首先你必须已经安装了python,并且配置好环境 键入pip 复制https://bootstrap.pypa.io/get-pip.py的内容并创建get-pip.py文件(该文件的内容就是刚刚复制 ...

  7. Linq实战 之 Linq to Sql及Entity Framework操作详解

    Linq实战 之 Linq to Sql及Entity Framework操作详解 一:linq to db的框架 1. linq to sql 2. linq to ado.net entity f ...

  8. c#进阶之浅析委托和事件

    何为委托 加了delegate关键字,没有方法体{}的方法模版(方法列表);委托是一种类型 public void Write() { //TODO } //加上关键字delegate,去掉方法体{} ...

  9. ZKEACMS 模板组件扩展

    前言 如果你还不知道ZKEACMS,不妨先了解一下. ASP.NET MVC 开源建站系统 ZKEACMS 推荐,从此网站“拼”起来 官方地址:http://www.zkea.net/zkeacms ...

  10. django drf GenericAPIView和ListAPIView

    drf提供了更快捷的查询方法ListModelMixin+GenericAPIView,和ListAPIView 1.ListModelMixin+GenericAPIView from django ...