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. ...
随机推荐
- 【转】有rand7(可以随机生成1到7的数据的随机函数),如何产生rand10(随机产生1-10的数)
今天停GJP说在面试的时候碰到了一道这样的题目:有rand7(可以随机生成1到7的数据的随机函数),如何产生rand10(随机产生1-10的数) 感觉很有意思,找到了这篇博客,感觉解法很好玩,转载在这 ...
- JavaWeb_初识监听器Listener
监听器(listener):对项目起到监听的作用,它能感知到包括request(请求域),session(会话域)和applicaiton(应用程序)的初始化和属性的变化 监听器是Servlet规范中 ...
- 数据重塑图解—Pivot, Pivot-Table, Stack and Unstack
Pivot pivot函数用于创建一个新的派生表,该函数有三个参数:index, columns和values.你需要在原始表中指定这三个参数所对定的列名,接下来pivot函数会创建一个新的表格,其中 ...
- 剑指offer:关于复制构造函数
1:首先参看代码: #include "stdafx.h" #include "iostream" using namespace std; class A { ...
- 将文件夹上传到FTP服务器,遍历上传,,,文件夹不能直接上传到FTP服务器上。。。
<? $ftp_ip = "FTP"; $ftp_user = "user"; $ftp_pwd = "password"; $con ...
- leetcode-easy-others-20 Valid Parentheses
mycode 95.76% class Solution(object): def isValid(self, s): """ :type s: str :rtype ...
- PADS常用画板过程
转载:PADS LAYOUT的一般流程 http://www.doc88.com/p-9129306856292.html https://wenku.baidu.com/view/cc4e0b338 ...
- web开发(十) struts2之图片验证码
1.配置前端页面 <!-- 验证码--> <div class="form-group " style="padding-left: 9%;" ...
- 阶段3 2.Spring_06.Spring的新注解_3 AnnotationConfigApplicationContext的使用
目前这个配置文件除了导约束就没有其他的内容了. 删除这个bean.xml文件 但是测试类里面还是读取的xml的信息 注解 查看ApplicationContext的 关系图 查看实现类的实现类 之前我 ...
- 远程连接elasticsearch遇到的问题
本文转自:https://blog.csdn.net/xuchuangqi/article/details/78989940 1.首先要远程连接就要把配置文件的network.host: 改为 net ...