http://www.nocow.cn/index.php/Translate:USACO/contact

题目大意:给一个只含0和1的序列,统计每个子序列的重复次数,并按次数递减来输出

考虑子序列时将序列前面加一个'1'然后转化成二进制整数,这样每个子序列与整数一一对应,统计二进制整数出现次数,按要求输出即可(ps:usaco老是喜欢在输出上做文章)代码如下(未提交):

 /**********************************************
*** Problem:
*** Author: JKL
*** University: CSUST
*** Team: __Dream
*** Email: [email protected]
*** My Blog: http://www.cnblogs.com/jklongint/
***********************************************/
//===================================================
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <numeric>
#include <ctime>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <set>
#include <bitset>
#include <deque>
using namespace std;
//---------------------------------------------------
#define mem(a,b) memset(a,b,sizeof(a))
#define GO cout<<"HelloWorld!"<<endl
#define Case(x) cout<<"Case "<<x<<":"
#define foru(i,n) for(int i=1; i <= n; i++)
#define ford(i,n) for(int i = n; i >= 1; i--)
#define fin freopen("input.txt","r",stdin);
#define fout freopen("output.txt","w",stdout)
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1 #define sqr(a) ((a)*(a))
#define abs(a) ((a>0)?(a):-(a))
#define pii pair<int,int> #define fmax(a,b) max(a,b)
#define fmin(a,b) min(a,b)
#define fmax3(a,b,c) (fmax(a,fmax(a,b)))
#define fmin3(a,b,c) (fmin(a,fmin(a,b))) #define sfi(x) scanf("%d",&x)
#define sfL(x) scanf("%I64d",&x)
#define sfc(x) scanf("%c",&x)
#define sfd(x) scanf("%lf",&x)
#define sfs(x) scanf("%s",x)
#define sfii(a,b) scanf("%d%d",&a,&b)
#define sfLL(a,b) scanf("%I64d%I64d",&a,&b)
#define sfcc(a,b) scanf("%c%c",&a,&b)
#define sfdd(a,b) scanf("%lf%lf",&a,&b)
#define sfss(a,b) scanf("%s%s",a,b) #define pfi(x) printf("%d",x)
#define pfL(x) printf("%I64d",x)
#define pfs(x) printf("%s",x)
#define pfd(x) printf("%lf",x)
#define pfc(x) print("%c",x)
#define newLine pfs("\n")
#define space pfs(" ") //--------------------------------------------------------
typedef __int64 LL;
typedef unsigned long long ULL;
//typedef __int64 __LL;
typedef unsigned __int64 __ULL; typedef vector<int> vi;
typedef vector<LL> vL;
typedef vector<string> vs;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<LL,LL> mLL;
typedef map<string,int> msi;
typedef map<char,int> mci;
//--------------------------------------------------------
const int dx[]={,-,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
const int N6=;
const int N5=;
const int N4=;
const int N3=;
const int N2=;
const int N=;
const int MOD=;
const LL LMAX=0x7fffffffffffffff;
const LL IMAX=0x3fffffff;
const double PI=3.14159265359;
//--------------------------------------------------------
template< class T > T gcd(T a, T b) { return (b != ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); } //------------------------------------------------------------
struct TreeNode{
LL sum;
};
struct Node{
int id, s;
};
char sbuf[];
//=================================================================
Node node[N4];
int cnt[N4], f[N4];
char s[N];
int getState(int n, int len)
{
int c = ;
foru(i, len) c = c * + s[n + i- ] - ;
return c;
}
char *getString(int a)
{
int c = ;
mem(sbuf, );
while(a > ){
sbuf[c++] = (a & ) + ;
a = a >> ;
}
c--;
sbuf[c] = ;
int cc = c / , l = ;
c--;
foru(i, cc){
swap(sbuf[l++], sbuf[c--]);
}
return sbuf;
}
int cmp(Node i, Node j)
{
return i.s > j.s || i.s == j.s && i.id < j.id;
}
int main()
{
//fin;
//fout;
//freopen("contact.in","r",stdin);
//freopen("contact.out","w",stdout)
int a, b, n;
cin>> a>> b>> n;
sfs(s);
int len = strlen(s);
for(int i = len - ; i >= ; i--){
for(int j = a; j <= b; j++){
if(i + j > len)break;
int t = getState(i, j);
f[t] ++;
}
}
int m = ( << (b + )) - , q = b + ;
foru(i, m){
node[i].s = f[i];
node[i].id = i;
}
sort(node + , node + + m, cmp);
//foru(i, m)cout<<node[i].s <<endl;
int cnt = ;
foru(i, m){
if(node[i].s != node[i-].s || i == ){
cnt++;
if(cnt > n)break;
if(i > )cout<<endl;
cout<<node[i].s<<endl<<getString(node[i].id);
}
else cout<<" "<<getString(node[i].id);
}
return ;
}
05-11 20:03