Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)
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(思维)的更多相关文章
- Codeforces Round #556 (Div. 1)
Codeforces Round #556 (Div. 1) A. Prefix Sum Primes 给你一堆1,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 ...
- Codeforces Round #556 (Div. 2)-ABC(这次的题前三题真心水)
A. Stock Arbitraging 直接上代码: #include<cstdio> #include<cstring> #include<iostream> ...
- Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)
Codeforces Round #521 (Div. 3) E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...
- 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/ ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 20-list简单使用:
C++list的使用总结及常用list操作 C++中list用法详解 STL中list的erase()方法的使用 listiterator 最近刚刚接触stl的list 学习的时候遇到了很多 ...
- OpenSceneGraph3.4.0+Qt5.6.1MinGW开发环境部署
基本步骤如下描述: Step1:CMake3.10编译openscenegraph3.4.0,生成makefile文件(中间过程可能会涉及到很多三方库,需要下载编译,然后按cm ...
- 以二进制的形式查看文件 Linux之od命令详解
od命令 以二进制的形式查看文件 od -t x1 /usr/local/FT/config/hsm_create.utf8.sql ef bb bf 4c 5f 0d 0a 5f 4e 4e 4f ...
- Rabbit MQ参考资料
https://github.com/ServiceStack/rabbitmq-windows/blob/master/README.md https://github.com/rabbitmq/r ...
- hibernate方言
hibernate中,方言是解决hql翻译成sql保证语法的正确,首先数据库都是支持sql的,不同的数据库会存在一些语法上面的差异.HQL则是基于对象的查询语言,当系统需要数据库的变换时,那么用hib ...
- 2018年计科五班秋季C语言基础课第1次作业
---恢复内容开始--- 1.翻阅邹欣老师博客关于师生关系博客,并回答下列问题: (1)大学和高中最大的不同是没有人天天看着你,请看大学理想的师生关系是?有何感想? 答:我认为是邹欣老师说的健身教练 ...
- dubbo获取错误ip
JAVA_OPTIONS="-Ddubbo.protocol.host=192.168.1.111
- ubuntu虚拟机安装简单pxe服务器
安装环境: vmware2台虚拟机,一台用来做pxe服务器(安装tftp.dhcp.apache2等服务),另一台用来做安装测试. 虚拟机的网络配置:dhcp的虚拟网络为192.168.10.100/ ...
- CodeForces 690C1 Brain Network (easy) (水题,判断树)
题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...
- WSAStartup函数
函数WSAStartup 一.WSAStartup函数 int WSAStartup ( ...