USACO Section 3.1: Contact
算法简单,写起来遇到些小问题
/*
ID: yingzho1
LANG: C++
TASK: contact
*/
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#include <stdio.h>
#include <queue>
#include <cstring>
#include <cmath>
#include <list>
using namespace std;
ifstream fin("contact.in");
ofstream fout("contact.out");
int A, B, N;
string input;
struct fre {
int frequency;
string content;
};
//bool cmp(const int &a, const int &b) {return a > b;}
bool cmp(const fre &a, const fre &b) {
if (a.frequency == b.frequency) {
if (a.content.size() == b.content.size()) return a.content < b.content;
else return a.content.size() < b.content.size();
}
else return a.frequency > b.frequency;
}
int main()
{
fin >> A >> B >> N;
while (!fin.eof()) {
string frag;
getline(fin, frag);
if (!input.size()) input = frag;
else input = input + frag;
}
map<string, int> rec;
for (int len = A; len <= B; len++) {
; cur + len <= input.size(); cur++) {
rec[input.substr(cur, len)]++;
}
}
vector<fre> res;
for (map<string, int>::iterator it = rec.begin(); it != rec.end(); it++) {
fre tmp;
tmp.frequency = it->second;
tmp.content = it->first;
res.push_back(tmp);
}
sort(res.begin(), res.end(), cmp);
;
;
;
while (step <= N && cur < res.size()) {
//cout << endl << "step: " << step << endl;
|| res[cur].frequency != res[cur-].frequency) {
pre = cur;
if (step == N) break;
if (cur) fout << endl;
fout << res[cur].frequency << endl;
fout << res[cur].content;
step++;
}
else {
== ) fout << endl << res[cur].content;
else fout << " " << res[cur].content;
}
cur++;
}
fout << endl;
;
}
USACO Section 3.1: Contact的更多相关文章
- 【USACO 3.1】Contact(01子串按出现次数排序)
题意:给你一个01字符串,将长度为a到b之间(包含a.b)的子串按照出现次数排序.注意输入输出格式 题解:01子串对应一个二进制,为了区别11和011这样的不同子串,我们把长度也记录下来,官方题解是在 ...
- USACO Section 1.3 题解 (洛谷OJ P1209 P1444 P3650 P2693)
usaco ch1.4 sort(d , d + c, [](int a, int b) -> bool { return a > b; }); 生成与过滤 generator&& ...
- USACO Section 3.3: Riding the Fences
典型的找欧拉路径的题.先贴下USACO上找欧拉路径的法子: Pick a starting node and recurse on that node. At each step: If the no ...
- USACO Section 3.3 Camlot(BFS)
BFS.先算出棋盘上每个点到各个点knight需要的步数:然后枚举所有点,其中再枚举king是自己到的还是knight带它去的(假如是knight带它的,枚举king周围的2格(网上都这么说,似乎是个 ...
- [IOI1996] USACO Section 5.3 Network of Schools(强连通分量)
nocow上的题解很好. http://www.nocow.cn/index.php/USACO/schlnet 如何求强连通分量呢?对于此题,可以直接先用floyd,然后再判断. --------- ...
- USACO Section 5.3 Big Barn(dp)
USACO前面好像有类似的题目..dp(i,j)=min(dp(i+1,j),dp(i+1,j+1),dp(i,j+1))+1 (坐标(i,j)处无tree;有tree自然dp(i,j)=0) .d ...
- USACO Section 1.3 Prime Cryptarithm 解题报告
题目 题目描述 牛式的定义,我们首先需要看下面这个算式结构: * * * x * * ------- * * * <-- partial product 1 * * * <-- parti ...
- USACO Section 1.1 Your Ride Is Here 解题报告
题目 问题描述 将字符串转变为数字,字母A对应的值为1,依次对应,字母Z对应的值为26.现在有一个字符串,将其中的每个字符转变为数字之后进行累乘,最终的结果对47求余数. 题目给你两个字符串,其中的字 ...
- USACO Section 1.1-1 Your Ride Is Here
USACO 1.1-1 Your Ride Is Here 你的飞碟在这儿 众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支 ...
随机推荐
- 如何做一个脚本自动打开IE浏览器
打开记事本,输入start iexplore "http://www.baidu.com"这个是打开百度,如果只要打开IE就输入start iexplore然后另存为--保存类型改 ...
- android 开发 socket发送会有部分乱码,串码,伴随着数据接收不完整
场景: 客户端A.B,A向B发送json字符串后紧接着发送文件,B接收到文件后才返回消息. 环境:android.使用的是原始的write 和read (若使用的是writeUTF不会出现此问题.)需 ...
- js分页
今天看了下妙味课堂的教程,写了下关于分页的js代码,写完的感觉就是有点小麻烦,需要很多if判断,思路要清晰 点击预览:http://peng666.github.io/blogs/page <! ...
- BZOJ3874 codevs3361 宅男计划
AC通道1:http://www.lydsy.com/JudgeOnline/problem.php?id=3874 AC通道2:http://codevs.cn/problem/3361/ [题目分 ...
- A*(A星)算法Go lang实现
之前发表一个A*的python实现,连接:点击打开链接 最近正在学习Go语言,基本的语法等东西已经掌握了.但是纸上得来终觉浅,绝知此事要躬行嘛.必要的练手是一定要做的.正好离写python版的A*不那 ...
- jquery的ajax向后台提交时,乱码的解决方案
1. 可以给每个参数加上encodeURIComponent(),然后在后台获得参数后用URLDecoder.decode(string, 'utf-8')解码. 2. 后台不用解码. $.ajax( ...
- C++时间标准库时间time和系统时间的使用
#include <iostream> #include <time.h> #include <stdio.h> #include <windows.h> ...
- Firefly卡牌手游《暗黑世界V1.5》服务器端源码+GM管理后台源码
http://www.9miao.com/content-6-304.html Firefly卡牌手游<暗黑世界V1.5>服务器端源码+GM管理后台源码 关于<暗黑世界V1.5> ...
- 电信SDK Pay函数里面System.out.print 无输出消息
private void Pay(HashMap<String, String> payParams){ System.out.print("----------Pay Dian ...
- asp.net @reqister指令
@register指令通过声明将自定义 ASP.NET 服务器控件添加到页或用户控件中. 1.@register 指令有两种用法如下 <%@ Register tagprefix="t ...