USACO 3.1 Contact

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

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

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

  1 /**********************************************
  2 ***    Problem:
  3 ***    Author:        JKL
  4 ***    University:    CSUST
  5 ***    Team:          __Dream
  6 ***    Email:          [email protected]
  7 ***    My Blog:        http://www.cnblogs.com/jklongint/
  8 ***********************************************/
  9 //===================================================
 10 #include <iostream>
 11 #include <fstream>
 12 #include <sstream>
 13 #include <iomanip>
 14 #include <cstdio>
 15 #include <cstdlib>
 16 #include <cmath>
 17 #include <cassert>
 18 #include <numeric>
 19 #include <ctime>
 20 #include <algorithm>
 21 #include <cstring>
 22 #include <string>
 23 #include <vector>
 24 #include <queue>
 25 #include <map>
 26 #include <stack>
 27 #include <list>
 28 #include <set>
 29 #include <bitset>
 30 #include <deque>
 31 using namespace std;
 32 //---------------------------------------------------
 33 #define mem(a,b) memset(a,b,sizeof(a))
 34 #define GO cout<<"HelloWorld!"<<endl
 35 #define Case(x) cout<<"Case "<<x<<":"
 36 #define foru(i,n) for(int i=1; i <= n; i++)
 37 #define ford(i,n) for(int i = n; i >= 1; i--)
 38  #define fin freopen("input.txt","r",stdin);
 39  #define fout freopen("output.txt","w",stdout)
 40 #define lson  l, m, rt << 1
 41 #define rson  m + 1, r, rt << 1 | 1
 42
 43 #define sqr(a)  ((a)*(a))
 44 #define abs(a) ((a>0)?(a):-(a))
 45 #define pii pair<int,int>
 46
 47 #define fmax(a,b) max(a,b)
 48 #define fmin(a,b) min(a,b)
 49 #define fmax3(a,b,c)  (fmax(a,fmax(a,b)))
 50 #define fmin3(a,b,c)  (fmin(a,fmin(a,b)))
 51
 52 #define sfi(x) scanf("%d",&x)
 53 #define sfL(x) scanf("%I64d",&x)
 54 #define sfc(x) scanf("%c",&x)
 55 #define sfd(x) scanf("%lf",&x)
 56 #define sfs(x) scanf("%s",x)
 57 #define sfii(a,b) scanf("%d%d",&a,&b)
 58 #define sfLL(a,b) scanf("%I64d%I64d",&a,&b)
 59 #define sfcc(a,b) scanf("%c%c",&a,&b)
 60 #define sfdd(a,b) scanf("%lf%lf",&a,&b)
 61 #define sfss(a,b) scanf("%s%s",a,b)
 62
 63 #define pfi(x) printf("%d",x)
 64 #define pfL(x) printf("%I64d",x)
 65 #define pfs(x) printf("%s",x)
 66 #define pfd(x) printf("%lf",x)
 67 #define pfc(x) print("%c",x)
 68 #define newLine pfs("\n")
 69 #define space pfs(" ")
 70
 71 //--------------------------------------------------------
 72 typedef __int64 LL;
 73 typedef unsigned long long ULL;
 74 //typedef __int64 __LL;
 75 typedef unsigned __int64 __ULL;
 76
 77 typedef vector<int> vi;
 78 typedef vector<LL> vL;
 79 typedef vector<string> vs;
 80 typedef set<int> si;
 81 typedef map<int,int> mii;
 82 typedef map<LL,LL> mLL;
 83 typedef map<string,int> msi;
 84 typedef map<char,int> mci;
 85 //--------------------------------------------------------
 86 const int dx[4]={1,-1,0,0};
 87 const int dy[4]={0,0,1,-1};
 88  const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
 89  const int N6=1000006;
 90  const int N5=100006;
 91  const int N4=10006;
 92  const int N3=1006;
 93  const int N2=106;
 94  const int N=200009;
 95  const int MOD=1000000007;
 96  const LL LMAX=0x7fffffffffffffff;
 97  const LL IMAX=0x3fffffff;
 98  const double PI=3.14159265359;
 99 //--------------------------------------------------------
