康拓展开/逆展开 模板

#include<algorithm>
#include<iostream>
#include<cstdio>
#define int long long using 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;
}

[BZOJ] 3301: [USACO2011 Feb] Cow Line的更多相关文章

  1. 3301: [USACO2011 Feb] Cow Line

    3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 82  Solved: 49[Submit ...

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

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

  3. BZOJ3301: [USACO2011 Feb] Cow Line

    3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 67  Solved: 39[Submit ...

  4. [USACO2011 Feb] Cow Line

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

  5. BZOJ 1631: [Usaco2007 Feb]Cow Party( 最短路 )

    这道题和蔡大神出的今年STOI初中组的第二题几乎一模一样... 先跑一遍最短路 , 再把所有边反向 , 再跑一遍 , 所有点两次相加的最大值即为answer --------------------- ...

  6. BZOJ 1631: [Usaco2007 Feb]Cow Party

    题目 1631: [Usaco2007 Feb]Cow Party Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 491  Solved: 362[Sub ...

  7. BZOJ 3403: [Usaco2009 Open]Cow Line 直线上的牛( deque )

    直接用STL的的deque就好了... ---------------------------------------------------------------------- #include& ...

  8. BZOJ 3446: [Usaco2014 Feb]Cow Decathlon( 状压dp )

    水状压dp. dp(x, s) = max{ dp( x - 1, s - {h} ) } + 奖励(假如拿到的) (h∈s). 时间复杂度O(n * 2^n) ------------------- ...

  9. BZOJ 2274 [Usaco2011 Feb]Generic Cow Protests

    [题解] 很容易可以写出朴素DP方程f[i]=sigma f[j] (sum[i]>=sum[j],1<=j<=i).  于是我们用权值树状数组优化即可. #include<c ...

随机推荐

  1. 7、python数据类型之集合set

    数据类型之集合setset 不允许重复的无序集合,不能通过下标取值,因为无序1.创建   创建空集合   s ={} 默认类型为字典,所以不是空集合,空集合如下   s = set()   s = { ...

  2. [Leetcode]011. Container With Most Water

    public class Solution { public int maxArea(int[] height) { int left = 0, right = height.length - 1; ...

  3. BigDecimal默认用四舍五入方式

    import java.math.BigDecimal; target.setWeight(source.getWeight().setScale(3, BigDecimal.ROUND_HALF_U ...

  4. Jquery 实现表单验证,所有验证通过方可提交

    1. [代码]Jquery 实现表单验证,所有验证通过方可提交 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ...

  5. learn_tmp

    // 4.1构造映射val scores = Map("Alice" -> 10, "Bob" -> 3, "Cindy" -& ...

  6. FTP服务器windows配置

    1.配置IIS Web的FTP站点 1.1 打开iis管理器(方法很多,这里我们用命令) Win+r中输入:inetmgr 1.2 新建FTP站点 1.2.1 新建FTP服务器根目录文件夹 1.2.2 ...

  7. fiddle

    web开发中Chrome.IE.firefox等浏览器都自带提供了插件帮助开发者跟踪http数据,在手机客户端怎么实现http数据抓包呢?Fiddler可以实现真机调试抓包.Fiddler支持Any ...

  8. new 和 delete 用法

    1. 这两个其实是 C++ 语言标准库的库函数,原型分别如下: void *operator new(size_t); //allocate an object void *operator dele ...

  9. 【Linux】Xshell-Linux常用命令

    (1)命令ls——列出文件 ls -la 给出当前目录下所有文件的一个长列表,包括以句点开头的“隐藏”文件 ls a* 列出当前目录下以字母a开头的所有文件 ls -l *.doc 给出当前目录下以. ...

  10. 浅析System.Console.WriteLine()

    浅析System.Console.WriteLine() Writeline()函数的功能向 StreamWriter 类写入指定字符串和一行字符,共有19个重载,其与Write()函数的主要区别在于 ...