百度之星2016资格赛D,水题
很简单的题,主要是要用字符串哈希,把字符串处理成整数。接下来可以继续用hash,也可以像我一样用个map就搞定了。
/*
* Author : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
typedef long long LL;
/*
* 输入非负整数
* 支持short、int、long、long long等类型(修改typec即可)。
* 用法typec a = get_int();返回-1表示输入结束
*/
typedef int typec;
typec get_int() {
typec res = , ch;
while (!((ch = getchar()) >= '' && ch <= '')) {
if (ch == EOF)
return -;
}
res = ch - '';
while ((ch = getchar()) >= '' && ch <= '')
res = res * + (ch - '');
return res;
}
//输入整数(包括负整数,故不能通过返回值判断是否输入到EOF,本函数当输入到EOF时,返回-1),用法int a = get_int2();
int get_int2() {
int res = , ch, flag = ;
while (!((ch = getchar()) >= '' && ch <= '')) {
if (ch == '-')
flag = ;
if (ch == EOF)
return -;
}
res = ch - '';
while ((ch = getchar()) >= '' && ch <= '')
res = res * + (ch - '');
if (flag == )
res = -res;
return res;
}
/**
* 输入一个字符串到str中,与scanf("%s", str)类似,
* 会忽略掉缓冲区中的空白字符。返回值为输入字符串
* 的长度,返回-1表示输入结束。
*/
int get_str(char *str) {
char c;
while ((c = getchar()) <= ' ') {
if(c == EOF) {
return -;
}
}
int I = ;
while (c > ' ') {
str[I++] = c; c = getchar();
}
str[I] = ;
return I;
} int hash_code(const char str[]) {
int h = ;
for (int i = ; str[i] > ; i++) {
h = * h + str[i];
}
return h;
} int main() {
int N = get_int();
char str[];
map<int, int> mymap;
for (int i = ; i < N; i++) {
get_str(str);
int len = strlen(str);
sort(str, str + len);
int hash = hash_code(str);
if (mymap.count(hash) > ) {
printf("%d\n", mymap[hash]++);
} else {
printf("0\n");
mymap[hash] = ;
}
}
return ;
}
百度之星2016资格赛D,水题的更多相关文章
- 百度之星IP聚合(水题map&字符处理)
虽然题目停水的,但是好像字符处理运用的还比较合适 Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊 ...
- BestCoder 百度之星2016
20160523 百度之星初赛第一场 1001 All X Problem Description F(x, m)F(x,m) 代表一个全是由数字xx组成的mm位数字.请计算,以下式子是否成立: F( ...
- 51nod百度之星2016练习赛
今天看了看51nod发现有这样一个练习赛,就做了做.因为实力太弱想不出E题,各位神犇勿D. (5.26UPD:E题想粗来了) A 区间交 不难发现若干线段[li,ri]的交就是[max(li),min ...
- [百度之星2014资格赛] Disk Schedule 报告
Disk Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- 百度之星2014资格赛 1003 - Xor Sum
先上代码: Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)T ...
- 百度之星2014资格赛 1004 - Labyrinth
先上题目: Labyrinth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 5688:2016"百度之星" - 资格赛 Problem D
原文链接:https://www.dreamwings.cn/hdu5688/2650.html Problem D Time Limit: 2000/1000 MS (Java/Others) ...
- 2016百度之星 资格赛ABCDE
看题:http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=690 交题:http://acm.hdu.edu.cn/search.php ...
- HDU 5686:2016"百度之星" - 资格赛 Problem B
原文链接:https://www.dreamwings.cn/hdu5686/2645.html Problem B Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- 切糕(bzoj 3144)
Description Input 第一行是三个正整数P,Q,R,表示切糕的长P. 宽Q.高R.第二行有一个非负整数D,表示光滑性要求.接下来是R个P行Q列的矩阵,第z个 矩阵的第x行第y列是v(x, ...
- poj 2724 Purifying Machine
Purifying Machine Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5408 Accepted: 1575 ...
- 【NOIP2016练习】T1 string (计数)
题意: 思路: ; ..]of int64; n,k,i:longint; ans,x,y:int64; s,t:ansistring; function c(x,y:longint):int64; ...
- C语言实验报告二
实验一:第11次实验作业报告 题目:方阵循环右移 实验要求:将给定n×n方阵中的每个元素循环向右移m个位置,即将第0.1.⋯.n−1列变换为第n−m.n−m+1.⋯.n−1.0.1.⋯.n−m−1列. ...
- 《Vim实用技巧》第2版读书笔记
学习前的建议: 一.如果你需要一个功能强大的文本编辑器,速度飞快.使用方便.代码补全.编程强大.定制性强,Vim就是你需要的: 二.学习入门曲线陡峭,但是使用后期异常简单,效率超高: 三.号称可以跟上 ...
- linux 中信号量
ctrl-c 发送 SIGINT 信号给前台进程组中的所有进程.常用于终止正在运行的程序.ctrl-z 发送 SIGTSTP 信号给前台进程组中的所有进程,常用于挂起一个进程.ctrl-d 不是发送信 ...
- iOS-tableView上拉加载更多后,界面出现偏移
问题描述: 在做tableview的界面展示的时候,cell用自动计算高度的.但是在上拉加载更多的时候,数据请求完后,刷新界面,界面的顶部就出现了偏移 分析: 查阅资料后发现,当tableView的c ...
- R语言实战读书笔记(十三)广义线性模型
# 婚外情数据集 data(Affairs, package = "AER") summary(Affairs) table(Affairs$affairs) # 用二值变量,是或 ...
- NavBarControl(侧边导航栏)
- SPOJ GSS系列(数据结构维护技巧入门)
题目链接 GSS $GSS1$ 对于每个询问$l$, $r$,查询$a_{l}$, $a_{l+1}$, $a_{l+2}$, ..., $a_{r}$这个序列的最大字段和. 建立线段树,每个节点维护 ...