100 template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
101 template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
102
103 //------------------------------------------------------------
104 struct TreeNode{
105     LL  sum;
106 };
107 struct Node{
108     int id, s;
109 };
110 char sbuf[20];
111 //=================================================================
112 Node node[N4];
113 int cnt[N4],  f[N4];
114 char s[N];
115 int getState(int n, int len)
116 {
117     int c = 1;
118     foru(i, len) c = c * 2 + s[n + i- 1] - 48;
119     return c;
120 }
121 char *getString(int a)
122 {
123     int c = 0;
124     mem(sbuf, 0);
125     while(a > 0){
126         sbuf[c++] = (a & 1) + 48;
127         a = a >> 1;
128     }
129     c--;
130     sbuf[c] = 0;
131     int cc = c / 2, l = 0;
132     c--;
133     foru(i, cc){
134         swap(sbuf[l++], sbuf[c--]);
135     }
136     return sbuf;
137 }
138 int cmp(Node i, Node j)
139 {
140     return i.s > j.s || i.s == j.s && i.id < j.id;
141 }
142 int main()
143 {
144     //fin;
145     //fout;
146     //freopen("contact.in","r",stdin);
147     //freopen("contact.out","w",stdout)
148     int a, b, n;
149     cin>> a>> b>> n;
150     sfs(s);
151     int len = strlen(s);
152     for(int i = len - 1; i >= 0; i--){
153         for(int j = a; j <= b; j++){
154             if(i + j > len)break;
155             int t = getState(i, j);
156             f[t] ++;
157         }
158     }
159     int m = (1 << (b + 1)) - 1, q = b + 1;
160     foru(i, m){
161         node[i].s = f[i];
162         node[i].id = i;
163     }
164     sort(node + 1, node + 1 + m, cmp);
165     //foru(i, m)cout<<node[i].s <<endl;
166     int cnt = 0;
167     foru(i, m){
168         if(node[i].s != node[i-1].s || i == 1){
169             cnt++;
170             if(cnt > n)break;
171             if(i > 1)cout<<endl;
172             cout<<node[i].s<<endl<<getString(node[i].id);
173         }
174         else cout<<" "<<getString(node[i].id);
175     }
176     return 0;
177 }

USACO 3.1 Contact

时间: 2024-11-08 09:02:26

USACO 3.1 Contact的相关文章

*usaco题目分享——Contact

ContactIOI'98 The cows have developed a new interest in scanning the universe outside their farm with radiotelescopes. Recently, they noticed a very curious microwave pulsing emission sent right from the centre of the galaxy. They wish to know if the

USACO 3.2 Contact

ContactIOI'98 The cows have developed a new interest in scanning the universe outside their farm with radiotelescopes. Recently, they noticed a very curious microwave pulsing emission sent right from the centre of the galaxy. They wish to know if the

USACO Training Section 3.1 Contact

P2724 联系 Contact 题目背景 奶牛们开始对用射电望远镜扫描牧场外的宇宙感兴趣.最近,他们注意到了一种非常奇怪的脉冲调制微波从星系的中央发射出来.他们希望知道电波是否是被某些地外生命发射出来的,还是仅仅是普通的的星星发出的 题目描述 帮助奶牛们用一个能够分析他们在文件中记下的记录的工具来找到真相.他们在寻找长度在A到B之间(包含A和B本身)在每天的数据文件中重复得最多的比特序列 (1 <= A <= B <= 12).他们在找那些重复得最多的比特序列.一个输入限制告诉你应输出

USACO contact

题目意思是给你一个01串, 让你找出其中长度为A-B的串的频率, 输出频率最高的N个, 直接用map搞定, 代码如下: /* ID: m1500293 LANG: C++ PROG: contact */ #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <map> #include <iostream> #incl

【USACO 3.1.5】联系

[描述] 奶牛们开始对用射电望远镜扫描牧场外的宇宙感兴趣.最近,他们注意到了一种非常奇怪的脉冲调制微波从星系的中央发射出来.他们希望知道电波是否是被某些地外生命发射出来的,还是仅仅是普通的的星星发出的. 帮助奶牛们用一个能够分析他们在文件中记下的记录的工具来找到真相.他们在寻找长度在A到B之间(含)在每天的数据文件中重复得最多的比特序列 (1 <= A <= B <= 12).他们在找那些重复得最多的比特序列.一个输入限制告诉你应输出多少频率最多的序列. 符合的序列可能会重叠,并且至少出

洛谷 P3133 [USACO16JAN]无线电联系Radio Contact

P3133 [USACO16JAN]无线电联系Radio Contact 题目描述 Farmer John has lost his favorite cow bell, and Bessie the cow has agreed to help him find it! They both fan out and search the farm along different paths, but stay in contact via radio so they can keep in to

COGS 696. [IOI1996][USACO 2.3] 最长前缀

★   输入文件:prefix.in   输出文件:prefix.out   简单对比时间限制:1 s   内存限制:128 MB 描述 USACO 2.3.1 IOI96 在生物学中,一些生物的结构是用包含其要素的大写字母序列来表示的.生物学家对于把长的序列分解成较短的序列(即元素)很感兴趣. 如果一个集合 P 中的元素可以通过串联(元素可以重复使用,相当于 Pascal 中的 “+” 运算符)组成一个序列 S ,那么我们认为序列 S 可以分解为 P 中的元素.元素不一定要全部出现(如下例中B

手动添加arraylist注解类(Contact联系人对象)

因为在Java核心库不支持arraylist xml直接注解,这里可以自己写个小工具类 Contact.java: package com.newer.xml; import java.util.ArrayList; import org.simpleframework.xml.Attribute; import org.simpleframework.xml.Element; import org.simpleframework.xml.ElementList; import org.simp

USACO prefix TrieTree + DP

/* ID:kevin_s1 PROG:prefix LANG:C++ */ #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #include <cstdlib>