西安邀请赛-L(打表找规律)
题目链接:https://nanti.jisuanke.com/t/39279
题意:给定n个不同的数表示的序列,定义两种操作:1. 交换前一半和后一半(如果有奇数个,则中间的不管)。2. 交换每个偶数位和它之前的数(如果有奇数个,最后一个不管)。问通过这两种操作,可以得到多少个不同的序列。
思路:典型的打表找规律的题,下次比赛吸取教训。打表的代码如下:
#include<cstdio>
using namespace std; int a[],b[];
int n,ans; bool check(){
bool flag=;
for(int i=;i<=n;++i)
if(a[i]!=b[i]){
flag=;
break;
}
return flag;
} int main(){
for(n=;n<=;++n){
int hf=n/;
ans=;
for(int i=;i<=n;++i)
a[i]=i,b[i]=i;
while(){
for(int i=;i<=hf;++i){
int tmp=b[i];
b[i]=b[n-hf+i];
b[n-hf+i]=tmp;
}
if(check()) break;
++ans;
for(int i=;i<=n-;i+=){
int tmp=b[i];
b[i]=b[i+];
b[i+]=tmp;
}
if(check()) break;
++ans;
}
printf("%d:%d\n",n,ans+);
}
return ;
}
然后就可以找到规律了:
n%4==0: ans=4
n%4==1: if(n==1) ans=1
else ans=2*n
n%4==2: ans=n
n%4==3: if(n==3) ans=6
else ans =12
AC代码:
#include<cstdio>
using namespace std; int a[],b[];
int n,ans; bool check(){
bool flag=;
for(int i=;i<=n;++i)
if(a[i]!=b[i]){
flag=;
break;
}
return flag;
} int main(){
for(n=;n<=;++n){
int hf=n/;
ans=;
for(int i=;i<=n;++i)
a[i]=i,b[i]=i;
while(){
for(int i=;i<=hf;++i){
int tmp=b[i];
b[i]=b[n-hf+i];
b[n-hf+i]=tmp;
}
if(check()) break;
++ans;
for(int i=;i<=n-;i+=){
int tmp=b[i];
b[i]=b[i+];
b[i+]=tmp;
}
if(check()) break;
++ans;
}
printf("%d:%d\n",n,ans+);
}
return ;
}
西安邀请赛-L(打表找规律)的更多相关文章
- 计蒜客 39279.Swap-打表找规律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀请赛现场赛重现赛
Swap There is a sequence of numbers of length nn, and each number in the sequence is different. Ther ...
- codeforces#1090 D. New Year and the Permutation Concatenation(打表找规律)
题意:给出一个n,生成n的所有全排列,将他们按顺序前后拼接在一起组成一个新的序列,问有多少个长度为n的连续的子序列和为(n+1)*n/2 题解:由于只有一个输入,第一感觉就是打表找规律,虽然表打出来了 ...
- Tetrahedron(Codeforces Round #113 (Div. 2) + 打表找规律 + dp计数)
题目链接: https://codeforces.com/contest/166/problem/E 题目: 题意: 给你一个三菱锥,初始时你在D点,然后你每次可以往相邻的顶点移动,问你第n步回到D点 ...
- Codeforces Round #493 (Div. 2)D. Roman Digits 第一道打表找规律题目
D. Roman Digits time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- 【ZOJ】3785 What day is that day? ——KMP 暴力打表找规律
转自:http://www.cnblogs.com/kevince/p/3887827.html 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这么一说大家心里肯定有数了吧,“不就是nex ...
- Nowcoder 练习赛 17 C 操作数 ( k次前缀和、矩阵快速幂打表找规律、组合数 )
题目链接 题意 : 给定长度为n的数组a,定义一次操作为: 1. 算出长度为n的数组s,使得si= (a[1] + a[2] + ... + a[i]) mod 1,000,000,007: 2. ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 5753 Permutation Bo (推导 or 打表找规律)
Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- HDU 4861 Couple doubi (数论 or 打表找规律)
Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...
随机推荐
- Python实现telnet命令测试防火墙
Python实现telnet命令测试防火墙 telnet主要用于测试主机端口是否开通 ping主要是用来测试网络是否畅通和主机是否正在使用 使用Python实现Telnet测试主机端口是否开通的功能. ...
- Linux Shell脚本,删除旧文件,保留最新的几个文件
删除某一目录下文件,只保留最新的几个 #!/bin/bash #保留文件数 ReservedNum= FileDir=/home/dev/saas_test/testcases/report/html ...
- Android_(控件)使用AlertDialog实现点击Button显示出多选框
单击"更多"按钮,显示出多选框 运行截图: 程序结构 (本想通过Button中android:background使用drawable资源下的图片作为按钮背景,设计太丑就去掉了Σ( ...
- python-日常用法小记
1.判断是否是数字 math.isnan("a") 2.数学math math.log(x) 3.查看安装路径 import sys print sys.path 4.字符串与日期 ...
- java web过滤器防止未登录进入界面
import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import ja ...
- TCP层close系统调用的实现分析
在调用close系统调用关闭套接字时,如果套接字引用计数已经归零,则需继续向上层调用其close实现,tcp为tcp_close:本文仅介绍tcp部分,前置部分请参考本博关于close系统调用的文章: ...
- js中的事件委托技术
1.什么是事件委托:通俗的讲,时间就是onclick,onmouseover,onmouseout,等就是事件,委托呢,就是让别人来做,这个时间本来是加在某些元素上的,然而你却加到别人身上来做,完成这 ...
- 基于XML的AOP配置(2)-环绕通知
配置方式: <aop:config> <aop:pointcut expression="execution(* com.itheima.service.impl.*.*( ...
- LC 683. K Empty Slots 【lock,hard】
There is a garden with N slots. In each slot, there is a flower. The N flowers will bloom one by one ...
- 依赖注入框架之dagger2
主页: https://github.com/google/dagger 历史 * Dagger1是由Square公司受到Guice(https://github.com/google/guice)启 ...