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 ...
随机推荐
- 洛谷 P2569[SCOI2010]股票交易(动规+单调队列)
//只能写出裸的动规,为什么会有人能想到用单调队列优化Orz 题目描述 最近lxhgww又迷上了投资股票,通过一段时间的观察和学习,他总结出了股票行情的一些规律. 通过一段时间的观察,lxhgww预测 ...
- [SoapUI] 在某个测试步骤下面增加Script Assertion,运用 messageExchange 获取response content
import com.eviware.soapui.support.GroovyUtils import com.eviware.soapui.support.XmlHolder import org ...
- jdk1.7 环境变量配置
Windows系统中设置环境变量如下图右击“我的电脑”,选择“属性”. 点击“高级”选项卡,选择“环境变量”. 在“系统环境变量”中设置上面提到的3个环境变量,如果变量已经存在就选择“编辑”,否则选 ...
- 线段树 - 3264 Balanced Lineup
大略的的看了线段树的定义然后就开始练手, 可能很多地方可以优化, 仅供参考. 徘徊在AC的边缘, 提交代码要把cout/cin 缓存 printf/scanf 刚好能过. #include <i ...
- git 进阶操作
1.blame git blame +文件名,可以查看到某个文件每一行最近一次是由谁编辑修改的.-L 22,33 选项可以制定 2.bisect 开始git bisect: $ git bisec ...
- centos7用fdisk进行分区
1.查看分区信息:fdisk -l 从上面可以看到,/dev/sdb分区还没有使用,现在将其划分成2个10G的分区. 2.执行:fdisk /dev/sdb 1):fdisk命令参数 p:打印分区表. ...
- git hook 自动部署
1. 当前虚拟站点根目录的 .git/ 权限 2. 当前项目裸仓库创建 hooks/post-receive 文件,并给予x 的权限 3. 复制如下内容 #!/bin/sh unset $(git r ...
- CoderForces 518D Ilya and Escalator (期望DP)
题意:给定 n 个人,在每一时刻一个人进入地铁的概率是 p,站着不动的概率是 1-p,然后问你 t 时间地铁里有多少人. 析:很明显这是一个期望DP,用d[i][j]表示 i 时刻 j 个人进入地铁的 ...
- Linux内核版本
在Linux中找到/usr/src/kernels/目录,该目录下面有一个系统内核文件 例如:2.6.32-431.11.2.el6.x86_64 Linux内核版本规则 Linux内核版本有三组数字 ...
- STS 闪退
# # A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ILLEGAL_INSTRUCTI ...