康拓展开/逆展开 模板

#include<algorithm>
#include<iostream>
#include<cstdio>
#define int long longusing namespace std;inline int rd(){int ret=0,f=1;char c;while(c=getchar(),!isdigit(c))f=c=='-'?-1:1;while(isdigit(c))ret=ret*10+c-'0',c=getchar();return ret*f;
}
#define space() putchar(' ')
#define nextline() putchar('\n')
void pot(int x){if(!x)return;pot(x/10);putchar('0'+x%10);}
void out(int x){if(!x)putchar('0');if(x<0)putchar('-'),x=-x;pot(x);}const int MAXN = 24;int n,m;int fac[MAXN],a[MAXN];int vis[MAXN],tim;
void ct(int x){ x--;++tim;for(int i=1;i<=n;i++){int cur=x/fac[n-i],j;for(j=1;j<=n;j++){if(vis[j]==tim)continue;if(cur==0) break;cur--;}vis[j]=tim;out(j);space();x%=fac[n-i];}nextline();
}void rct(){int ans=1;for(int i=1;i<=n;i++){int tmp=0;for(int j=i+1;j<=n;j++){if(a[j]<a[i])tmp++;}ans+=fac[n-i]*tmp;}out(ans);nextline();
}signed main(){n=rd();m=rd();fac[0]=1;for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i;char s[MAXN];int x;for(int i=1;i<=m;i++){scanf("%s",s);if(s[0]=='P'){x=rd();ct(x);}else{for(int j=1;j<=n;j++)a[j]=rd();rct();  }}return 0;
}

转载于:https://www.cnblogs.com/ghostcai/p/9866495.html

[BZOJ] 3301: [USACO2011 Feb] Cow Line相关推荐

  1. 康托展开与逆康托展开(bzoj 3301: [USACO2011 Feb] Cow Line)

    康拓展开: 已知序列a1, a2, a3, -, an是1~n的一个排列,求这是1~n全排列中,第几小的排列? ans = ,其中F(i)表示后面n-i个数中比当前小的数的个数 例如 n = 5,序列 ...

  2. 【BZOJ】3301: [USACO2011 Feb] Cow Line(康托展开)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3301 其实这一题很早就a过了,但是那时候看题解写完也是似懂非懂的.... 听zyf神犇说是康托展开, ...

  3. [USACO2011 Feb] Cow Line

    原题链接https://www.lydsy.com/JudgeOnline/problem.php?id=3301 康拓展开和逆展开的模板题. #include<iostream> #in ...

  4. BZOJ 1631: [Usaco2007 Feb]Cow Party【最短路】

    1631: [Usaco2007 Feb]Cow Party [题目描述] 传送门 题解 正向建边,从X开始刷一趟SPFA,然后反向建边,从X刷一趟SPFA,最后两次的答案加和就可以了. 代码如下 # ...

  5. bzoj 1697: [Usaco2007 Feb]Cow Sorting牛排序(置换)

    1697: [Usaco2007 Feb]Cow Sorting牛排序 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 706  Solved: 413 ...

  6. poj 3268 bzoj 1631: [Usaco2007 Feb]Cow Party(最短路)

    1631: [Usaco2007 Feb]Cow Party Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 855  Solved: 613 [Subm ...

  7. bzoj 3403: [Usaco2009 Open]Cow Line 直线上的牛

    3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec  Memory Limit: 128 MB Submit: 206  Solved: 16 ...

  8. 【BZOJ】【3301】【USACO2011 Feb】Cow Line

    康托展开 裸的康托展开&逆康托展开 康托展开就是一种特殊的hash,且是可逆的-- 康托展开计算的是有多少种排列的字典序比这个小,所以编号应该+1:逆运算同理(-1). 序列->序号:( ...

  9. 贪心  POJ - 3617 ​​​​​​​Best Cow Line

    Best Cow Line POJ - 3617 FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of ...

最新文章

  1. 可能是最好的跨域解决方案了
  2. 049_Number对象
  3. Python 各种运行错误(如:SyntaxError :invalid syntax)
  4. 我以为信用卡多就是好事,谁知道……
  5. 【软件质量】代码注释的消极作用
  6. 腾讯广告招人啦,校招优质岗位你不容错过!
  7. 在树莓派上编译安装golang环境
  8. 李炎恢的课程中心(JQUERY视频)
  9. 浏览器插件之ActiveX开发(三)
  10. 分别用精密星历和广播星历计算卫星坐标 -- 对 GNSS 第一次编程的总结
  11. UVA489 刽子手的游戏 Hangman Judge
  12. OpenCV4学习笔记(59)——高动态范围(HDR)成像
  13. 转型只争朝夕!又一火电企业成立新能源公司
  14. ubuntu下 vim工具的安装与使用教程(一)
  15. Android 节操视频播放器jiecaovideoplayer使用
  16. 如何使用微信开发者工具查看Appid以及SECRET
  17. python爬虫爬取微信_Python爬虫爬取微信公众号历史文章全部链接
  18. Invalid vnode type when creating vnode: undefined. vue 3.2版本错误解决
  19. 10.1 黑马Vue电商后台管理系统之完善订单管理模块--加入修改订单模块
  20. 【ceph】ceph osd blacklist cep黑名单|MDS问题分析

热门文章

  1. linux命令详解——tar
  2. 利用SiteMapPath控件做论坛导航
  3. Linux0.11 kernel/exit.c中的free_page_tables()
  4. sql读取 获取子节点 父节点
  5. 管理者每天要做的十件事
  6. JMETER 分布式踩过的坑及填坑方法
  7. Fragment标签页+OKHttp网络请求数据+MVP模式
  8. 计算机课玩游戏检讨500字,上电脑课玩游戏的检讨书范文
  9. linux如何重启syslog服务,Linux syslog服务
  10. activiti前端画图转化_用于Activiti前端显示流程图的插件