Two progressions CodeForces - 125D (暴力)
大意: 给定序列, 求划分为两个非空等差序列.
暴搜, 加个记忆化剪枝.
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head #ifdef ONLINE_JUDGE
const int N = 3e4+10;
#else
const int N = 111;
#endif int n, d1, d2, c[N], *f = c;
map<int,bool> v1[N], v2[N];
vector<int> a, b; int dfs() {
if (f==c+n) return !b.empty();
if (a.size()<2||*f-a.back()==d1&&!v1[f-c+1].count(d1)) {
a.pb(*f++);
if (a.size()>=2) d1=a[1]-a[0], v1[f-c][d1]=1;
if (dfs()) return 1;
--f, a.pop_back();
}
if (b.size()<2||*f-b.back()==d2&&!v2[f-c+1].count(d2)) {
b.pb(*f++);
if (b.size()>=2) d2=b[1]-b[0], v2[f-c][d2]=1;
if (dfs()) return 1;
--f, b.pop_back();
}
return 0;
} int main() {
scanf("%d", &n);
REP(i,0,n-1) scanf("%d", c+i);
if (dfs()) {
for (auto &&t:a) printf("%d ", t);hr;
for (auto &&t:b) printf("%d ", t);hr;
}
else puts("No solution");
}
Two progressions CodeForces - 125D (暴力)的更多相关文章
- CodeForces 670D1 暴力或二分
今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1 This problem is given in two versions that diff ...
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...
- Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...
- Codeforces Round #425 (Div. 2) Problem B Petya and Exam (Codeforces 832B) - 暴力
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain ...
- codeforces 691F 暴力
传送门:https://codeforces.com/contest/691/problem/F 题意:给你n个数和q次询问,每次询问问你有多少对ai,aj满足ai*aj>=q[i],注意 a* ...
- Two progressions CodeForce 125D 思维题
An arithmetic progression is such a non-empty sequence of numbers where the difference between any t ...
- Vicious Keyboard CodeForces - 801A (暴力+模拟)
题目链接 题意: 给定一个字符串,最多更改一个字符,问最多可以有多少个“VK”子串? 思路: 由于数据量很小,不妨尝试暴力写.首先算出不更改任何字符的情况下有多个VK字串,然后尝试每一次更改一个位置的 ...
- (CodeForces 548B 暴力) Mike and Fun
http://codeforces.com/problemset/problem/548/B Mike and some bears are playing a game just for fun. ...
随机推荐
- python爬取智联招聘职位信息(多进程)
测试了下,采用单进程爬取5000条数据大概需要22分钟,速度太慢了点.我们把脚本改进下,采用多进程. 首先获取所有要爬取的URL,在这里不建议使用集合,字典或列表的数据类型来保存这些URL,因为数据量 ...
- 【转】稳定婚姻问题(Stable Marriage Problem)
转自http://www.cnblogs.com/drizzlecrj/archive/2008/09/12/1290176.html 稳定婚姻是组合数学里面的一个问题. 问题大概是这样:有一个社团里 ...
- C++入门经典-例6.6-字符串复制
1:字符串复制函数strcpy的格式如下: strcpy(字符数组名,字符串) 其作用是把字符串中的字符串复制到字符数组中.需要注意的是,字符串结束标志'\0'也一同被复制. 注意是将后面的内容复制给 ...
- IDEA 无法显示项目目录结构解决
不要去网上看什么乱七八糟的骚教程,一点用都没有.直接按下列步骤操作: 1. 关闭IDEA, 2. 然后删除项目文件夹下的.idea文件夹3. 重新用IDEA工具打开项目
- 套接字之close系统调用
close系统调用用于关闭文件描述符,其系统调用实现如下所示: / * Careful here! We test whether the file pointer is NULL before * ...
- python3笔记七:break和continue语句
一:学习内容 break语句 continue语句 二:break语句 1. 说明 作用:跳出for和while的循环注意:只能跳出距离它最近的那一层循环 2.举例1 for i in range(1 ...
- SQL Server清空数据库中ldf日志文件
USE [master] ALTER DATABASE [Whir_InternalSystem] SET RECOVERY SIMPLE WITH NO_WAIT ALTER DATABASE [W ...
- AC自动机小记
不知不觉这篇博客已经被我咕咕咕了一个月了. 也许我写过AC自动机的博客,但我也不知道我写没写过 前情回顾之\(kmp\) \(kmp\)用来解决一个模式串匹配一个文本串的问题,其思路是设置失配指针,找 ...
- Tensorflow所遇坑
TensorFlow问题: 1.FLAGS._parse_flags()报错AttributeError:_parse_flags 解决: 因为TensorFlow的版本问题了,TensorFlow版 ...
- easyui tree checkbox 单选控制
参考文档:中文网:http://www.jeasyui.net/plugins/185.html easyui-tree的checkbox默认是多选的, 如何控制只能单选一个子节点,看代码: $('# ...