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. ...
随机推荐
- windows下kafka配置入门 示例
实验平台与软件: 操作系统:windows7 32 位 java 开发包: jdk1.8.0_144 集群: zookeeper-3.3.6 消息队列: kafka_2.11-0.11.0.1 安装 ...
- 解决新建Maven项目webapp-- index.jsp报错
现在,随着项目开发的不断增长,项目变得庞大,jar包管理起来也很费时.使用maven工程可以很轻松的帮助我们管理jar包,省时. 今天,我在公司电脑新建的maven工程,新建完后 index.jsp报 ...
- java 多线程为何会出现无法捕获异常的现象?
提出问题: 很多Java初学者在初学java 多线程的时候可能会看到如下代码: public class ExceptionThread implements Runnable{ @Override ...
- SQLite 数据类型与C#数据类型对应表
SQLite 数据类型 C# 数据类型 BIGINT Int64 BIGUINT UInt64 BINARY Binary BIT Boolean 首选 BLOB Binary ...
- 一些 postman
听了:https://v.qq.com/x/page/f0816egftuw.html npm 是 node package manager, Nodejs下的包管理器.安装完 nodejs 后(no ...
- leetcode 121买卖股票的最佳时机I
从下标1开始,维护两个变量,一个是0~i-1中的最低价格low,一个是当前的最高利润res;先更新最高利润,在更新最低价格:应用了贪心算法的基本思想,总是选择买入价格最低的股票,代码如下: 具有最优子 ...
- OpenStack RPM Sample 解析
目录 文章目录 目录 前言 RPM 打包环境安装 RPM 打包流程 OpenStack RPM SPEC Sample RPM 升级/回退 前言 软件功能升级,尤其是 Python 这类解析型语言的软 ...
- 无界面上(linux)运行jmeter(2)
无界面上(linux)运行jmeter 1.先在bin目录下面创建一个文件夹testplan用来存放脚本(.jmx文件),然后在创建一个文件夹testresult用来存放脚本执行后的结果(.jtl文件 ...
- CentOS mysql安装
MySQL For Excel 1.3.5MySQL for Visual Studio 1.2.5MySQL Fabric 1.5.6 & MySQL Utilities 1.5.6Conn ...
- jQuery 获得内容
地址 text() - 设置或返回所选元素的文本内容 html() - 设置或返回所选元素的内容(包括 HTML 标记) val() - 设置或返回表单字段的值 一.text() html() &l ...