usaco Chapter 3 section 3.1 Contact
来源:互联网 发布:淘宝卖家的流程图 编辑:程序博客网 时间:2024/06/03 11:17
/*
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 emission is transmitted by some extraterrestrial form of intelligent life or if it is nothing but the usual heartbeat of the stars.
Help the cows to find the Truth by providing a tool to analyze bit patterns in the files they record. They are seeking bit patterns of length A through B inclusive (1 <= A <= B <= 12) that repeat themselves most often in each day's data file. They are looking for the patterns that repeat themselves most often. An input limit tells how many of the most frequent patterns to output.
Pattern occurrences may overlap, and only patterns that occur at least once are taken into account.
*/
/*
ID: niepeng1
PROB:contact
LANG: C++
*/
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <math.h>
#include <string.h>
#include <stdio.h>
using namespace std;
#define Max1 200010
int way[Max1]={0};
long int cond[20][4916];
struct Node{
int count;//出现频繁度
int data;//位数
int jj;
};
Node tem[20000];
FILE *in,*out;
int cmp(const Node & a,const Node & b){
if(a.count==b.count)//频度相同
{
if(a.data == b.data)//位数相同,比二进制数大小
return a.jj<b.jj;
return a.data<b.data;
}
return a.count>b.count;//位数相同比频度
}
void Display(int count,int data,int j)
{
char a[20]="000000000000000";
a[data]='/0';
while(--data>=0)
{
a[data]=j&1;
j=j>>1;
a[data]+='0';
}
fprintf(out,"%s",a);
}
int main()
{
char rec[Max1];
int i,j,a,b,num,len,k,id,iu,j1;
char cc;
for(i=0;i<20;i++)
for(j=0;j<4915;j++)
{
cond[i][j]=0;
}
in=fopen("contact.in","r");
out=fopen("contact.out","w");
fscanf(in,"%d %d %d",&a,&b,&num);
i=0;
while(fscanf(in,"%c",&cc)!=-1)
{
if(cc!='/n')
rec[i++]=cc;
}
rec[i]='/0';
len=i;
for(k=0;k<=12;){
for(i=0;i<len;i++)
{
way[i]=way[i]<<1;
way[i]+=(rec[i+k]-'0');
if(cond[k+1][way[i]]==0 && k+1 >= a && k+1 <= b)
{
j++;
}
cond[k+1][way[i]]++;
}
k++;
len--;
}
id=pow(2,a);
iu=pow(2,b);
k=0;
for(i=a;i<=b;i++){
for(j=0;j<4915;j++){
if( cond[i][j] >0)
{
tem[k].data=i;//位数
tem[k].count=cond[i][j];
tem[k].jj=j;
k++;
}
}
}
sort(tem,tem+k,cmp);
fprintf(out,"%d/n",tem[0].count);
int kk=0;
for(i=0,j1=0;(i<k) & (j1<num);i++){
Display(tem[i].count,tem[i].data,tem[i].jj);
if( tem[i].count!=tem[i+1].count)
{
if(j1 == num-1 || i == k-1)
{break;}
j1++;
kk=1;
fprintf(out,"/n%d/n",tem[i+1].count);
}
else{
if( j1 == num || kk%6==0)
fprintf(out,"/n");
else
fprintf(out," ");
kk++;
}
}
fprintf(out,"/n");
fclose(in);
fclose(out);
return 0;
}
- usaco Chapter 3 section 3.1 Contact
- USACO-Section 3.1-PROB Contact
- usaco Chapter 3 section 3.1 Agri-Net
- usaco Chapter 3 section 3.1 Humble Numbers
- usaco Chapter 3 section 3.1 Score Inflation
- usaco Chapter 3 section 3.1 Shaping Regions
- usaco Chapter 3 section 3.1 Stamps
- USACO Section 3.1 Contact - AC自动机..
- USACO section 3.1 Contact(AC自动机)
- USACO-Section 3.1 Contact(枚举)
- usaco Chapter 3 section 3.2 Factorials
- usaco Chapter 3 section 3.2 Stringsobits
- usaco Chapter 3 section 3.2 Feed Ratios
- usaco Chapter 3 section 3.2 Magic Squares
- usaco Chapter 3 section 3.2 Sweet Butter
- usaco Chapter 3 section 3.3 Shopping Offers
- usaco Chapter 3 section 3.3 Camelot
- usaco Chapter 3 section 3.3 A game
- c#2.0语法新关键字 partial
- 仿163网盘无刷新多文件上传系统转一下很不错啊
- VC常见编译错误信息集合
- Xenomai屏蔽PWM TIMER0-3的修改
- ASP.NET 2.0 本地化1
- usaco Chapter 3 section 3.1 Contact
- 网络命令速查手册
- Tomcat 编码(配置catalina.bat)
- ASP.NET 2.0 本地化2
- 本博客文章格式说明~
- 程序调试常用API
- 介绍一下和AspNetPager结合的不错的分页方案
- linux 内核源代码目录结构概述
- 常用的八个cmd网络命令