AtCoder Grand Contest 001 D - Arrays and Palindrome
题目传送门:https://agc001.contest.atcoder.jp/tasks/agc001_d
题目大意:
现要求你构造两个序列\(a,b\),满足:
- \(a\)序列中数字总和为\(N\)
- \(b\)序列中数字总和为\(N\)
- \(a,b\)中包含的数都是正整数
- 满足以下两个条件的序列,所有元素必定相同
- 最开始的\(a_1\)个元素是回文的,之后的\(a_2\)个元素是回文的,...,之后的\(a_n\)个元素是回文的
- 最开始的\(b_1\)个元素是回文的,之后的\(b_2\)个元素是回文的,...,之后的\(b_n\)个元素是回文的
现在已知\(a\)为给定序列\(A\)的排列,请求出一组可能的序列\(a,b\);若不存在,则输出\(Impossible\)
又是一个很妙的构(zhi)造(shang)题,如果满足那俩神奇条件,画一下长得就和蚊香一样

多打几个表就能发现,长度为奇数的回文串只能放在队首或队尾,而且超过两个就无解……然后为了扭成一个蚊香样,\(b\)串就需要满足第一个+1,最后一个-1,其余照抄即可
/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
static char buf[1000000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int frd(){
int x=0,f=1; char ch=gc();
for (;ch<'0'||ch>'9';ch=gc()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=gc()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline int read(){
int x=0,f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline void print(int x){
if (x<0) putchar('-'),x=-x;
if (x>9) print(x/10);
putchar(x%10+'0');
}
const int N=1e2;
int A[N+10];
int main(){
int n=read(),m=read(),cnt=0;
for (int i=1;i<=m;i++) A[i]=read(),cnt+=A[i]&1;
if (cnt>2){
printf("Impossible\n");
return 0;
}
for (int i=1;i<=m;i++) if (A[i]&1) swap(A[1]&1?A[m]:A[1],A[i]);
if (m==1){
if (A[1]==1){
printf("1\n1\n1\n");
return 0;
}
printf("%d\n2\n1 %d\n",A[1],A[1]-1);
return 0;
}
for (int i=1;i<=m;i++) printf("%d",A[i]),putchar(i==m?'\n':' ');
printf("%d\n%d ",m-(A[m]==1),A[1]+1);
for (int i=2;i<m;i++) printf("%d ",A[i]);
if (A[m]!=1) printf("%d\n",A[m]-1);
return 0;
}
AtCoder Grand Contest 001 D - Arrays and Palindrome的更多相关文章
- Atcoder Grand Contest 001 D - Arrays and Palindrome(构造)
Atcoder 题面传送门 洛谷题面传送门 又是道思维题,又是道把我搞自闭的题. 首先考虑对于固定的 \(a_1,a_2,\dots,a_n;b_1,b_2,\dots,b_m\) 怎样判定是否合法, ...
- AtCoder Grand Contest 001 C Shorten Diameter 树的直径知识
链接:http://agc001.contest.atcoder.jp/tasks/agc001_c 题解(官方): We use the following well-known fact abou ...
- Atcoder Grand Contest 001 F - Wide Swap(拓扑排序)
Atcoder 题面传送门 & 洛谷题面传送门 咦?鸽子 tzc 来补题解了?奇迹奇迹( 首先考虑什么样的排列可以得到.我们考虑 \(p\) 的逆排列 \(q\),那么每次操作的过程从逆排列的 ...
- AtCoder Grand Contest 001
B - Mysterious Light 题意:从一个正三角形边上一点出发,遇到边和已走过的边则反弹,问最终路径长度 思路:GCD 数据爆long long #pragma comment(linke ...
- [Atcoder Grand Contest 001] Tutorial
Link: AGC001 传送门 A: …… #include <bits/stdc++.h> using namespace std; ; ]; int main() { scanf(& ...
- AtCoder Grand Contest 001 题解
传送门 \(A\) 咕咕咕 const int N=505; int a[N],n,res; int main(){ scanf("%d",&n); fp(i,1,n< ...
- JZOJ5405 & AtCoder Grand Contest 001 F. Permutation
题目大意 给出一个长度为\(n\)的排列\(P\)与一个正整数\(k\). 你需要进行如下操作任意次, 使得排列\(P\)的字典序尽量小. 对于两个满足\(|i-j|>=k\) 且\(|P_i- ...
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
- AtCoder Grand Contest 011
AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...
随机推荐
- Filter注入对象
由于没有在web.xml文件中加上<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter ...
- mac Git本地服务器配置
本文转载至 http://blog.csdn.net/piziliweiguang/article/details/9311791 XCode 默认支持 Git 作为代码仓库,当我们新建一个仓库的 ...
- 20170228 Z_po_send_email
FUNCTION zmm_po_send_email. function zmm_po_send_email. *"------------------------------------- ...
- iOS 在UILabel显示不同的字体和颜色(ios6 and later)
在项目开发中,我们经常会遇到在这样一种情形:在一个UILabel 使用不同的颜色或不同的字体来体现字符串,在iOS 6 以后我们可以很轻松的实现这一点,官方的API 为我们提供了UILabel类的at ...
- 数据库连接池-配置 wallfilter问题解决-UncategorizedSQLException
wallFilter对sql有着严格的校验,会对有风险的sql过滤,抛出异常信息: org.springframework.jdbc.UncategorizedSQLException: ### Er ...
- (C/C++)register关键字
register:这个关键字的作用是请求编译器尽可能的将变量存在CPU内部寄存器中,而不是通过内存寻址访问,以提高效率. 注意是尽可能,不是绝对.一个CPU 的寄存器也就那么几个或几十个,你要是定义了 ...
- Vue : props 使用细节(父组件传递数据给子组件)
props使用细节 在Vue.js中我们可以使用 props 实现父组件传递数据给子组件,下面我们总结一下props的使用细节 1.基础类型检查 2.必填数据 3.默认值 4.自定义验证函数 其中每一 ...
- react native与原生的交互
一.交互依赖的重要组件 react native 中如果想要调用ios 中相关的方法,必须依赖一个重要的组件nativemodules import { NativeModules } from ' ...
- kentico检查当前授权用户,是否为admin角色
https://docs.kentico.com/k11/custom-development/user-internals-and-api/checking-permissions-using-th ...
- 【BZOJ 3223】 文艺平衡树
[题目链接] 点击打开链接 [算法] 本题是splay区间操作的模板题 我们每个点的权值设为”当前在序列中的排名“,根据二叉排序树的性质,这棵树的中序遍历就是当前序列 如果我们要获得一段区间[l,r] ...