大意: 给定序列, 求划分为两个非空等差序列.

暴搜, 加个记忆化剪枝.

#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 (暴力)的更多相关文章

  1. CodeForces 670D1 暴力或二分

    今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1   This problem is given in two versions that diff ...

  2. 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 ...

  3. Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力

    Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...

  4. 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 ...

  5. 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 ...

  6. codeforces 691F 暴力

    传送门:https://codeforces.com/contest/691/problem/F 题意:给你n个数和q次询问,每次询问问你有多少对ai,aj满足ai*aj>=q[i],注意 a* ...

  7. Two progressions CodeForce 125D 思维题

    An arithmetic progression is such a non-empty sequence of numbers where the difference between any t ...

  8. Vicious Keyboard CodeForces - 801A (暴力+模拟)

    题目链接 题意: 给定一个字符串,最多更改一个字符,问最多可以有多少个“VK”子串? 思路: 由于数据量很小,不妨尝试暴力写.首先算出不更改任何字符的情况下有多个VK字串,然后尝试每一次更改一个位置的 ...

  9. (CodeForces 548B 暴力) Mike and Fun

    http://codeforces.com/problemset/problem/548/B Mike and some bears are playing a game just for fun. ...

随机推荐

  1. jQuery_插入操作

    jQuery的插入方法有很多,有内部插入,也有外部插入,每个插入方式里面还有很多种,本文一一介绍,注释在代码里,直接上代码: 代码: <!DOCTYPE html> <html> ...

  2. layui button按钮点击导致页面重新刷新的解决方案

    网友的解决方法:(我只想说,放屁!!!而且大家都在复制粘贴,浪费时间) 方法一:将button标签更换为input <input class="layui-btn test" ...

  3. 【转】稳定婚姻问题(Stable Marriage Problem)

    转自http://www.cnblogs.com/drizzlecrj/archive/2008/09/12/1290176.html 稳定婚姻是组合数学里面的一个问题. 问题大概是这样:有一个社团里 ...

  4. web服务基础

    Web服务基础 用户访问网站的基本流程 我们每天都会用web客户端上网,浏览器就是一个web客户端,例如谷歌浏览器,以及火狐浏览器等. 当我们输入www.oldboyedu.com/时候,很快就能看到 ...

  5. spark 笔记 10: TaskScheduler相关

    任务调度器的接口类.应用程序可以定制自己的调度器来执行.当前spark只实现了一个任务调度器) )))))val createTime = System.currentTimeMillis()clas ...

  6. linux上的syslog

    在centos上,syslog其实是rsyslog,对应的配置文件为/etc/rsyslog.conf,守护进程为:/etc/rsyslog.d --------------------------- ...

  7. Linux高级调试与优化——用户态堆

    内存问题是软件世界的住房问题 嵌入式Linux系统中,物理内存资源通常比较紧张,而不同的进程可能不停地分配和释放不同大小的内存,因此需要一套高效的内存管理机制. 内存管理可以分为三个层次,自底向上分别 ...

  8. Grunt打包Electron,生成exe的安装包

    在之前的博客:3.electron打包生成exe文件 我们已经得到了electron打包好的应用了,目录如下,但是我们如何整合成一个安装程序,发给客户使用呢? 我们可以使用grunt-electron ...

  9. 【转】How-to: Enable User Authentication and Authorization in Apache HBase

    With the default Apache HBase configuration, everyone is allowed to read from and write to all table ...

  10. nodejs之流数据读取与写入

    1.(fs.createReadStream)当文件比较大时,建议使用文件流读取,不会出现卡顿现象,demo如下. const fs = require('fs'); //流的方式读取文件 var r ...