西安邀请赛-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 ...
随机推荐
- SQL Server代码的一种学习方法
使用SQL Server Management Studio的操作过程中,界面上方都可以生成sql脚本代码. 如新建数据库时: CREATE DATABASE [db_New] ON PRIMARY ...
- jQuery.getJSON(url, [data], [callback])
jQuery.getJSON(url, [data], [callback]) 概述 通过 HTTP GET 请求载入 JSON 数据. 在 jQuery 1.2 中,您可以通过使用JSONP形式的回 ...
- Javascript你必须要知道的知识点
1.使用 typeof bar === "object" 判断 bar 是不是一个对象有神马潜在的弊端?如何避免这种弊端? 使用 typeof 的弊端是显而易见的(这种弊端同使用 ...
- 9.一次简单的Web作业
Web作业 <!DOCTYPE html> <!-- 作业描述:由于引用了JQuery库,所以请在联网的时候打开该页面. 本次作业是在上次作业的基础上的进一步完善,上次作业页面预留的 ...
- K 短路
这种东西到现在才学-- 考虑 \(T\) 为根的最短路树,一条路径一定是树上边和非树边交错. 我们只管非树边,对于一条路径,非树边构成一个序列 \(L\),相邻两条路径 \(\left(u_1,v_1 ...
- apt-get build-dep命令详解
apt-get build-dep命令详解 - 星星之火的Blog - CSDN博客 https://blog.csdn.net/starflame/article/details/7416311 ...
- ETL-拉链算法-带删除的拉链算法
truncate table CUST;truncate table TAG_CUST; truncate table vt_inc;truncate table vt_new; insert int ...
- nmap脚本nse的使用
nmap脚本(nse)使用总结 0x01 nmap按脚本分类扫描 nmap脚本主要分为以下几类,在扫描时可根据需要设置--script=类别这种方式进行比较笼统的扫描: auth: 负责处理鉴权证书( ...
- koa 基础(九) ejs 模板引擎的使用
1.app.js /** * ejs 模板引擎的使用: * 1.npm install koa-views --save * 2.npm install ejs --save * 3.var view ...
- WOE1-Feature Selection 相关:一个计算WOE和Information Value的python工具
python信用评分卡建模(附代码,博主录制) https://study.163.com/course/introduction.htm?courseId=1005214003&utm_ca ...