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

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

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

 /**********************************************
*** Problem:
*** Author: JKL
*** University: CSUST
*** Team: __Dream
*** Email: 1451108308@QQ.COM
*** 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 ;
}

USACO 3.1 Contact的更多相关文章

  1. USACO 3.2 Contact

    ContactIOI'98 The cows have developed a new interest in scanning the universe outside their farm wit ...

  2. 【USACO 3.1】Contact(01子串按出现次数排序)

    题意:给你一个01字符串,将长度为a到b之间(包含a.b)的子串按照出现次数排序.注意输入输出格式 题解:01子串对应一个二进制,为了区别11和011这样的不同子串,我们把长度也记录下来,官方题解是在 ...

  3. USACO Section 3.1: Contact

    算法简单,写起来遇到些小问题 /* ID: yingzho1 LANG: C++ TASK: contact */ #include <iostream> #include <fst ...

  4. 洛谷P2724 联系 Contact

    P2724 联系 Contact 17通过 86提交 题目提供者该用户不存在 标签 难度普及/提高- 提交  讨论  题解 最新讨论 暂时没有讨论 题目背景 奶牛们开始对用射电望远镜扫描牧场外的宇宙感 ...

  5. USACO 2016 January Contest, Gold解题报告

    1.Angry Cows http://www.usaco.org/index.php?page=viewproblem2&cpid=597 dp题+vector数组运用 将从左向右与从右向左 ...

  6. USACO . Your Ride Is Here

    Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often co ...

  7. 【USACO 3.1】Stamps (完全背包)

    题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...

  8. USACO翻译:USACO 2013 NOV Silver三题

    USACO 2013 NOV SILVER 一.题目概览 中文题目名称 未有的奶牛 拥挤的奶牛 弹簧牛 英文题目名称 nocow crowded pogocow 可执行文件名 nocow crowde ...

  9. USACO翻译:USACO 2013 DEC Silver三题

    USACO 2013 DEC SILVER 一.题目概览 中文题目名称 挤奶调度 农场航线 贝西洗牌 英文题目名称 msched vacation shuffle 可执行文件名 msched vaca ...

随机推荐

  1. C - 剪花布条 (KMP例题)

    一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢?  Input输入中含有一些数据,分别是成对出现的花布条和 ...

  2. Element里el-badge在el-tab里视图不被渲染问题

    我们发现:el-badge绑定的变量是有数据的,但是界面上就是不渲染. 这个时候执行getTodo发现数据已经打印出来,当是视图未发送变化.于是查阅资料:vm.$forceUpdate()示例:迫使 ...

  3. JS:document.documentElement对象的

    document.documentElement.clientWidth 获取浏览器窗口文档显示区域的宽度,不包括滚动条. document.documentElement.clientHeight ...

  4. phpstudy之访问loaclhost显示目录

    phpstudy版本:phpstudy2018 具体操作: 当前版本的默认设置访问网站根目录是不会显示目录的,需要我们设置,其实也很简单,只需两步就可以搞定 1.找到phpstudy目录下的www文件 ...

  5. Python - Python算法之冒泡算法的超简单实现

    [原创]转载请注明作者Johnthegreat和本文链接 冒泡排序在算法中算是最简单也最容易实现的,这里介绍一个非常简单实现的代码: def bubble_sort(ls): for first in ...

  6. 为什么redis是单线程的以及为什么这么快?

    官网的说法 我们先来认真看一下官网的说法.翻译过来大意如下: CPU并不是您使用Redis的瓶颈,因为通常Redis要么受内存限制,要么受网络限制.例如,使用在一般Linux系统上运行的流水线Redi ...

  7. bootstrop日历

    https://blog.csdn.net/cuixiaobo521/article/details/77880633

  8. python学习08排序算法举例

    '''''''''排序算法:前提是所有数按照从小到大的顺序排列.1.冒泡算法将第一数与第二个数比较大小,如果第一个数比第二个数大,则沉底(交换位置,使大数在小数后面,这个过程类似于大泡沉底的过程) ' ...

  9. java关于throw Exception的一个小秘密

    目录 简介 throw小诀窍 总结 java关于throw Exception的一个小秘密 简介 之前的文章我们讲到,在stream中处理异常,需要将checked exception转换为unche ...

  10. springboot中Redis的Lettuce客户端和jedis客户端

    1.引入客户端依赖 <!--jedis客户端依赖--> <dependency> <groupId>redis.clients</groupId> &l ...