标签:break printf use fst cas panel always help 模拟
原题代号:HDU 1027
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1027
原题描述:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8415 Accepted Submission(s):
4955
# include <stdio.h> # include <string.h> # include <stdlib.h> # include <iostream> # include <fstream> # include <vector> # include <queue> # include <stack> # include <map> # include <math.h> # include <algorithm> using namespace std; # define pi acos(-1.0) # define mem(a,b) memset(a,b,sizeof(a)) # define FOR(i,a,n) for(int i=a; i<=n; ++i) # define For(i,n,a) for(int i=n; i>=a; --i) # define FO(i,a,n) for(int i=a; i<n; ++i) # define Fo(i,n,a) for(int i=n; i>a ;--i) typedef long long LL; typedef unsigned long long ULL; int ans[10]={1},num[10],sum,a[1005]; void swap_(int &b,int &c) { int t; t=b,b=c,c=t; } int main() { for(int i=1;i<=8;i++) { ans[i]=ans[i-1]*i; } /* for(int i=1;i<=10;i++) cout<<ans[i]<<endl;*/ int n,m; while(scanf("%d%d",&n,&m)!=EOF) { for(int i=1;i<=n;i++) a[i]=i; mem(num,0); sum=0; while(m>1) { for(int i=8;i>=1;i--) if(m>ans[i]) { m-=ans[i],num[i]++,sum++; break; } } /* cout<<sum<<endl; for(int i=1;i<=8;i++) printf("%2d,,%d\n",i,num[i]);*/ while(sum) { for(int i=8;i>=1;i--) { if(num[i]) { swap_(a[n-i],a[n-i+num[i]]); sort(a+n-i+1,a+n+1); sum-=num[i]; num[i]=0; } } } for(int i=1;i<=n;i++) printf(i==1?"%d":" %d",a[i]); cout<<endl; } return 0; }
HDU 1027 Ignatius and the Princess II
标签:break printf use fst cas panel always help 模拟
原文地址:http://www.cnblogs.com/teble/p/7202771.html