计蒜客 39279.Swap-打表找规律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀请赛现场赛重现赛
There is a sequence of numbers of length nn, and each number in the sequence is different. There are two operations:
- Swap the first half and the last half of the sequence (if nn is odd, the middle number does not change)
- Swap all the numbers in the even position with the previous number (the position number starts from 11, and if nn is odd, the last number does not change)
Both operations can be repeated innumerable times. Your task is to find out how many different sequences may appear (two sequences are different as long as the numbers in any one position are different).
Input
Each test file contains a single test case. In each test file:
The first line contains an integer nn, indicating the length of the sequence (1 \le n \le 10000)(1≤n≤10000).
The second line contains nn different numbers.
Output
Output the number of different sequences.
样例输入1复制
3
2 5 8
样例输出1复制
6
样例输入2复制
4
1 2 3 4
样例输出2复制
4
找规律,打个表就发现了。
打表代码也贴下面。
代码:
//L-找规律
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e4+; int a[maxn]; int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
if(n>=&&n<=&&n!=){
printf("%d\n",n);
return ;
}
else if(n==){
printf("%d\n",n*);
return ;
}
if(n%==){
if((n/)%==){
printf("4\n");
}
else{
printf("%d\n",n);
}
}
else{
if((n-)%==){
printf("12\n");
}
else{
printf("%d\n",n*);
}
}
} /*
1
2
6
4
10
6
12
4
18
10
12
4
26
14
12
4
34
18
12
4
*/ /*
打表找规律
打表的代码 #include<bits/stdc++.h>
using namespace std;
const double PI=acos(-1.0);
const int maxn=1e5+10; char a[maxn]; int main()
{
for(int k=1;k<=20;k++){
int n=k;
memset(a,0,sizeof(a));
for(int i=1;i<=n;i++){
a[i]='a'+i-1;
}
int num=0;
int cnt=50;
map<string,int> mp;
string s;
while(cnt--){
for(int i=1;i<n;i+=2){
swap(a[i],a[i+1]);
}
s.clear();
for(int i=1;i<=n;i++){
s+=a[i];
}
if(mp[s]==0) num++,mp[s]=1;
int ret;
if(n%2==1) ret=n/2+1;
else ret=n/2;
for(int i=1;i<=n/2;i++){
swap(a[i],a[i+ret]);
}
s.clear();
for(int i=1;i<=n;i++){
s+=a[i];
}
if(mp[s]==0) num++,mp[s]=1;
}
cout<<num<<endl;
}
} */
计蒜客 39279.Swap-打表找规律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀请赛现场赛重现赛的更多相关文章
- 计蒜客 39272.Tree-树链剖分(点权)+带修改区间异或和 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest E.) 2019ICPC西安邀请赛现场赛重现赛
Tree Ming and Hong are playing a simple game called nim game. They have nn piles of stones numbered ...
- 计蒜客 39280.Travel-二分+最短路dijkstra-二分过程中保存结果,因为二分完最后的不一定是结果 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest M.) 2019ICPC西安邀请赛现场赛重现赛
Travel There are nn planets in the MOT galaxy, and each planet has a unique number from 1 \sim n1∼n. ...
- 计蒜客 39270.Angel's Journey-简单的计算几何 ((The 2019 ACM-ICPC China Shannxi Provincial Programming Contest C.) 2019ICPC西安邀请赛现场赛重现赛
Angel's Journey “Miyane!” This day Hana asks Miyako for help again. Hana plays the part of angel on ...
- 计蒜客 39268.Tasks-签到 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest A.) 2019ICPC西安邀请赛现场赛重现赛
Tasks It's too late now, but you still have too much work to do. There are nn tasks on your list. Th ...
- 计蒜客31452 Supreme Number(找规律)
A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying ...
- 计蒜客 28315.Excellent Engineers-线段树(单点更新、区间最值) (Benelux Algorithm Programming Contest 2014 Final ACM-ICPC Asia Training League 暑假第一阶段第二场 E)
先写这几道题,比赛的时候有事就只签了个到. 题目传送门 E. Excellent Engineers 传送门 这个题的意思就是如果一个人的r1,r2,r3中的某一个比已存在的人中的小,就把这个人添加到 ...
- 计蒜客 成绩统计 (Hash表)
链接 : Here! 思路 : 如果用 $STL$ 的 $map$ 或者是使用 $unordered\underline{}map$ 的话是会 $T$ 的, 所以得手写一个 $hash表$. 其实这个 ...
- 最短路+找规律 Samara University ACM ICPC 2016-2017 Quarterfinal Qualification Contest L. Right Build
题目链接:http://codeforces.com/gym/101149/problem/L 题目大意:有n个点(其实是n+1个点,因为编号是0~n),m条有向边.起点是0,到a和b两个节点,所经过 ...
- 计蒜客 A1607 UVALive 8512 [ACM-ICPC 2017 Asia Xi'an]XOR
ICPC官网题面假的,要下载PDF,点了提交还找不到结果在哪看(我没找到),用VJ交还直接return 0;也能AC 计蒜客题面 这个好 Time limit 3000 ms OS Linux 题目来 ...
随机推荐
- Kafka重启出错:Corrupt index found
日志记录 FATAL Fatal error during KafkaServerStable startup. Prepare to shutdown (kafka.server.KafkaServ ...
- C# vb .net实现装饰边框效果滤镜
在.net中,如何简单快捷地实现Photoshop滤镜组中的装饰边框效果呢?答案是调用SharpImage!专业图像特效滤镜和合成类库.下面开始演示关键代码,您也可以在文末下载全部源码: 设置授权 第 ...
- Golang slice和map的申明和初始化
1 前言 仅供记录使用. 2 代码 /** * @Author: FB * @Description: * @File: SliceMapInit.go * @Version: 1.0.0 * @Da ...
- visual studio 2015 开发时常见问题的解决方案
1.visual studio 2015 用printf函数打印时来不及看结果窗口就关闭 方案一 在所写的代码后面,加上system("PAUSE"); 如下:
- AVI文件格式
AVI文件采用的是RIFF文件结构方式.波形音频wave,MIDI和数字视频AVI都采用这种格式存储. AVI文件的整体结构如下图所示 构造RIFF文件的基本单元叫做数据块(Chunk),每个数据块包 ...
- pandas-11 TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely错误解决方法
pandas-11 TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be sa ...
- 采用__call__ 实现装饰器模式
装饰器模式在实现中也是很常见的:比如手机贴膜,手机壳 都是为了给手机增加一些额外功能 增加耐操 装饰器模式的本质就是对对象二次包装,赋额外功能 __call__ __call__是python魔术方法 ...
- java基本结构
前言 Java文件的运行过程: 1,javac.exe:编译器 2,java.exe:解释器 微软shell下运行实例: C:\Users\Administrator>cd D:\文档\JAVA ...
- spring 中的 bean 是线程安全的吗?
spring 中的 bean 是线程安全的吗? Spring 不保证 bean 的线程安全. 默认 spring 容器中的 bean 是单例的.当单例中存在竞态条件,即有线程安全问题.如下面的例子 计 ...
- 如何选择优秀的APS系统供应商?问自己这几个问题!
高级的计划和排程和生产排程软件的好处是巨大的.然而,生产排程软件不是商品,尚不能保证您选择的任何高级的计划和排程软件能满足您的所有需求. 那么,我们来谈谈如何选择适合你的公司最好的生产排程软件.这需要 ...