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. cucumber学习索引

    Cucumber(1) —— 环境配置 Cucumber(2)——目录结构以及基本语法 Cucumber(3)——命令以及日志 Cucumber(4)——jenkins的集成

  2. iOS中点击事件失效的解决办法

    解决办法有 2种可供选择: 将目标​元素换成 <a> 或者 button 等可点击的​元素 ​给​目标元素加一条样式规则 cursor : pointer;

  3. PHP 将字符串转换为字符集格式UTF8/GB2312/GBK 函数iconv()

     iconv()介绍 iconv函数可以将一种已知的字符集文件转换成另一种已知的字符集文件 iconv('要转化的格式',‘转化后的格式’,‘转化的数据’); 但是转化是经常出错,一般需要在转成的编码 ...

  4. Python爬虫---爬取腾讯动漫全站漫画

    目录 操作环境 网页分析 明确目标 提取漫画地址 提取漫画章节地址 提取漫画图片 编写代码 导入需要的模块 获取漫画地址 提取漫画的内容页 提取章节名 获取漫画源网页代码 下载漫画图片 下载结果 完整 ...

  5. pytorch 矩阵数据增加维度unsqueeze和降低维度squeeze

    增加一个维度 out.unsqueeze(-1) 降低一个维度 out.squeeze(dim=1)

  6. Python之小型信息管理系统

    #Author:msq #Time:2019/11/16 import re import os filename = "person.txt" def menu(): #输出菜单 ...

  7. 杂园日记-H5-IOS-Android混合开发

    1.js 调用 原生API iOS: window.webkit.messageHandlers.yourFunName.postMessage({"1":"3" ...

  8. [机器学习实战-Logistic回归]使用Logistic回归预测各种实例

    目录 本实验代码已经传到gitee上,请点击查收! 一.实验目的 二.实验内容与设计思想 实验内容 设计思想 三.实验使用环境 四.实验步骤和调试过程 4.1 基于Logistic回归和Sigmoid ...

  9. 20199308《Linux内核原理与分析》第十一周作业

    缓冲区溢出漏洞实验 实验步骤 一.初始设置 1.Ubuntu 和其他一些 Linux 系统中,使用地址空间随机化来随机堆(heap)和栈(stack)的初始地址,这使得猜测准确的内存地址变得十分困难, ...

  10. Vue3.0新版API之composition-api入坑指南

    关于VUE3.0 由于vue3.0语法跟vue2.x的语法几乎是完全兼容的,本文主要介绍了如何使用composition-api,主要分以下几个方面来讲 使用vite体验vue3.0 composit ...